You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feat: Add support for custom APIs @W-15585881@ (#402)
* add custom API helper
* add unit tests
* lint
* update docs
* update README
* move custom api param type from core to commerce-sdk
* update unit test
* update unit tests and add flag for transforming request body
* update property name
* update README example with enableTransformBody example
* update example in README
* revert template changes
* update customApiParameters type
* consume new commerce-sdk-core
Invalid query parameters that are not a part of the API and do not follow the `c_` custom query parameter convention will be filtered from the request and a warning will be displayed.
231
231
232
+
### Custom APIs
233
+
234
+
The SDK supports calling [custom APIs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/custom-apis.html) with a helper function, `customApiHelper.callCustomEndpoint()`.
235
+
236
+
Example usage:
237
+
238
+
```javascript
239
+
import*asCommerceSdkfrom"commerce-sdk";
240
+
const { helpers } = CommerceSdk;
241
+
242
+
// client configuration parameters
243
+
constclientConfigExample= {
244
+
parameters: {
245
+
clientId:'<your-client-id>',
246
+
organizationId:'<your-org-id>',
247
+
shortCode:'<your-short-code>',
248
+
siteId:'<your-site-id>',
249
+
},
250
+
// If not provided, it'll use the default production URI:
// When this flag is set to true, the request body will be automatically
299
+
// formatted in the expected format set by the 'Content-type' headers
300
+
// 'application/json' or 'application/x-www-form-urlencoded'
301
+
enableTransformBody:true,
302
+
303
+
// object can be passed since we have enableTransformBody set to true
304
+
body: { data:'data' }
305
+
// if enableTransformBody is not set to true,
306
+
// we have to ensure the request body is correctly formatted
307
+
// body: JSON.stringify({ data: 'data' })
308
+
},
309
+
clientConfig: clientConfigExample,
310
+
rawResponse:false
311
+
})
312
+
313
+
console.log('get response: ', getResponse)
314
+
console.log('post response: ', postResponse)
315
+
```
316
+
232
317
## Caching
233
318
234
319
The SDK currently supports two types of caches - In-memory and Redis. Both the implementations respect [standard cache headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control). To use another type of cache, write your own implementation of the [CacheManager](https://github.com/SalesforceCommerceCloud/commerce-sdk-core/tree/main/src/base/cacheManager.ts). See the [default cache manager](https://github.com/SalesforceCommerceCloud/commerce-sdk-core/tree/main/src/base/cacheManagerKeyv.ts) to design your implementation.
0 commit comments