Skip to main content
Best answer

Configuring Simple API Request for Help Scout

  • January 21, 2021
  • 1 reply
  • 205 views

Forum|alt.badge.img

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!

Best answer by ZaneBest answer by Zane

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.

 

 

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

Forum|alt.badge.img+9
  • Zapier Staff
  • 331 replies
  • Answer
  • January 21, 2021

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.