Question

My API is returning in invalid format


Newbie here… Trying to do something pretty basic, and can’t deem to get it to work.

 

Here is my code:

const options = {
  url: 'https://happeningout.api.accelo.com/api/v0/contacts/',
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'Authorization': `Bearer ${bundle.authData.access_token}`
  },
  params: {
    'page': bundle.meta.page,
    'sort': 'updated',
    'per_page': '100'
  }
}

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 error:

Invalid API Response: - Results must be an array, got: object, ({"response":[{"surname":"Example","firstname":"Con) - Got a result missing the "id" property ([{"surname":"Example","firstname":"Contact","id":"4","email":"contact@ExampleClient.com","mobile":""},{"id":"5","mobile":"2059011005","email":"darren.loli@loligroup.com","surname":"Loli","firstname":"Orlando"},{"id":"6","mobile":"9542940108","email":) What happened (You are seeing this because you are an admin): Executing triggers.new_contact.operation.perform with bundle Invalid API Response: - Results must be an array, got: object, ({"response":[{"surname":"Example","firstname":"Con) - Got a result missing the "id" property ([{"surname":"Example","firstname":"Contact","id":"4","email":"contact@ExampleClient.com","mobile":""},{"id":"5","mobile":"2059011005","email":"darren.loli@loligroup.com","surname":"Loli","firstname":"Orlando"},{"id":"6","mobile":"9542940108","email":) Console logs: Stack trace: CheckError: Invalid API Response: - Results must be an array, got: object, ({"response":[{"surname":"Example","firstname":"Con) - Got a result missing the "id" property ([{"surname":"Example","firstname":"Contact","id":"4","email":"contact@ExampleClient.com","mobile":""},{"id":"5","mobile":"2059011005","email":"darren.loli@loligroup.com","surname":"Loli","firstname":"Orlando"},{"id":"6","mobile":"9542940108","email":) at checkOutput (/var/task/node_modules/zapier-platform-core/src/app-middlewares/after/checks.js:42:15) at Object.collector.then.newOutput (/var/task/node_modules/zapier-platform-core/src/middleware.js:80:37) at bound (domain.js:402:14) at Object.runBound (domain.js:415:12) at Object.tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:517:31) at Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:574:18) at Promise._settlePromiseCtx (/var/task/node_modules/bluebird/js/release/promise.js:611:10) at _drainQueueStep (/var/task/node_modules/bluebird/js/release/async.js:142:12) at _drainQueue (/var/task/node_modules/bluebird/js/release/async.js:131:9) at Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:147:5) at Immediate.Async.drainQueues [as _onImmediate] (/var/task/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5) at process.topLevelDomainCallback (domain.js:126:23)


7 replies

Userlevel 7
Badge +11

Hi @hapening!

 

Can I double-check something? Are you using the Code by Zapier app in a Zap or are you building an app integration using the Zapier Developer Platform? That will help to give us some context for this 🙂

@Danvers I’m in developer.zapier.com

also @Danvers if I add brackets [ ] like so:

const options = {
  url: 'https://happeningout.api.accelo.com/api/v0/contacts/',
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'Authorization': `Bearer ${bundle.authData.access_token}`
  },
  params: {
    'page': bundle.meta.page,
    'sort': 'updated',
    'per_page': '100'
  }
}

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 solve the array/object issue, but then get this error:

Invalid API Response: - Got a result missing the "id" property ({"meta":{"status":"ok","message":"Everything executed as expected.","more_info":"https://api.accelo.com/docs/#status-codes"},"response":[{"id":"4","email":"contact@ExampleClient.com","firstname":"Contact","surname":"Example","mobile":""},{"surname":") What happened (You are seeing this because you are an admin): Executing triggers.new_contact.operation.perform with bundle Invalid API Response: - Got a result missing the "id" property ({"meta":{"status":"ok","message":"Everything executed as expected.","more_info":"https://api.accelo.com/docs/#status-codes"},"response":[{"id":"4","email":"contact@ExampleClient.com","firstname":"Contact","surname":"Example","mobile":""},{"surname":") Console logs: Stack trace: CheckError: Invalid API Response: - Got a result missing the "id" property ({"meta":{"status":"ok","message":"Everything executed as expected.","more_info":"https://api.accelo.com/docs/#status-codes"},"response":[{"id":"4","email":"contact@ExampleClient.com","firstname":"Contact","surname":"Example","mobile":""},{"surname":") at checkOutput (/var/task/node_modules/zapier-platform-core/src/app-middlewares/after/checks.js:42:15) at Object.collector.then.newOutput (/var/task/node_modules/zapier-platform-core/src/middleware.js:80:37) at bound (domain.js:402:14) at Object.runBound (domain.js:415:12) at Object.tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:517:31) at Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:574:18) at Promise._settlePromiseCtx (/var/task/node_modules/bluebird/js/release/promise.js:611:10) at _drainQueueStep (/var/task/node_modules/bluebird/js/release/async.js:142:12) at _drainQueue (/var/task/node_modules/bluebird/js/release/async.js:131:9) at Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:147:5) at Immediate.Async.drainQueues [as _onImmediate] (/var/task/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5) at process.topLevelDomainCallback (domain.js:126:23)

Im Getting the same issue for ID and cannot solve via forums so far.

My Array is as ‘Items’ and the Identifier is UID. I can’t for the life of me figure out how to parse UID as ID. Any help would be greatly appreciated.

const options = {
url: 'REDACTED',
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${bundle.authData.access_token}`,
'x-myobapi-version': 'v2',
'x-myobapi-key': 'REDACTED',
'x-myobapi-cftoken': 'REDACTED'
},
params: {

}
}

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

Thanks

Userlevel 6
Badge +9

@hapening try 

 

return results.response

 

For polling triggers, Zapier expects a bare array of the objects that will get passed to a Zap (each row will cause 1 Zap execution). Each object must have and explicitly named `id` field that uniquely identifies that object (so Zapier knows whether or not it’s already triggered a Zap with that object). Zapier doesn’t do any digging through objects and guessing about the right array to use - we need the integration to be explicit.  So you’re super close, you even have an id field, just lift that array out and return that to us and you should be up and running.

Userlevel 6
Badge +9

@Brodersen  if you post the json your API is returning we can probably share some tips on how to address the id issue.  I suspect what you’ll need to do is add an `id` field to each object and assign the value of the `UID` field to it. Something like this: 

 

Userlevel 7
Badge +9

Hi @hapening 

Please return ‘results.response’ instead of just results

@Brodersen 

Assuming your results array is results.Items you can loop through setting the UID as the id

I.e.

 

results.Items.forEach(item => {

item.id = item.UID

})

return results.Items

Reply