How to create JSON object dynamically in Azure Logic Apps? - azure-logic-apps

I have a workflow in Azure Logic App that execute an API call to get custom fields values from Trello card. Then, I put a 'for each' step to get the definition (field name) of every custom field. This is made by calling another method of Trello API. I want to create a JSON object based in the values I've got from these API calls. The format of JSON is as simple as:
{
"name1": "value1",
"name2": "value2",
...
}
Edit:
I have an initial object with this schema:
{
"Cel": "",
"City": "",
"CreatedOn": "",
"Lead": "",
"Mail": "",
"Brand": "",
"Name": "",
"Salesperson": ""
}
It's a simple json object with key:value pairs.
I want to set the object properties inside a for each loop. I got the values of the fields from Trello API (returns an array like):
[{"id":"5fbdb5da1626b7499d690ebf","value":{"date":"2020-11-09T15:00:00.000Z"},"idCustomField":"5fbdb5cee93a775e4a9405e5","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946e31680220774095ed9","idValue":"5fa9464bd260145aacba03ed","idCustomField":"5fa9462327f2c331a184a483","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946e0dafc5b7ead25411a","value":{"text":"Lilia Noemi Cabral"},"idCustomField":"5fa9454303ee497b7b99772a","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946bf8697d18d58b73ac1","value":{"text":"Tania"},"idCustomField":"5fa94518f410418c57662fd0","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946c3a2ee2771d26ba30e","value":{"text":"tania#gmail.com"},"idCustomField":"5fa945088fc819708d157c5b","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946bc38b469081857ea9a","value":{"text":"Asuncion"},"idCustomField":"5fa944fe9d7af62b3806c8b6","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946b82bbaf938c4c3c341","value":{"number":"098234567"},"idCustomField":"5fa944e59527342399f460e2","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946b32aad4d323ba0648e","value":{"text":"Tania Cardozo Olivera"},"idCustomField":"5fa944d779089c6ca5cf534b","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"}]
I put a for each step to iterate and parse the field value. I got the field name with another call to Trello API, which return this response:
{"id":"5fa94518f410418c57662fd0","idModel":"5f988b8cb225cc7ac34deae9","modelType":"board","fieldGroup":"53eb88d2e4cde013cb9f03e7500ad1a00a4c82f153f9165f7b1ec554f4cc2d74","display":{"cardFront":true},"name":"Name","pos":81920,"type":"text","limits":{"customFieldOptions":{"perField":{"status":"ok","disableAt":50,"warnAt":45}}},"isSuggestedField":false}
So, I matched the idCustomField to get the field name and field value. Now I want to set the property in the initial declared object (each property name is equal to custom field name in Trello)
I've tried using a compose step with:
setProperty(variables('Object'),body('Parse_JSON')?['name'],body('Parse_JSON2')?['text'])
And later set the variable object to the compose outputs, but doesn't work fine. The result object doesn't have all the properties set. My idea is to set all the object properties inside the for each loop.
What could I be doing wrong?
Is there a way to achieve that in Azure Logic Apps?
Thanks in advance!

You should use
setProperty(variables('object'), body('Parse_JSON')?['name'], body('Parse_JSON_2')?['value']?['text'])
instead of
setProperty(variables('Object'),body('Parse_JSON')?['name'],body('Parse_JSON2')?['text'])
================================Update===================================
Your problem may be caused by the "For each" loop run in parallel, so please try with the steps below (Note: if you do this change, when you want to change back, sometimes it will show error message when you click "Save" of you logic app. So please create another logic app for test or make a backup copy of logic app):
Click the "Settings" of your "For each" loop.
Then enable Concurrency Control and set Degree of Parallelism as 1.

Related

How the body of the PATCH request should look like to change values in an array?

I need to change the values of the object on a third-party resource. I authorize there by token. Passing data via JSON
There is an object, for example, with this structure:
{"Fields": {"anyid": {"Blocks": []}},
"name": "123"}
I want to insert a value into this object, in the "Blocks" array: [], insert a value, for example "anyword".
Write PATCH request
{"Fields": {"anyid": {"Blocks": ["anyword"]}}}
and i get an error - 500 "Object reference not set to an instance of an object"
but, if i will write
{"Name": "any name"},
the query works absolutely correctly and the value changes.
The problem is directly with the nested fields within Fields, can you tell me how the body of the request should look so that I can change the values in the array?

How to fix Zapier not showing all Dynamic Dropdown options that are presented in a JSON Array GET API Repsonse?

I'm building a Zapier app for a platform that has dynamic fields that are specific to the individual user.
My API returns this response using a GET request:
[
{
"title": "003 Best Selling Book",
"id": "d86cbdf41be958336f1221a2211c3f65",
"date": "03/25/2021"
},
{
"id": "b844eaa3da5c476ab7337e83775777e0",
"title": "002 Best Selling Book",
"date": "03/26/2021"
}
]
The response is received by Zapier successfully
Response received by Zapier
but it is only showing the first item in the JSON array.
Only one object in my array shown.
When I go to test my trigger, it only shows me the one object in my array and give me a MISSING VALUE! error.
Missing Value Error in Zapier
Does anyone know how to fix this?
I'm trying to setup a Dropdown Type that is Dynamic and uses a Trigger to get the JSON object that populates the trigger.
A screenshot of the settings for the my dropdown from the Form Editor on the Zapier Platform Input Designer
I tried looking for example code in the Zapier Github or elsewhere on Stackoverflow or the web that showed example JSON responses for Zapier Actions, Zapier Triggers and Zapier Dynamic Dropdowns but couldn't find any.
Per the docs, your returned JSON needs name and id properties.

Triggering multiple webhooks with Zapier array of Json objects

I'm having trouble with triggering multiple webhooks via Zapier like explained on Zapiers website
Did anyone manage to use this functionality?
I'm trying to create "an array of properly formed JSON objects".
To be able to select it as data source in the next step it needs to be a simple array (thats why I stringify the jsons inside the array).
Here is the json array I'm creating in Zapier Code trying to use to trigger two separate webhooks being triggered
var jsonArray = ['{"id":1,"data":111}','{"id":2,"data":222}'];
output = {jsonArrayOut: jsonArray};
Here is a screenshot of a custom webhook request in Zapier
No matter how I format the data I always get one request, not two.
This is the result I see
Could anyone please tell me what am I missing?
Cool, so what you described in this comment should totally be possible.
Your zap will be the following:
Trigger - new email
Parse email, return an array of {id, data} (see below)
Update inventory (will happen for each item in the array in step 2)
This takes advantage of an undocumented feature of code steps where if they return arrays, the zap branches and subsequent steps run multiple times. Note that there's no UI for this and it'll look confusing, but it will work.
Your JS code will be something like the following:
// parse email code
// get items and their quantities
// return object that looks like this
return [{id: 1, data: 123}, {id: 2, data: 456}]
In step 3 (however you're doing that), you'll be able to select id and data as mappable inputs. When you're setting the zap up, you'll only see 1 and 123 as options, but when the zap is on and runs for real, step 3 will get run for each array element returned in step 2.
According to the docs:
You can send an array of properly formed JSON objects, and we will
trigger the Zap once for each object in the array.
Application will be able to parse through the json and understand its structure. Making it as a string makes it to lose it.
So I'm guessing sending it as a string might not work. The Application won't be able to find the number of elements inside the string, it will consider entire string to be one element.
Try,
output = [{"id": 1, "data": 111},{"id": 2, "data": 222}];

Logic app read property of json stored in variable

I have this json in a Logic App variable. I want to 'id' property of this JSON and use further. How to get this id property value?
My json is:
{
"id": 1,
"name": "John bright",
"username": "Lily",
"email": "abc#aabc.com",
}
You said your json is a variable, but you don't mention which type it's stored.
Stored as string. In this way the whole json is a string, it's not supported to select property. So you need parse it to Json with Parse JSON action then you will be able to select property. About the Parse JSON Schema, just click the Use sample payload to generate schema and paste your json value, it will generate. And select your property just use the #{body('Parse_JSON')?['name']}, it will work.
If it's stored as an Object, it will be easier to do it, just use expression variables('test1')['name'] to get it.
Use the Parse Json action and use your payload as a "Use sample payload to generate schema". After that, id will be listed as a Dynamic content from the Parse Json action.

Customising the JSON generated by EXT-JS

I am using EXT-JS 3.2.0 and I have an Ext.grid.EditorGridPanel backed by a Ext.data.Store object. The store has the restful flag on and uses Ext.data.JsonReader and Ext.data.JsonWriter. It works great for retrieving data and populating the grid. However, when I add or update a record, the JSON produced for the POST/PUT has the data nested under a root field. This is not matching up with what the service I am calling expects. It wants a flat object. For example, when I add or update a record, the JSON produces looks something like this:
{
"data": {
"name": "TEST",
"id": "-1"
}
}
But I need it to be
{
"name": "TEST",
"id": "-1"
}
Any ideas?
Thanks,
John
I don't know if it's the best approach but I ended up creating my own Ext.data.Connection object and making the request where I needed it, for example on the delete. Not the solution I was hoping for but it works.

Resources