Rest API error: The result was not an array

Hi,

when running a test for the Rest API I addedd under Get collection (GET) I can see a result coming back but with an error.

This is what I get:

Error: Error:
The result was not an array. Maybe the data you’re looking for is inside one of the response object keys?

{
“n”: 62,
“jobs”: {
“53819”: {
“ID”: 53819,
“slug”: “job-test1”,
“title”: “Job Test 1”,
“content”: “This is where the job description is.”,
“url”: “https://www.url.com”,
“employer”: {
“name”: “Employer Test”,
“address”: “Street 1, 1060 City”
},

I tried adding different values to the Response key path, but I always get the same error back.
Is there maybe something wrong with results?
Shouldn’t there be brackets [ and ] in the results?

Thanks for your help!

Looks like your API is not returning an array but instead a single object, unless there’s something bugging out. Is the raw API request something you can share so we could check it out?

Here is the URL of the API I am using (I created a bit.ly URL):

deleted URL

Maybe that helps?

Thanks!

So the issue is that your response does not contain an array of data, but instead an object with ID keys pointing to the data. Unfortunately, this sort of data transformation is not possible directly from the REST data configurator.

Are you able to edit the current endpoint or create an additional endpoint that would return the jobs objects inside an array?

Alternatively, you could define the item schema manually into an app/page variable, use HTTP request to fetch the raw response, then use a formula to map the data into an array for Set page variable:

VALUES(outputs["HTTP request"].resBody.jobs)
1 Like

Great, thanks for the information!
I will try adding the item schema manually first, if that doesn’t work for some reason, I will ask a developer to edit the endpoint.

1 Like

Hi again,
I tried your alternative suggestion and add the item schema manually into an app variable.
Then I used the http request node to fetch raw response.
But the last step (“use a formula to map the data into an array for Set page variable”) is where I am stuck.

Do I need to change anything in this formula:
VALUES(outputs["HTTP request"].resBody.jobs)

Some values I want to use from my feed are "title, “url” and “posted_date”.
On the screenshot you can see the raw response I get from the JSON feed.

Thanks for your help!

How does the result of that formula look like if you use the debugger or paste it to an Alert node? It should be an array of objects like

[
  {
    "ID": 14417,
    "title": "...",
  }
]

though of course with more fields.

It looks like this:

I put the feed URL in the http request node and the formula in the Dialog message.

Does my last response help? The id of my project is 98833.

I think I am pretty close to a solution here. :slight_smile:

@Harri_Sarsa Does the screenshot help in any way? I appreciate your help!
Thanks

Jo_Li, maybe I could help, but the screen shot needs to have visible the first instance of the object in your initial question and some lines before it, in order to identify the structure of the API response.

@Eduardo_Jaramillo Thanks Eduardo!

This is the URL of the feed: https://shorturl.at/npGQ6 where you can see the response.

Sorry Jo_Li, but the link redirects to the shorturl.at page, not to your feed. Can you check it out?

that’s strange. here is the actual URL:
(deleted URL)

Jo_Li,

Looking up your data, the most probable cause for the REST API direct integration not returning an array, but an object is in the GETALL return schema, which should reflect your data structure buy can have some variations depending on your database engine. Since the key for each set of data is a number, it will be rather long and prone to problems if there are new sets (the schema would change with every modification to the data and as the return data wouldn’t match the schema, it will be treated as an object, not an array). In the following image you can see the problem:
image

As you can see in the following example, the record number is not a key but a simple value and the data sets is inside the “fields” key (inmutable)
image

Hope this helps,

Thanks for checking and your help.
I will check with a developer to see what we can do to fix this.