How do you use an OpenAPI Array field in a REST flow action?

BurtCrepeault
Tera Contributor

Hi all,

 

I have an OpenAPI swagger loaded in ServiceNow, and some of the field definitions look like this:

 

{
     "fAllowEmptyValue": false,
     "fAllowReserved": false,
     "fContents": [
          {
               "fSchema": {
                    "fDeprecated": false,
                    "fEnum": [],
                    "fExclusiveMaximum": false,
                    "fExclusiveMinimum": false,
                    "fGlideType": "object",
                    "fName": "id0988831599",
                    "fNullable": false,
                    "fOneOf": [],
                    "fProperties": [
                         {
                              "fDeprecated": false,
                              "fEnum": [],
                              "fExclusiveMaximum": false,
                              "fExclusiveMinimum": false,
                              "fFormat": "int32",
                              "fGlideType": "integer",
                              "fName": "id0988831599",
                              "fNullable": false,
                              "fOneOf": [],
                              "fProperties": [],
                              "fReadOnly": false,
                              "fRequired": [],
                              "fType": "integer",
                              "fUniqueItems": false,
                              "fWriteOnly": false
                         }
                    ],
                    "fReadOnly": false,
                    "fRequired": [],
                    "fType": "array",
                    "fUniqueItems": false,
                    "fWriteOnly": false
               }
          }
     ],
     "fDeprecated": false,
     "fExplode": true,
     "fName": "id",
     "fParameterType": "query",
     "fRequired": false,
     "fStyle": "form"
}

 

This id field has fContent.fSchema.fType = "array", elements of which are fFormat: "Int32" and fGlideType: "integer".

When using this spec in a REST step of a Flow Action, I'm fumbling the ball as to how the query parameters should be created.

 

BurtCrepeault_0-1749680552676.png

So I'm scripting the ID query parameter, and according to this product's documentation, the end result should look like this:

https://path/to/api/?id=6&id=8&id=7&id=9

My Flow Action receives a string of IDs, comma separated, and I've tried these mothods so far :

// Method 1
const stringIds = fd_data.action_inputs.ids.split(',');
const intIds = stringIds.map(str => parseInt(str, 10));
return intIds;
  // URL from HTTP logs:
  // https://path/to/api/?id=%5B%226.0%22%2C%227.0%22%2C%228.0%22%2C%229.0%22%5D

// Method 2
const stringIds = fd_data.action_inputs.ids.split(',');
var response = '';
for (var i=0; i<stringIds.length; i++) {
    response += i == 0 ? parseInt(stringIds[i]) : "&id=" + parseInt(stringIds[i]);
}
return response;
  // URL: https://path/to/api/?id=6%26id%3D7%26id%3D8%26id%3D9
  // close, but & and = characters are substituted, so id = the whole string

And of course, all I'm getting back from this server is:

Response code: 400
Response message: {"id":["Enter a whole number."]}

It's late, maybe I'll figure this out in my sleep, but if anyone has some insights on the issue, I'd be much obliged.

0 REPLIES 0