Best answer

Invalid API - I get missing the "id" property when I already have an "id" property

  • 27 August 2021
  • 2 replies
  • 116 views

Userlevel 1

Hello,

I have an “id” property already in my response, under children:

 "kind": "Listing",
"data": {
"after": null,
"dist": 1,
"modhash": "",
"geo_filter": "",
"children": [
{
"kind": "t3",
"data": {
"approved_at_utc": null,
"saved": false,
"mod_reason_title": null,
"gilded": 0,
"removal_reason": null,
"link_flair_background_color": "",
"id": "pc39rj",
"is_robot_indexable": true,
}
}
],
"before": null
}
}

This is my API Endpoint Code…

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

// You can do any parsing you need for results here before returning them

return [results];
});

I don’t really understand why it won’t pick it up... I am guessing I would need additional code in the parsing section?

Any help would be appreciated!

 

WDes

icon

Best answer by ikbelkirasan 27 August 2021, 18:38

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 7
Badge +12

Hi @WDES2021 - The id needs to be at the top level, that’s why it didn’t work. Try this out and see if fixes your issue:

return z.request(options).then((response) => {
response.throwForStatus();

const results = response.json.data.children.map((child) => {
return {
...child,
id: child.data.id,
};
});

return results;
});

 

Userlevel 1

Confirmed that resolved it. Thank you for the immediate response!