Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/contentstack-variants/src/export/experiences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default class ExportExperiences extends PersonalizationAdapter<ExportConf
headers: { 'X-Project-Uid': exportConfig.project_id },
cmaConfig: {
baseURL: exportConfig.region.cma + `/v3`,
headers: { api_key: exportConfig.apiKey },
headers: {
api_key: exportConfig.apiKey,
...(exportConfig.branchName ? { branch: exportConfig.branchName } : {}),
},
},
});
this.exportConfig = exportConfig;
Expand Down
5 changes: 4 additions & 1 deletion packages/contentstack-variants/src/import/experiences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
headers: { 'X-Project-Uid': config.modules.personalize.project_id },
cmaConfig: {
baseURL: config.region.cma + `/v3`,
headers: { api_key: config.apiKey },
headers: {
api_key: config.apiKey,
...(config.branchName ? { branch: config.branchName } : {}),
},
},
};
super(Object.assign(config, conf));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
this.cmaAPIClient?.headers({ authtoken: token });
}
}

// Ensure the CMA client targets the configured branch. Variant groups, CT
// links and other stack-CMA endpoints are branch-scoped, so without this
// header the requests would fall back to the default (main) branch even
// when the import/export is running against a non-main branch.
const branchName = (this.config as any)?.branchName;
if (this.adapterConfig.cmaConfig && branchName) {
log.debug(`Setting branch header for CMA client: ${branchName}`, this.exportConfig?.context);
this.cmaAPIClient?.headers({ branch: branchName });
}

log.debug('Personalization adapter initialization completed', this.exportConfig?.context);
} catch (error: any) {
log.debug(`Personalization adapter initialization failed: ${error}`, this.exportConfig?.context);
Expand Down
Loading