@@ -643,37 +643,31 @@ export class ExperienceSite {
643643 * @returns path of downloaded site zip
644644 */
645645 public async downloadSiteApi ( ) : Promise < string > {
646- this . logger . debug ( 'Downloading site via API' ) ;
647-
648- this . logger . debug ( 'Querying site from org' ) ;
649- const remoteMetadata = await this . org
650- . getConnection ( )
651- . query < { Id : string ; Name : string ; LastModifiedDate : string ; MasterLabel : string } > (
652- `Select Id, Name, LastModifiedDate, MasterLabel, UrlPathPrefix, SiteType, Status from Site WHERE Name like '${ this . siteName } 1'`
653- ) ;
654-
655- if ( ! remoteMetadata ?. records ?. length ) {
656- const errorMsg = `No published site found for: ${ this . siteDisplayName } ` ;
646+ const remoteMetadata = await this . getSiteMetadataFromConnectApi ( ) ;
647+ if ( ! remoteMetadata ) {
648+ const errorMsg = `No site found for: ${ this . siteDisplayName } ` ;
657649 this . logger . error ( errorMsg ) ;
658650 throw new SfError ( errorMsg ) ;
659651 }
660652
661- const theSite = remoteMetadata . records [ 0 ] ;
662- this . logger . debug ( `Found site: ${ theSite . Name } ` ) ;
653+ this . logger . debug ( 'Downloading site via API' ) ;
663654
664655 // Download the site via API
665656 const conn = this . org . getConnection ( ) ;
666657
667658 // Create temporary metadata for file naming
668659 const metadata : SiteMetadata = {
669- bundleName : theSite . Name ,
670- bundleLastModified : theSite . LastModifiedDate ,
671- coreVersion : '254 ' ,
660+ bundleName : this . siteName ,
661+ bundleLastModified : new Date ( ) . toISOString ( ) ,
662+ coreVersion : '256 ' ,
672663 } ;
673664
674- const siteId = theSite . Id ;
675- const siteIdMinus3 = siteId . substring ( 0 , siteId . length - 3 ) ;
676- this . logger . debug ( `Site ID: ${ siteId } , Modified ID: ${ siteIdMinus3 } ` ) ;
665+ const siteId = remoteMetadata . builderUrl ?. split ( 'siteId=' ) [ 1 ] ;
666+ if ( ! siteId ) {
667+ const errorMsg = `Missing builderUrl for site: ${ this . siteDisplayName } ` ;
668+ this . logger . error ( errorMsg ) ;
669+ throw new SfError ( errorMsg ) ;
670+ }
677671
678672 const accessToken = conn . accessToken ;
679673 const instanceUrl = conn . instanceUrl ; // Org URL
@@ -688,7 +682,7 @@ export class ExperienceSite {
688682 this . logger . debug ( `Resource will be saved to: ${ resourcePath } ` ) ;
689683
690684 try {
691- const apiUrl = `${ instanceUrl } /services/data/v${ conn . version } /sites/${ siteIdMinus3 } /preview${ this . apiQueryParams } ` ;
685+ const apiUrl = `${ instanceUrl } /services/data/v${ conn . version } /sites/${ siteId } /preview${ this . apiQueryParams } ` ;
692686 this . logger . debug ( `API URL: ${ apiUrl } ` ) ;
693687
694688 this . logger . debug ( 'Sending API request' ) ;
0 commit comments