cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Array of strings in Object definition field SDK Connector

wilbert
Deputy Chef II
Deputy Chef II

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?

 

4 ACCEPTED SOLUTIONS

gary1
Executive Chef II
Executive Chef II

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!

View solution in original post

wilbert
Deputy Chef II
Deputy Chef II

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)

View solution in original post

I was testing in the SDK console. Got a bit further and I now see the payload

wilbert_0-1677586284859.png

It is indeed just about getting the roles element parsed correctly, it should look like:

{
  "name": "Peter Pan",
  "roles": [
    "APP_USER"
  ],
  "appUserSettings": {
    "firstName": "Peter",
    "lastName": "Pan",
    "posPinCode": "123456",
    "locale": "nl-NL"
  }
}
 
or 
"roles": [
    "APP_USER",
"WEB_USER"
  ]
 
In case of multiple roles.
 
 

 

View solution in original post

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: 
multiselect_input_field.png

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 

View solution in original post

8 REPLIES 8

gary1
Executive Chef II
Executive Chef II

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!

wilbert
Deputy Chef II
Deputy Chef II

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)

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?sdk-http-request-debug.png

 

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

wilbert_1-1677583327171.png