Best answer

Why do I keep getting "Got a result missing the "id" property"?


Userlevel 1

I’ve tried all the similar solutions to people who had the same problem and I keep getting “Got a result missing the "id" property”. Following is the structure of my returned data (the first ‘id’ =12 is the id):

{
"data": [
{
"type": "stage",
"id": 12,
"attributes": {
"color": "#9bedcf",
"createdAt": "2021-03-05T17:54:49.000Z",
"name": "Becoming KLT",
"order": 2,
"updatedAt": "2021-03-11T17:19:02.000Z"
},
"relationships": {
"creator": {
"data": {
"type": "user",
"id": 1
}
},
"prospects": {
"links": {
"related": "https://api..."
}
},
"updater": {
"data": {
"type": "user",
"id": 1
}
}
},
"links": {
"self": "https://api..."
}
}
]
}

Following is my current code

const options = {
url: 'https://apiURL/api/v2/stages',
method: 'GET',
headers: {
'Accept': 'application',
'Authorization': `Bearer ${bundle.authData.access_token}`
},
params: {

}
}

return z.request(options).then((response) => {
response.throwForStatus();
const result = z.JSON.parse(response.content);
result.id = result.id;
return [result];
});

And I’m getting the following error:

Invalid API Response:
- Got a result missing the "id" property ({"data":[{"type":"stage","id":1,"attributes":{"color":"#e8eefe","createdAt":"2021-01-29T23:43:13.000Z","name":"Cold / Not Started","order":1,"updatedAt":"2021-02-16T23:53:40.000Z"},"relationships":{"creator":{"data":null},"prospects":{"links":{"relat)
What happened (You are seeing this because you are an admin):
Executing triggers.get_stages.operation.perform with bundle

Please help!!! 

icon

Best answer by ikbelkirasan 28 May 2021, 18:45

@Troy Tessalone Sure thing!

Hi @scottsmeester303 - The following code snippet should do the trick:

const options = {
url: "https://apiURL/api/v2/stages",
method: "GET",
headers: {
Accept: "application",
Authorization: `Bearer ${bundle.authData.access_token}`,
},
params: {},
};

return z.request(options).then((response) => {
response.throwForStatus();
const items = response.json.data;
return items;
});

 

View original

8 replies

Userlevel 7
Badge +10

Hi @scottsmeester303 

Were you able to figure this out or do you still need help?

Userlevel 1

Hey @Troy Tessalone - still need help!

Userlevel 7
Badge +10

@ikbelkirasan Can you chime in here?

Userlevel 7
Badge +11

@Troy Tessalone Sure thing!

Hi @scottsmeester303 - The following code snippet should do the trick:

const options = {
url: "https://apiURL/api/v2/stages",
method: "GET",
headers: {
Accept: "application",
Authorization: `Bearer ${bundle.authData.access_token}`,
},
params: {},
};

return z.request(options).then((response) => {
response.throwForStatus();
const items = response.json.data;
return items;
});

 

Userlevel 1

That worked!! Thank you, gents!

Userlevel 1

Bonus points: what did I do wrong? 

Userlevel 7
Badge +11

@scottsmeester303 - Awesome!

Ok so, you were returning an object that contains a property called data which contained the items array. The trigger expects the items array to be returned so what the code does here is that it extracts the array from the data property. Each item does already have an id so there’s no need to manipulate that. Make sense?

Userlevel 1

It does. Thank you for the explanation.

A+ to the Zapier Community…

edit: “dev forum” to Community

Reply