How to extract data from API response body.

Reddy
Kilo Sage

Hello,

 

I'm having trouble extracting the gid from the highlighted text in the response body.

 

Response: {"data":[{"gid":"1206582039905837","assignee":{"gid":"1203482360254605","name":"test"},"due_on":"2024-02-28","name":"update website total rewards","notes":"upgrade site and subsite","permalink_url":"","projects"[{"gid":"1206559999430612","resource_type":"project"}]}]}

 

Reddy_0-1707942762711.png

 

1 ACCEPTED SOLUTION

The Machine
Kilo Sage

This seemed to work for me.  try adding [i] after projects.

var o = {
  "data": [
    {
      "gid": "1206582039905837",
      "assignee": { "gid": "1203482360254605", "name": "test" },
      "due_on": "2024-02-28",
      "name": "update website total rewards",
      "notes": "upgrade site and subsite",
      "projects": [{ "gid": "1206559999430612", "resource_type": "project" }]
    }
  ]
}
var gid = o.data[0].projects[0].gid
console.log(gid);

View solution in original post

3 REPLIES 3

The Machine
Kilo Sage

This seemed to work for me.  try adding [i] after projects.

var o = {
  "data": [
    {
      "gid": "1206582039905837",
      "assignee": { "gid": "1203482360254605", "name": "test" },
      "due_on": "2024-02-28",
      "name": "update website total rewards",
      "notes": "upgrade site and subsite",
      "projects": [{ "gid": "1206559999430612", "resource_type": "project" }]
    }
  ]
}
var gid = o.data[0].projects[0].gid
console.log(gid);

Thank you, @The Machine !

It's working.

@The MachineOnly a few created records are getting project ids inserted. Do you have an idea why this is happening?

 

I checked the response body and the data has projects gid for all the tasks.