Skip to main content
Best answer

Got a result missing the "id" property

  • April 2, 2021
  • 1 reply
  • 136 views

const timestart =Math.floor(Date.now() / 1000) -  bundle.inputData.startTimestamp;
    const endtime = Math.floor(Date.now() / 1000) - bundle.inputData.endTimestamp
const options = {
  url: `${bundle.authData.server}/org/${bundle.authData.orgId}/contacts`,
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'Authorization': `Token ${bundle.authData.token}`
  },
  params: {
    'startTimestamp': timestart,
    'endTimestamp': endtime,
    'reportType': bundle.inputData.reportType,
    'fields': bundle.inputData.fields
  }
}

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;
  });

here is the code that I am executing. When I execute I get the following errors 

 

CheckError: Invalid API Response: - Results must be an array, got: object, ({"50219":{"campaigns":[{"campaignId":63651,"campai) - Got a result missing the "id" property ({"campaigns":[{"campaignId":63651,"campaignName":"Activation Flow"}],"fields":{"name":"Chris Collins"}})

 

Here is the actual JSON that is returned from the API. 

 

{
    "547012": {
        "campaigns": [
            {
                "campaignId": 63651,
                "campaignName": "Activation Flow"
            }
        ],
        "fields": {
            "name": "Paul Collins"
        }
    },
    "547013": {
        "campaigns": [
            {
                "campaignId": 63651,
                "campaignName": "Activation Flow"
            }
        ],
        "fields": {
            "name": "jenny Collins"
        }
    }
}

the value 547012 and 547013 should be the id but I do not know how to turn the response into that?

Best answer by ikbelkirasanBest answer by ikbelkirasan

@cozza13 - Try the following code snippet:

const timestart =
  Math.floor(Date.now() / 1000) - bundle.inputData.startTimestamp;
const endtime = Math.floor(Date.now() / 1000) - bundle.inputData.endTimestamp;

const options = {
  url: `${bundle.authData.server}/org/${bundle.authData.orgId}/contacts`,
  method: "GET",
  headers: {
    Accept: "application/json",
    Authorization: `Token ${bundle.authData.token}`,
  },
  params: {
    startTimestamp: timestart,
    endTimestamp: endtime,
    reportType: bundle.inputData.reportType,
    fields: bundle.inputData.fields,
  },
};

return z.request(options).then((response) => {
  response.throwForStatus();
  const results = Object.entries(response.json).map(([key, value]) => {
    return Object.assign({}, value, {
      id: key,
    });
  });
  return results;
});

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • Answer
  • April 2, 2021

@cozza13 - Try the following code snippet:

const timestart =
  Math.floor(Date.now() / 1000) - bundle.inputData.startTimestamp;
const endtime = Math.floor(Date.now() / 1000) - bundle.inputData.endTimestamp;

const options = {
  url: `${bundle.authData.server}/org/${bundle.authData.orgId}/contacts`,
  method: "GET",
  headers: {
    Accept: "application/json",
    Authorization: `Token ${bundle.authData.token}`,
  },
  params: {
    startTimestamp: timestart,
    endTimestamp: endtime,
    reportType: bundle.inputData.reportType,
    fields: bundle.inputData.fields,
  },
};

return z.request(options).then((response) => {
  response.throwForStatus();
  const results = Object.entries(response.json).map(([key, value]) => {
    return Object.assign({}, value, {
      id: key,
    });
  });
  return results;
});