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

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?

Related

How should I build a Fetch (Post) data array/structure from scratch? How do I join two arrays? Is it necessary for Fetch?

I need to build some kind of data structure/array starting with nothing and from a loop where the data is available. These would be key/value pairs. I tried initializing an empty cartData array [] in my javascript file, then using push, but this does not appear to be the right thing. This is a shopping cart program. I have all of the customer data captured in an array that looks like {First Name: firstName, Last Name: lastName, Email: emailAddress,... ,} and from the console it appears to have worked and in that form. For cartData, I'm getting something like
{Book_Title1: Price1},{Book_Title2: Price2},...{},{}
as a collection of objects. When I added to the cartData = [] array I gathered the data inside the loop and used the following method
cartData.push({[purchaseItem]: purchasePrice})
to add new items to the empty array. What I get is a collection of objects that look like
{BookTitle1: Price1}, {BookTitle2: Price2},...{}, {}
are the {}brackets unnecessary? There seem to be a number of opinions without examples. I was assuming that the first structure shown here is what is needed for Fetch to post the way a normally presents data. I could be wrong on that also. I need to know the correct way to do it and a way to combine the two data sets (three if we count the Key/Value pair for grand $total.) My goal is to have the customer hit the purchase button, the cart/form data to go to Formspree.io and for them to send an email with all of this order information. It works well enough with an unadulterated . I just need to amend the data for the cart.
It would help if you provide a snippet of the code that you've written, because it's not really clear what format are you sending the data in.
Your question seems to imply that you're sending the request body as an array. That is incorrect. It has to be a JSON.
Secondly make sure you add the 'Content-Type: application/json' header to your request

How to create JSON object dynamically in 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.

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.

angularjs $resource.query with complex structure

all my rest API for the query (e.g. /clubs) return an object that is of this form:
{
"total": 10,
"results": [...]
}
the $resourece.query expect an array.
what's the correct way to parse this response?
Should I override in the definition of the resource the query setting isArray: false? (if I set the functions to override the query do I've to re-set all the other methods such as get save etc?)
Should I create a parseFunction to parse the result and return an array? if so, how?
how can I create a my resource in a way that I don't have to replicate the code for every resource? basically extending the current $resource object to override the configuration, or the parsing function.
What are you receiving back is an object and not an array, so use $resource.get, then you can access the results array from the object

Resources