Question

Invalid API Response: - Got a non-object result, expected an object from create (undefined)

  • 2 March 2021
  • 2 replies
  • 34 views

Userlevel 1

I am building an integration using the online developer portal 

I am getting the response  - Invalid API Response: - Got a non-object result, expected an object from create (undefined) when trying to create a record via our api .

In postman I get the following response from our api
{
    "id": "df6fd489-a498-4f48-b1f0-d330ede11597",
    "policy_group_id": null,
    "policy_group": {
        "id": null,
        "name": null
    },
    "name": "Dare Inc3",
    "policy_ref_number": "11211",
    "user_id": "xxxxxxxxxx-1564-44d0-835f-2447710a0b7b",
    "user": {
        "id": "xxxxxxxxx-1564-44d0-835f-2447710a0b7b",
        "sub": "xxxxxxxxx5e5b9006a14707d",
        "first_name": "Martin",
        "last_name": "",
        "avatar": "https://s.gravatar.com/avatar/cb135195defd73b472707171c06137ee?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fma.png",
        "email": "martin@xxxxxxxx"
    },
    "policy_holder_id": "xxxxxxx-0ec7-4ed8-96cf-bc9cb20276e1",
    "policy_holder": {
        "id": "xxxxxxxxx-0ec7-4ed8-96cf-bc9cb20276e1",
        "name": "Martin xxxx",
        "email": null
    },
    "product": "some product",
    "gross_value": "239.89",
    "commission_split_template_id": null,
    "commission_template_id": null,
    "start_date": "2021-03-01T00:00:00.000000Z",
    "end_date": "2022-02-28T00:00:00.000000Z",
    "premium_value": 679.9,
    "payment_frequency_type": "month",
    "payment_frequency": 1,
    "status": "active",
    "created_at": "2021-03-02T11:49:23.000000Z",
    "updated_at": "2021-03-02T11:49:23.000000Z"
}

The code in the API request is 

const options = {
  url: `https://us-east-1-app-staging/api/v1/organisation/${bundle.inputData.organisation}/policies`,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-TOKEN': bundle.authData.token
  },
  
  body: {
    'policy_holder_id': bundle.inputData.policy_holder_id,
    'name': bundle.inputData.name,
    'policy_ref_number': bundle.inputData.policy_ref_number,
    'premium_value': bundle.inputData.premium_value,
    'start_date': bundle.inputData.start_date,
    'end_date': bundle.inputData.end_date
  }
}

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

Any ideas why the error is happening?

Thanks in advanced.


2 replies

Userlevel 6
Badge +9

Can you share what you’re seeing in your Zapier logs? Verifying the request in Postman is a great first sanity check. The next is seeing exactly what’s getting returned from your API to your request handler, and from your request handler to Zapier, and if it’s different that what you see in Postman, then working backward to figure out what’s different about the request, etc.  You can find logs in the “Monitoring” section on the left hand navigation of the UI - click a point on the graph to see the logs.  If you’re testing with the embedded test component in the UI you’ll see HTTP and bundle logs there.  

Userlevel 1
Badge

try adding a [] to your object

 

[{
"id": "df6fd489-a498-4f48-b1f0-d330ede11597",
"policy_group_id": null,
"policy_group": {
"id": null,
"name": null
},
"name": "Dare Inc3",
"policy_ref_number": "11211",
"user_id": "xxxxxxxxxx-1564-44d0-835f-2447710a0b7b",
"user": {
"id": "xxxxxxxxx-1564-44d0-835f-2447710a0b7b",
"sub": "xxxxxxxxx5e5b9006a14707d",
"first_name": "Martin",
"last_name": "",
"avatar": "https://s.gravatar.com/avatar/cb135195defd73b472707171c06137ee?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fma.png",
"email": "martin@xxxxxxxx"
},
"policy_holder_id": "xxxxxxx-0ec7-4ed8-96cf-bc9cb20276e1",
"policy_holder": {
"id": "xxxxxxxxx-0ec7-4ed8-96cf-bc9cb20276e1",
"name": "Martin xxxx",
"email": null
},
"product": "some product",
"gross_value": "239.89",
"commission_split_template_id": null,
"commission_template_id": null,
"start_date": "2021-03-01T00:00:00.000000Z",
"end_date": "2022-02-28T00:00:00.000000Z",
"premium_value": 679.9,
"payment_frequency_type": "month",
"payment_frequency": 1,
"status": "active",
"created_at": "2021-03-02T11:49:23.000000Z",
"updated_at": "2021-03-02T11:49:23.000000Z"
}]

 

Reply