JSON response content checker

Status
Not open for further replies.

PC974

Premier Customer
Basic Certified
Joined
Sep 22, 2024
Messages
18
Reaction score
8
Hi all,

im trying to make a simple JSON Response content checker but i cant get it work with the in built fonction "CONTAINS"

I made a Get request on an api , and the response can be :

Code:
"statusCode": 404,

"statusCodeValue": "NOT_FOUND",

"errors":[

{

"id": "202409201516",

"parameters":{},

"code": "ERROR_1",

"title": "unknown",

"detail": "Error 1",

"lstErreurs":["Error 1"]

}

]


Or can be :
Code:
"statusCode": 404,

"statusCodeValue": "NOT_FOUND",

"errors":[

{

"id": "202409201516",

"parameters":{},

"code": "ERROR_2",

"title": "unknown",

"detail": "Error 2",

"lstErreurs":["Error 2"]

}

]



i need to make differents things for each Error , i try to check the "text" with the inbuild fonction "contains" if there is an Error 1 or Error 2 in my reponse.
But it dosent work.

Any ideas ?

Regards,
 
Hello @PC974,

In first place, that response is not valid JSON. Ensure that your API is returning valid JSON. Once you do, you can use the JSON / XML Parser component, which will let you get a value from the response.
 
Hello @edossantos_sipcaller,

Good idea to use the JSON/XML Parser. I had forgotten about that tool.

Now I can get my variable "code" more easily.

I've created a condition check for Error_1, Error_2, etc., but I can't get it to work. I tried using the contains or equals built-in functions, but the call flow evaluates the branch as false.

I checked my project$.TypeErreur404 variable, and it correctly contains the string "Error_1" or "Error_2".

Is it possible to compare strings?

Thanks a lot.
 

Attachments

  • 2024-09-25 12_20_10-3CX Call Flow Designer.png
    2024-09-25 12_20_10-3CX Call Flow Designer.png
    22.1 KB · Views: 7
ok i get it , the quote was the probleme .... ERROR_2 and not "ERROR_2"
 
ok i get it , the quote was the probleme .... ERROR_2 and not "ERROR_2"
Yes, when you use the Expression Editor and select "Constant String" type, the CFD will automatically add the quotes for you. Also, it will escape any character that might need to be escaped.
 
Status
Not open for further replies.

Members Online Now

Forum statistics

Threads
111,832
Messages
589,285
Members
164,662
Latest member
DejanMDS