
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2020 05:22 AM
I want to build a component to retrieve data but the rest api requires some parameters to be passed as json in the request body.
I am looking at the documentation for createHttpEffect and I cannot figure out how to send a json body with the request.
Does anybody know what parameters this should be passed in?
Solved! Go to Solution.
- Labels:
-
Now Experience UI Framework

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2020 02:09 PM
Hi Tommy,
I'll do a little digging and see if I can find something outside of the docs on developer. That being said, one of the things we demonstrated on last week's shows was using a Flow Designer action to consume an external API, then calling that action from a scripted rest API, and consuming the SRAPI from our component. That way we can abstract things from the component a bit and do any heavy lifting in the SRAPI. If you are looking to consume an external API from your component, that might be an architecture to look at either way.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 01:28 PM
Thank you Brad. For now I will use this type of architechure as it actually is better since the call I need to do require authentication with userid/password so better to let the server handle that.
I am still interested in knowing how to set the body in case I come across a use case where that is needed.
This is what I am working on (very rougth and basic)
https://vimeo.com/420419736
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 01:53 AM
Hi,
Please try the below:
For example, you want to make a rest api call on click of a button
<now-button
label="Submit"
variant="primary"
on-click={e => {
dispatch('SAVE_REQUEST',
{
requestData:
{
status: "requested",
user: properties.user.value,
start_date: properties.startDate,
end_date: properties.endDate
}
}
)
}}
/>
In the action handler, you can do the following:
'SAVE_REQUEST': createHttpEffect(
'/api/now/table/<table_name>',
{
method: 'POST',
dataParam: 'requestData',
successActionType: 'HTTP_EFFECT_SUCCESS',
errorActionType: 'HTTP_EFFECT_ERROR'
}
)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 03:27 AM
Thank you for your effort. But you are really not answering my question. My question has nothing to do with updating a record via the table API. My question is about building a json body to send to an external REST API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 03:50 AM
Hi,
The 'requestData' is a JSON payload which is being passed to the dataParam via the dispatched action. I was showing table API as an example, but I think you can call any rest api here.
requestData:
{
status: "requested",
user: properties.user.value,
start_date: properties.startDate,
end_date: properties.endDate
}
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 04:31 AM
No I am sorry but you are wrong.
What you suggest will not result in a json body. I have tried this approach. This datParam is a ServiceNow specific feature.
You can try it yourself.
Goto https://putsreq.com/ and create a fake endpoint and test your code out. You will then see that there is NO body on the request sent.