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?
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?
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:
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.
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.
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.
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:
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)
Not sure where this all landed, but I had the same issue today while testing a connection. The problem ended up being the use of the ‘Resource URL’ in the ‘response key path’ input. I am NOT a coder, so I found this forum and realized my issue through the tutorials post by Steve Stava on YouTube. Just posting in the event this helps someone else down the road.
Hello, I am running into the same issue the OP had. I am hoping you can elaborate a bit more on the solution you found. Did you need to add or remove something to the ‘response key path’? Thanks in advance:)