Best answer

Configuring Simple API Request for Help Scout

  • 21 January 2021
  • 1 reply
  • 174 views

Userlevel 3
Badge

Hi there,

 

I am new to APIs and have very limited experience with them (and coding in general), but I am attempting to make an API request using Zapier’s Developer Platform.

 

I got past authentication but now I am struggling to effectively make an API request.

 

The error I am receiving is:

Invalid API Response: - Results must be an array

As per Zapier Documentation, I realize that I need to make sure the results are returned as an array.

I am uncertain of what I might add to the Code Editor to make that happen:
 

const options = {
url: 'https://api.helpscout.net/v2/reports/company',
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${bundle.authData.access_token}`,
'X-TYPES': bundle.inputData.types
},
params: {
'start': '2021-01-01T12:00:00Z',
'end': '2021-01-02T12:00:00Z',
'types': bundle.inputData.types
}
}

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

 

 

If anyone has any tips for a total beginner, I’d super appreciate a pointer in the right direction here!

icon

Best answer by Zane 21 January 2021, 16:13

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.

1 reply

Userlevel 7
Badge +9

This will help: https://platform.zapier.com/docs/faq#i-got-an-an-array-is-expected-error-how-do-i-fix-that

 

In your case, wrap results in array brackets in your return statement.  `return [results];`

 

Anticipating the common next question: Make sure the object referenced by `results` contains a unique field called `id`.  If it doesn’t you can add one in code before returning, setting it to another value or concatenated values of the object to derive a unique identifier for the object.  There’s some other answers in this community that have examples of solving that problem.