Last active
July 13, 2025 13:06
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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); | |
| }); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: