โ02-23-2023 05:40 AM
I am building an SDK connector for a new API that makes a lot of use of arrays of strings in the payload.
A simple example of the API call payload:
{
"name": "John Smith",
"groups": [
"Group 1",
"Group 2"
],
"locations": [
"Headoffice",
"Amsterdam"
],
"appUserSettings": {
"firstName": "John",
"darkmode": true,
"pinCode": "123",
"locale": "nl-NL",
}
}
Both the roles and locations elements are arrays of strings. Workato's works with hashes of key values and string arrays is a bit of a challenge. In a recipe I have been able to get this to work by, for instance, using the pluck function the get the group names from a list of groups.
In the SDK I can't get de definiton of the input fields right. I assume would be something like
{
name: "groups",
type: "array",
of: "string",
control_type: 'multiselect',
pick_list: 'groups',
hint: "The users groups in the application."
},
{
name: "locations",
type: "array",
of: "string",
hint: "The users allowed loactions in the application."
}
Groups is a predefined list, loactions is free input.
Any help is greatly appreciated. Maybe there are existing Community Connectors using string arrays?
Solved! Go to Solution.
โ02-23-2023 09:00 AM
For groups, you don't need to set the input field as an array of strings. Set it as a multi-select string with a pick list and it will output as an array of strings in the input hash. Like this:
{
name: 'groups',
control_type: 'multiselect',
pick_list: 'groups',
type: 'string'
}
You should be able to use its output directly in the "groups" key of your payload like this:
payload["groups"] = parse_json(input["groups"])
(parse_json may be the trick to all of this, but I can never remember exactly when it needs to be used...)
For locations, you can set the input field as an array of strings like you're already doing. This input field will require an actual array, and will output as an array of strings just like the the groups string/multi-select. You can access it the same way, like
parse_json(input["locations"])
Hope this helps!
โ02-28-2023 01:18 AM
Thanks, the input for the groups works. The parse_json function does not seem to be enough. The API gives an 400 Bad request, but it is hard to debug what exacltly is send. The input seems fine. It is just in parsing the groups array to the payload.
Action input:
{
"appUserSettings": {
"locale": "nl-NL",
"firstName": "Peter",
"darkmode": true,
"pinCode": "123"
},
"name": "Peter Pan",
"groups": [ "Group 1", "Group 2" ]
}
I am just gonna try to build the payload step by step and see if I can capture the result somehow as well (I don't have any logging on the side of the called API as well)
โ02-28-2023 04:14 AM
I was testing in the SDK console. Got a bit further and I now see the payload
It is indeed just about getting the roles element parsed correctly, it should look like:
โ02-28-2023 05:30 AM
Hi @wilbert,
Please check your input for the groups field. I have an example also using multiselect and the selected fields are given as an input with a space separator:
For this, you should add the property: delimiter: " " to your groups input field. And then finally I convert the given String into an Array right for the HTTP request:
includeDemoBoardData: _input['includeDemoBoardData'].split(" ")
Hope this helps!
Cheers,
Chris
โ02-23-2023 09:00 AM
For groups, you don't need to set the input field as an array of strings. Set it as a multi-select string with a pick list and it will output as an array of strings in the input hash. Like this:
{
name: 'groups',
control_type: 'multiselect',
pick_list: 'groups',
type: 'string'
}
You should be able to use its output directly in the "groups" key of your payload like this:
payload["groups"] = parse_json(input["groups"])
(parse_json may be the trick to all of this, but I can never remember exactly when it needs to be used...)
For locations, you can set the input field as an array of strings like you're already doing. This input field will require an actual array, and will output as an array of strings just like the the groups string/multi-select. You can access it the same way, like
parse_json(input["locations"])
Hope this helps!
โ02-28-2023 01:18 AM
Thanks, the input for the groups works. The parse_json function does not seem to be enough. The API gives an 400 Bad request, but it is hard to debug what exacltly is send. The input seems fine. It is just in parsing the groups array to the payload.
Action input:
{
"appUserSettings": {
"locale": "nl-NL",
"firstName": "Peter",
"darkmode": true,
"pinCode": "123"
},
"name": "Peter Pan",
"groups": [ "Group 1", "Group 2" ]
}
I am just gonna try to build the payload step by step and see if I can capture the result somehow as well (I don't have any logging on the side of the called API as well)
โ02-28-2023 01:26 AM
Hi @wilbert, once you test your action in the SDK, you should already see the HTTP-Request details including the playload sent to your API-Endpoint. Can you confirm it is not shown?
โ02-28-2023 03:22 AM
That what I expected but it is not the case. I do not see the request body. Maybe because it is a PUT request? I just see the headers