Reputation: 925
sample api url: https://jsonplaceholder.typicode.com/posts
title is not a mandatory field in received json. It may or may not be part of each record.
When this field is missing in record, @{items('For_each')['title']} this throws an exception.
I want the value of myVariable to set as 'N/A' in that case. How do i do this?
Upvotes: 0
Views: 1697
Reputation: 1984
I make the assumption that this is an array and that you have a set schema in the HTTP trigger. If the schema is set, make sure you remove Title
as a required field.
Using these asumptions you should be able to do the following with Coalesce()
If Title
now is not present in the body of the HTTP request the Title
will be equal to 'N/A'
Using postman to test, note, the result is backward as it is the first object sent in my array.
Upvotes: 2
Reputation: 14344
Cause you url data all have the title, so I test with When a HTTP request is recived
trigger to get the json data.
In this situation the data could only be like this:
{
"userId": 1,
"id": 2,
"body": "xxxxx"
}
not like the below one:
{
"userId": 1,
"id": 2,
"title":,
"body": "xxxxxxxxx"
}
I test with the first one, it did show the error message: property 'title' doesn't exist,. So here is my solution, after the action Set variable
, add an action to set the variable you want and set the action run after Set variable
has failed like the below picture.
After configuration, if the title doesn't exist, it will be set as N/A
as you want.
Hope this could help you, if this is not what you want or you have other questions, please let me know.
Upvotes: 1