Skip to content

Instantly share code, notes, and snippets.

@nocrates
Last active July 13, 2025 13:06
Show Gist options
  • Select an option

  • Save nocrates/db7c1dd9b40f91d4693e6533ccba6f90 to your computer and use it in GitHub Desktop.

Select an option

Save nocrates/db7c1dd9b40f91d4693e6533ccba6f90 to your computer and use it in GitHub Desktop.
From B2BCommerce (Commerce on Core) for Salesforce, using the LWC (Lightning Web Component) within the LWR, this gist will call a commerce-api URL with the session credentials of the running user.
/* Returns a promise */
fetchCommerceUrl(url) {
let apiver = 'v64.0';
let commercebase = '/webruntime/api/services/data/' + apiver + '/commerce';
let fullurl = commercebase + url;
console.log('Begin fetchCommerceUrl on ', fullurl);
return fetch(fullurl, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
credentials: 'same-origin'
})
.then(response => {
return response.json();
})
.then(data => {
if (data) {
return data;
}
})
.catch(error => {
console.log('Error with fetchCommerceUrl: ', fullurl, error);
});
}
@nocrates
Copy link
Author

Example usage:

async fetchLegacyOrders() {
    let legacyStoreId = '0ZEbb00000014PlGAI'
    let legacyOrderSummaryUrl = '/webstores/'
    + legacyStoreId + '/order-summaries'
    + '?fields=GrandTotalAmount%2CDeliveryBlock__c'
    + '&pageSize=100'
    + '&ownerScoped=false'
    + '&language=en-US'
    + '&asGuest=false'
    + '&htmlEncode=false';

    const legacyOrders = await this.fetchCommerceUrl(legacyOrderSummaryUrl);
    console.log("%c legacyOrders", "color: green", legacyOrders);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment