helpers<dot>snHttp<dot>post is not a function - client side call to Scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I must be missing something here because it can't be this hard... 😕
I am using a PDI setup with Yokohama. I have a local app that I created and im using UI Builder to create a page for the app. I need a button on the page that when clicked (client side) will call a scripted REST API.
1. I have used the REST API Explorer to test my Scripted REST API POST method and I get a status code 200 OK response and the expected response body.
2. Note the API request does not require any parameters.
3. I have created a page in a workspace in my local app that has a button on it.
4. I have created a client script called Button Click that has the following code:
/**
* @Param {params} params
* @Param {api} params.api
* @Param {any} params.event
* @Param {any} params.imports
* @Param {ApiHelpers} params.helpers
*/
async function handler({ api, helpers }) {
try {
console.log('Running...');
const response = await helpers.snHttp.post(
'/api/x_1091492_twodd_0/twodd_guc_api/run',
{ headers: { Accept: 'application/json' } }
);
const responseData = response.data || {};
const data = typeof responseData.result !== 'undefined'
? responseData.result
: responseData;
console.log('Completed:', data.message);
api.state.setValue('guc_result', data);
console.log('Process summary:', data.summary);
} catch (err) {
console.error('Error:', err);
}
}
5. On the Button under the Events tab, I have added a handler that points to this client script.
6. When I preview the page, view the console, and click the button:
I get the console log "Running..."
I get an error that says "Error running ...: TypeError: helpers.snHttp.post is not a function at handler..."
I have also tried direct api calls as well as trying to use Ajax instead of the api, but nothing seems to work. I must be missing something. Any help is appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi,
I'm not in front of computer, but seems you are calling helpers.snhttp.post() but the correct is helpers.snhttp() as per documentations. The method (get, post, etc) should be passed as parameter object.