Skip to content

Instantly share code, notes, and snippets.

@megasmack
Forked from nocrates/fetchCommerceUrl.js
Created July 13, 2025 13:06
Show Gist options
  • Select an option

  • Save megasmack/f09c7fb509752f5784ddff837265e6af to your computer and use it in GitHub Desktop.

Select an option

Save megasmack/f09c7fb509752f5784ddff837265e6af 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);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment