Creating an array from a get webhook response nested json.
Hi,
The current Zapier steps i have set up creates a GET request to an external service. that service replies with a list of data that is nested. My end step i need to do is make multiple PUT requests to another API with part of the URL being a value from the response from the GET. There is not a fixed number of id’s/times that it will need to PUT.
Currently if i do it with just the GET then the next step is the PUT it puts all of the values of the ID i need to put at the end of the API url as just a comma separated list. I need them to make separate PUT requests for Each ID.
Any help would be greatly appreciated.
Page 1 / 1
Hi @arusso !
Tagging in @ikbelkirasan and @olivialook to see if they can help you crack this one! Thank you in advance
We need help with this problem too! Any solutions?
@arusso@Liz_Roberts@ikbelkirasan@olivialook
Hi @arusso! Could using the Code by Zapier → Run JavaScript to loop through and send individual PUT requests work here? Not sure if AJAX works in Zapier but that could work
@info@aqualabaquaria.com - You can solve this problem by adding a code step to split the comma-separated values. The script should return an array of objects, one object per card_number value.
Since the script is returning an array, each item will trigger the next steps of the zap multiple times, once per item.
@ikbelkirasan thanks for the response. I’m still having trouble. Attached is my screengrab. I tried to change the names in your code to match mine but not sure if I did it right. Obviously not, because it’s still not working.
@info@aqualabaquaria.com - Can you please show me a screenshot of the output of the step 5 of your zap? Thanks!
here you go @ikbelkirasan
Hi @info@aqualabaquaria.com
Please try the following code snippet and show me a screenshot of the result? Thanks!
const { userAPIKey } = inputData;
let results = =];
if (userAPIKey) { results = userAPIKey.split(",").map((userAPIKey, i) => { return { id: i + 1, userAPIKey, }; }); }
console.log(results);
return results;
Looks like it’s still not quite what we want, @ikbelkirasan
To be perfectly honest, the most ideal situation would be to help me pair the user ID associated with the API Key so the APIKey can be inserted as a variable in a URL for an API call. Any idea on easiest way to accomplish that? As you can see in my step 5 results, each employee has an ID and an API KEY, and I’m trying to get a single API Key for a specific employee to use in the custom URL
Thanks for your help so far!
@info@aqualabaquaria.com - In that case, try the following code. Make sure to pass the API keys as userAPIKeys and the user IDs as usersIds.
let { userAPIKeys, userIds } = inputData;
let results = s];
userAPIKeys = userAPIKeys ? userAPIKeys.split(",") : )]; userIds = userIds ? userIds.split(",") : )]; if (userAPIKeys.length !== userIds.length) { throw new Error("API keys number doesn't match the user IDs number"); }
@ikbelkirasan Here is what I got. Please let me know if I set it up right.
@info@aqualabaquaria.com Yes, that’s right. Now you should map the id and userAPIKey in the next step and it should work fine.
@ikbelkirasan I still seem to be having some trouble, take a look at the screen grab to see the avaoiable variables from the javascript output.
How do I pull the API Key I want out of the Runtime Meta Logs field? I already have the employee ID as a variable from a previous step, and I want to use that as an input to then spit out the APIKey for that employee so I can put that into the authorization of the subsequent webhook operation.
@info@aqualabaquaria.com Here’s what you need to map to those fields. You might think that it’s just a single user ID and a single user API key. In fact, those are just samples. When the zap goes live, this step will run multiple times, once per user ID and API key.