121
Views
5
Comments
Passing array of integers on the URL parameter
Question
Application Type
Reactive

I need to consume an api that has an array of integers on the url parameter.  Can anybody pls. help me with this.  I don't know how to do it.

Thanks,

RL

2022-08-03 04-32-50
Ravi Punjwani

Hi Robert,

Can you provide a sample data of the desired URL?

Is it something like this:
https://<THEIR_API_URL>/api/test?myArray=[1,2,3,999]

UserImage.jpg
Robert Lieou

Hi Ravi,

Yes, exactly like what you think.

https://<api_url>/api/test?myArray=[1,2,3]

Thanks,

2022-08-03 04-32-50
Ravi Punjwani

Hi @Robert Lieou 

In Outsystems REST Consume, List types cannot be used in the query strings.

But you can convert your list object into a CSV string and wrap it with square brackets. Then pass this string to the string type input parameter in your REST Consume API.

Thanks,

Ravi

UserImage.jpg
Robert Lieou

Hi Ravi,

When you said 'square brackets' did you mean double quotes since now it is a string instead of array.

Thanks,

2022-08-03 04-32-50
Ravi Punjwani

The list representation is usually accepted in array-like notation, which is square-brackets [ ]

Now that you've mentioned you need strings, instead of integers, the array/list of string can be represented in different ways:

  1. ["Red","Yellow","Blue"]
  2. ['Red','Yellow','Blue']
  3. [Red,Yellow,Blue]

From above options which one suit you best for your API call? I suggest trying out with some sample data using Postman and then only work on the Outsystems app to generate such matching texts. This will save your development time following trials and errors.

Once you select the correct format, just generate that type of string in your Outsystems app where you're calling the REST API.

Don't forget to use EncordUrl() inbuilt function to make sure your data is safe to go on a URL's query string parameters. You would be using EncodeUrl only after generating the desired string in proper format, but before sending it actually to the API.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.