Need to display message depending on API endpoint status code

Hi Team,

I need help to display message on Retool depending on API endpoint status.
Basically i am calling my API end point from Retool. I want to display message on my Retool i.e.,
if status code is 200 then success message.
if status code is 409 Dulpicate config message.
Mandatory fields missing like that.

Please help me how to read API endpoint status code and display message.

Thanks,
Lalitha.C

Checkout Transformers

Hi Scott,

Thanks for your response, however i am not able to access statuscode.
Here is my APIRequest tab data, basically I want to access that status code in case of success, where as for error I have to access Response tab. Below are my responses which I need to access.
Error:
{
"error": {
"data": 0,
"message": "One or more request data is invalid",
"errors": [
{
"message": "level is required"
},
{
"message": "product is required."
},
{
"message": "fieldName is required"
}
]
}
}

Success:
{
"request": {
"url": "https://cas-crim-result-validation.dev.ablocal.io/v1/mappings/createmappings?expression=&fieldname=test&level=test&product=FED1",
"method": "POST",
"body": "",
"headers": {
"User-Agent": "Retool/2.0 (+https://docs.tryretool.com/docs/apis)",
"content-type": "application/json",
"X-Retool-Forwarded-For": "10.1.2.40"
}
},
"response": {
"data": {
"data": {
"mappings": [
{
"id": "63a08b8330bd21001d9c4e08",
"product": "FED1",
"level": "test",
"field_names": [
"test"
],
"hash_code": "A2PBR9uPY5MQTNTKxRvzAnd9/x6QPQ0WXx7YndgDXC2nawlFD1e2ou7vX+9fpLl0+zc+98B3A2lzYvG4gEmmxw==",
"created_at": "2022-12-19T00:00:00-08:00",
"updated_at": "2022-12-19T00:00:00-08:00"
}
]
}
},
"headers": {
"date": [
"Mon, 19 Dec 2022 16:04:19 GMT"
],
"content-type": [
"application/json; charset=utf-8"
],
"transfer-encoding": [
"chunked"
],
"connection": [
"keep-alive"
],
"server": [
"Kestrel"
]
},
"status": 200,
"statusText": "OK"
}
}

Below are few screen shots which I tried:
For Error Configuration:

after run query it is displaying just Notification, not message - not sure where I went wrong.
I really stuck here, could you please help me out.

Did you click on the Response tab of the API resource and configure there?

Hi Scott,

I have done in General tab. Now it is working.
Below is my screen shot, however I want to add one line break in between messages.
Could you please check and let me know how can I achieve this.

Here is display screen shot:

I want to display like below:
level is required
product is required
fieldname is required

Basically I want to add line break in between messages.

Thanks,
Lalitha.C

Move your notification information into the Description field and simply return after each entry and add a title. However, I have not found a way to use a new line after each entry at this time.

Okey, Thank you Scott, however description field also behaving same.

Hey @lalitha1024!

It looks like notifications don't support multiline text at the moment, would it work to show each error as a separate notification with a script like the following?

ResultValidationMapping_Insert.data.data.error.errors.forEach(error => utils.showNotification({title: error.message}));

Hi Kabirdas,

Thanks for your advice, could you please let me know where do I need to write above code. Is it in Title?

Thanks,
Lalitha.C

The idea is to use it as your event handler! You change the action to "Run script" and then enter it there:

Can you let us know how that goes?