98
Views
16
Comments
Solved
How to send null as a parameter request in REST API test?
Application Type
Traditional Web, Mobile, Reactive, Service

Hi there,

I cannot manage to send URL parameter if parameter is null while doing test in the OS; for non null it is okay. My question is how to send the null as url parameter value?

regards and thanks


2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Hi,

Those array lists in url parameters are typically represented in the following way

?parameter=["key1","key2","key3"]

Looking at the stripe documentation than the lookup_keys is an optional parameter. That means you either send it with values or not at all. You do not send a null.

OutSystems does not support Arrays as Url parameters directly but there is an easy way to do it.

Create an input url input parameter LookupKeys and bind it to your method e.g. /prices?lookup_keys={LookupKeys}. Make sure that both mandatory and send default value is set to No. 

Create a wrapper service action with an input parameter LookupKeys with a data type of List of Text.

Add a local variable LocalLookupKeys with data type text

Add an If statement with a condition of not LookupKeys.Empty. In the true branch add a Serialize JSON action and serialize the input parameter LookupKeys. Then assign the result of the serialized value to LocalLookupKeys.

Use the LocalLookupKeys as parameter for the REST query.

This should do it.

Stefan

2025-01-09 14-56-57
IQ78

Thank u, Sir

All the syntaxes of this kind: ?parameter=["key1","key2","key3"] 

does not work on Test Tab, i tried combination like [{Key1},{key2}], {[key1,key2]}, etc

and the only one that properly works is something like this:

https://api.stripe.com/v1/prices?lookup_keys[0]={lookup_key}&lookup_keys[1]={lookup_key1}

For the action code, i haven't tried your suggestion, i'll try it later if there's the case.


For the null case, yes could be Stripe does not return the results for condition is null. I try also putting %00 with no luck in the Test of Service Studio.

regards

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

What data type does the parameter have?

2025-01-09 14-56-57
IQ78

Hi thanks,

It is a string

2023-04-16 15-25-31
Krishnanand Pathak

Hi Ibox,

Have you tried passing empty quotes  "".

Regards

Krishnanand Pathak 

2025-01-09 14-56-57
IQ78

yes, but with no luck


2025-02-10 17-24-13
Arun Rajput

Hi @ibox ,

I'm curious to know that why  you used '[]' in query parameter - lookup_Keys[]

Will this query parameter hold list or single line string only?

Best

Arun

2025-01-09 14-56-57
IQ78

Yes, that's the way to send member of arrays:

This is for one member, you can also put index in there lookup_keys[0] with same result.

if there are more then one member then we must put the indexes lookup_keys[0] = {lookupkey}&lookup_keys[1] = {lookupkey1} and i tried succeed for non null.


regards 


 

2025-02-10 17-24-13
Arun Rajput

Hi,

Did you try it on postman or swagger with null value?

Or can I also try this curl at my end? as it's stripe api and I have worked on stripe payment gateway?

Arun

2022-01-13 11-06-04
Neha Sheikh
Champion

Hi ibox,

I have tried doing the same thing. It is working for me with "" and with null as well.

You can try with this API.

https://personal-uketk5va.outsystemscloud.com/DemoRef/rest/Movies/GetMovies?Title={Title}

Can you double-check the datatype of the parameter?


Thanks,

Neha

2025-01-09 14-56-57
IQ78

Thanks,

I have already double checked -I hit the REST API of Stripe payment gateway-.

For empty string:

If i list all, there's the null:




regards

2022-01-13 11-06-04
Neha Sheikh
Champion

Hi ibox,

Have you tried setting Send default values as "Yes" ?

Regards,

Neha

API.png
2024-07-16 17-36-51
Shradha Rawlani

Hi,

Please check REST API setting where accept default value property should be YES.

Thanks

Shradha

2025-01-09 14-56-57
IQ78

It is Test tab, no option for that.

regards

2024-07-16 17-36-51
Shradha Rawlani
2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Hi,

Those array lists in url parameters are typically represented in the following way

?parameter=["key1","key2","key3"]

Looking at the stripe documentation than the lookup_keys is an optional parameter. That means you either send it with values or not at all. You do not send a null.

OutSystems does not support Arrays as Url parameters directly but there is an easy way to do it.

Create an input url input parameter LookupKeys and bind it to your method e.g. /prices?lookup_keys={LookupKeys}. Make sure that both mandatory and send default value is set to No. 

Create a wrapper service action with an input parameter LookupKeys with a data type of List of Text.

Add a local variable LocalLookupKeys with data type text

Add an If statement with a condition of not LookupKeys.Empty. In the true branch add a Serialize JSON action and serialize the input parameter LookupKeys. Then assign the result of the serialized value to LocalLookupKeys.

Use the LocalLookupKeys as parameter for the REST query.

This should do it.

Stefan

2025-01-09 14-56-57
IQ78

Thank u, Sir

All the syntaxes of this kind: ?parameter=["key1","key2","key3"] 

does not work on Test Tab, i tried combination like [{Key1},{key2}], {[key1,key2]}, etc

and the only one that properly works is something like this:

https://api.stripe.com/v1/prices?lookup_keys[0]={lookup_key}&lookup_keys[1]={lookup_key1}

For the action code, i haven't tried your suggestion, i'll try it later if there's the case.


For the null case, yes could be Stripe does not return the results for condition is null. I try also putting %00 with no luck in the Test of Service Studio.

regards

2021-10-09 07-57-44
Stefan Weber
 
MVP

Hi @ibox 

the reason why it is not working in the test tab is because the parameters are not url encoded using the test tab. They are sent as presented. URL encoding is only done when you call the consume action from code. So in your case your would have to encode the ["key1","key2"] part before using an online encoder

your call in the test tab would then look like this

/restcall?lookup_keys=%5B%22key1%22%2C%22key2%22%5D

Best

Stefan

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