I’m working on a custom Zapier integration and running into a problem with accessing nested data from my API response. The issue is that I need to get to an array that’s buried two levels deep in the response, and the key I need to access changes based on user input.
Basically, I want to do something like return apiData.field_collection[bundle.inputData.dynamicKey] but I can’t seem to make this work properly. The input variable doesn’t get recognized when I try to use it as a key.
Here’s my current API call setup:
const requestConfig = {
url: `https://api.projectapp.com/v2/field_data.json?type=task&record_id=${bundle.inputData.record_id}&field_type=Assigned User`,
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${bundle.authData.token}`,
'Accept': 'application/json'
},
params: {
'record_id': bundle.inputData.record_id,
'field_label': 'Assigned User'
}
}
return z.request(requestConfig)
.then((response) => {
response.throwForStatus();
const apiData = z.JSON.parse(response.content);
return apiData.field_collection[bundle.inputData.dynamicKey];
});
The API returns something like this:
{
"887766543": {
"editable": true,
"record_type": "task",
"workspace_id": 9988776,
"record_id": 445566778,
"modified_date": "2019-05-22T10:30:45-07:00",
"data": [
774433
],
"readable_value": "John Smith",
"modifier_id": "12345678",
"field_id": "998877",
"creation_date": "2019-05-10T09:15:30-08:00",
"field_label": "Assigned User",
"input_type": "single_select",
"id": "887766543"
}
}
I need to extract just the object with key “887766543” but this key changes for each request. The good news is I can pass this key as input data from the user. Any ideas on how to make this work?