How to define pass POST Data via a UX REST Data Broker?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2021 03:37 AM
I am trying to call a POST-based REST API via UX REST Data Broker from UI Builder.
I have managed to get a POST call working with no data
called in UI Builder via
api.data.approve_task.execute({
taskId: api.context.props.taskId
});
However I'm not clear on how to pass POST data into this via the `execute` method. The UI Builder API Documentation (execute) only indicates how to do this for URL parameters, but only specifies this for a simple operation with no Data.
I have tried:
1) adding as a "dataParam" (as used in createHTTPEffect)
api.data.approve_task.execute({
taskId: api.context.props.taskId
dataParam: {
comment: "my comment"
}
});
> this results in "no data" in REST client script i.e. the data isn't passed through
2) Looks like I can "hard-code" a "Request Body" in the Data Broker definition
> which get through to the REST client script - but isn't what I'm after
3) defined "data" as a parameter and tried to refer to it as
> but that results in "com.glide.rest.util.RESTRuntimeException: The payload is not valid JSON." in the logs
Any ideas on how to pass the data from client, though the Data Broker and into REST endpoint?
I have a follow on question - "if you execute the data resource, from UI Builder, how do you get access to the return data?"
"execute" doesn't return a Promise, nor does it seem to make a blocked call in the script - as logging the data via "api.data.approve_task.output" returns undefined - even though I see the data returned in Developer Tools (albeit base64 encoded)
- Labels:
-
Now Experience UI Framework
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2021 03:17 AM
Hi
Thanks for that
However, I'm struggling passing a javascript object through
If my UI Builder script is
api.data.schedule_rest.execute({
sys_id: '0486f2821be0cd504fe03227dc4bcbce',
schedule: {
changeWindowStart: {
date: "2021-12-22",
time: "12:00"
},
changeWindowEnd: {
date: "2021-12-22",
time: "12:00"
},
}
});
url
/api/my_scope/myapp/item/{{sys_id}}/schedule
params
[
{
"name": "sys_id",
"label": "Sys Id",
"description": "",
"readOnly": false,
"fieldType": "string",
"mandatory": true,
"defaultValue": ""
},
{
"name": "schedule",
"label": "Schedule",
"description": "",
"readOnly": false,
"fieldType": "object",
"mandatory": true
}
]
and Request Body
{ "schedule":"{{schedule}}" }
Data does seem to get passed, but it doesn't appear to be a Javascript object.
If I add a log line to the data in the REST endpoint via
var schedule = request.body.data.schedule;
gs.info('Schedule type['+typeof schedule+'] schedule['+schedule+']');
then it appears to be a json-like string with '=', but code can't access (e.g.) changeWindowStart.date, and JSON.parse on it fails.
Schedule type[string] schedule[{changeWindowStart={date=2021-12-22, time=12:00}, changeWindowEnd={date=2021-12-22, time=12:00}}]
So - How to define the "fieldType" for this param? I tried "object" (as above) and "JSON_LITERAL" with same result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2021 07:33 AM
Seems like a bug. I think it got fixed in SD release. Please use alternative solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2021 08:58 AM
Hi - what is SD release? I am on "Build tag: glide-rome-06-23-2021__patch3-hotfix1-11-12-2021" so pretty up-to-date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2021 09:20 PM
SD is SanDiego release which is under developerment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 02:31 AM
api.data.data_source_id.execute({
tableName: "incident",
short_description: "Something wrong in my network",
caller_id: api.context.session.user.sys_id
});
where this script go? is that a client script?
my question where are the parameters from Request Body coming from?