Zapier gives the error: Invalid API Response: - Results must be an array, got: object, ({"ID":”1234567","Prefix":"","FirstName":"John","M) - Got a result missing the "id" property (“1234567")
After doing many web searches, I found that the parentheses should be replaced with square brackets to indicate it is an array. Is this correct, and if so how do I go about doing this? I am not very familiar with JavaScript and feel pretty lost. I have tried the replace function, but did not have any luck. Many of my attempts resulted in similar errors indicating that it was now a string, not an object, etc.
I would appreciate any tips for solving this issue.
Thank you.
Page 1 / 1
Hey - Quick check without looking to deep into this - Have you tried just sending the object in an array?
so instead of
{}
Send like this
>{}]
That’s the first thing I’d try
Hi there @colinr ,
I don’t think this is an issue with the array or object. I believe the javascript HTTP request should be just fine working with an object, and Zapier prefers to work with this as well.
Zapier gives the error: Invalid API Response: - Results must be an array, got: object, ({"ID":”1234567","Prefix":"","FirstName":"John","M) - Got a result missing the "id" property (“1234567")
So I am not sure what kind of API you are calling, or what kind of request / respons it expects (this would make it a lot easier), but it looks like this could be a API error. I see you are calling the HTTP with;
Because of that I think the API expects an ID and you are giving none. Which could cause this.
Let me know if this works, or if you have any additional questions.
~Bjorn
Hi Bjorn & Saastronomical,
Bjorn, I tried making the changes you suggested and I receive the following error:
“inputData is not defined What happened (You are seeing this because you are an admin): Executing triggers.get_partner_by_id.operation.perform with bundle inputData is not defined”
The API I am using has very poor documentation and I feel is outdated. I do not know what kind of response it expects. There is a code sample in jQuery here but it is Greek to me:
Saastronomical, I am not seeing where to make that change in the code. I’d appreciate any guidance.
Thank you both very much, this API has been very frustrating so far!
@ForYourIT
About your thought: “Because of that I think the API expects an ID and you are giving none. Which could cause this.”
The ID is being sent as part of the API request. It is the PartnerID that is being searched for and results are at least partially returned as shown in my error message in the original post. The ID for this test run is 1234567, so I’m not sure what the problem is. I’m really hating this API.
@Saastronomical Saastronomical, I am not seeing where to make the changes you suggested in the code. I’d appreciate any guidance.
Sorry, I must have been tired since I just now understood you are creating an app and didn't run some javascript code on a webhook. You should keep those variables “bundle.inputData.PartnerID”.
Now I have tried the following code to transfer the json object in an array:
for(var i in json_data) result.push(.i, json_data _i]]);
return results;
});
Let me know if this works or you still getting an error.
~Bjorn
Hi @ForYourIT,
Thank you very much Bjorn, I think we are all tired (I sure am!) I tested your code (I did modify the code slightly as some parts used “result” instead of “results”, but I did try what you sent over first). I am getting the error below:
Invalid API Response: - Got a non-object result in the array, expected only objects (o"ID",”1234567"]) - Got a result missing the "id" property ( "ID",”1234567"]) What happened (You are seeing this because you are an admin): Executing triggers.get_partner_by_id.operation.perform with bundle Invalid API Response: - Got a non-object result in the array, expected only objects (n"ID",”1234567"]) - Got a result missing the "id" property (""ID",”1234567"])
I also tested this code in a different trigger I am building with the same basic setup, but instead of searching by PartnerID, it searches by Email address. (The results returned from either search would the the same fields as below.) I received the same error above for the Email test as well.
I don’t know if this helps, but here is a sample response body format for this API call (PartnerID search) from the API documentation: (The first item labeled “ID” is the PartnerID being searched for using the bundle.inputData.PartnerID input field):
Thank you again for your help, Bjorn, I owe you a few beers!!
So I haven’t made a custom Zapier integration before, but mainly worked with AWS Lambda / Fargate and then used a webhook but this will be interesting to take a look at. Anyway, we are having a new error so we are getting somewhere. Here is what I see:
Now we are returning an array with strings (>"ID",”1234567"]), however, it is expecting objects within an array (<"ID": ”1234567"])
We do not have the specific key that Zapier expects called “id”, which should be unique and always present. You can read more about that here (same as what you found).
Now bear with me, I am no developer...I got a team for that haha. However, I will use all my knowledge to help you out.
results.map is not a function What happened (You are seeing this because you are an admin): Starting GET request to https://myfakeurl.com/api/partner/ID/1234567 Received 200 code from https://myfakeurl.com/api/partner/ID/1234567?PartnerID=1234567 after 830ms Received content "{"ID":"1234567","Prefix":"","FirstName":"John","MiddleName":"","LastName":"Doe","Suffix":"","Salut" results.map is not a function
And this code:
return z.request(options).then((response) => { response.throwForStatus(); let items = response.json;
items.forEach(item => { item.id = item.ID; })
return items; });
Gives the following error:
items.forEach is not a function What happened (You are seeing this because you are an admin): Starting GET request to https://myfakeurl.com/api/partner/ID/1234567 Received 200 code from https://myfakeurl.com/api/partner/ID/1234567?PartnerID=1234567 after 860ms Received content "{"ID”:”1234567”,”Prefix":"","FirstName”:”John”,”MiddleName":"","LastName”:”Doe”,”Suffix":"","Salut" items.forEach is not a function
I’d appreciate any input as to what the issue might be, Bjorn suggested @ikbelkirasan but I’m not sure how to ask them to take a look.
Best Regards!
Hi @colinr and @ForYourIT - Just saw my name by chance lol - I didn’t get any notification!
So I don’t know if you got the issue fixed already or not. The error mentioned that the response must be an array. So, since the API response is a single object, wrapping it in an array should be the way to go.
Thank you for the response! I tried the code you gave and got this error:
Invalid API Response: - Got a result missing the "id" property ({"ID":"12334567","Prefix":"","FirstName":"John","MiddleName":"","LastName":"Doe","Suffix":"","Salutation":"","Spouse":"","SpouseLastName":"","Company":"","Address1":"3432 Arnold Ave","Address2":"","City":"San Diego","StateProv":"CA","PostalCode":"9210) What happened (You are seeing this because you are an admin): Executing triggers.get_partner_by_id.operation.perform with bundle Invalid API Response: - Got a result missing the "id" property ({"ID":"1234567","Prefix":"","FirstName":"John","MiddleName":"","LastName":"Doe","Suffix":"","Salutation":"","Spouse":"","SpouseLastName":"","Company":"","Address1":"3432 Arnold Ave","Address2":"","City":"San Diego","StateProv":"CA","PostalCode":"9210) Console logs: { ID: '1234567', Prefix: '', FirstName: 'John', MiddleName: '', LastName: 'Doe', Suffix: '', Salutation: '', Spouse: '', SpouseLastName: '', Company: '', Address1: '3432 Arnold Ave', Address2: '', City: 'San Diego', StateProv: 'CA', PostalCode: '92104-3438', CountryCode: 'US', PartnerPhones: ], PartnerAskArrays: ], Email: 'test@test.com', EmailPreference: '', WebURL: '', BirthDate: '1976-06-22T00:00:00', WeddingDate: null, MemberDate: '2020-04-25T03:08:31.493', OriginSource: 'Online', RequiresQC: false, Deceased: false, NoResponseLetters: false, NoDirectMail: false, NoTaxStatements: false, NoPhoneSolicitation: false, NoEmailSolicitation: false, UndeliverableAddress: false, NoMerge: false, VIP: false, Prospect: false, UndeliverableEmail: false, NoResponseEmails: false, NoAddressStandardization: false, WebUsername: '', WebPassword: '', WebMustChangePassword: false, WebPasswordRecoveryToken: null, WebPasswordTokenExpiration: null, CustomFlags: ], CustomDataFields: ] }
I received this error before and tried to address it with the code below (from @ForYourIT) but it returned an error.
return z.request(options).then((response) => { response.throwForStatus(); let items = response.json;
items.forEach(item => { item.id = item.ID; })
return items; });
I received this error:
items.forEach is not a function What happened (You are seeing this because you are an admin): Starting GET request to https://myfakeurl.com/api/partner/ID/1234567 Received 200 code from https://myfakeurl.com/api/partner/ID/1234567?PartnerID=1234567 after 860ms Received content "{"ID”:”1234567”,”Prefix":"","FirstName”:”John”,”MiddleName":"","LastName”:”Doe”,”Suffix":"","Salut" items.forEach is not a function
results.map is not a function What happened (You are seeing this because you are an admin): Starting GET request to https://uat-connect.aegispremier.com/api/F1331B55-403C-4C15-957D-C4C663E1ABB9/partner/ID/7417451 Received 200 code from https://uat-connect.aegispremier.com/api/F1331B55-403C-4C15-957D-C4C663E1ABB9/partner/ID/7417451?PartnerID=7417451 after 830ms Received content "{"ID":"7417451","Prefix":"","FirstName":"Colin","MiddleName":"","LastName":"Reed","Suffix":"","Salut" results.map is not a function
I’m not sure how to address these problems! Thank you very much for everyone’s help with solving this.
@ikbelkirasan Wonderful! This request was successful, yay! Although in code mode, Zapier marked some lines with a red X. Do you think this will cause issues further down the line? I have attached screenshots below.
Thank you so very much for your help, it was driving me nuts!
Haha thanks @ikbelkirasan ! Weird you didn’t get a notification. Good you could help out.
Great you got it solved @colinr. I think those are just some warnings / issues with indention. But maybe @ikbelkirasan got a better answer for this
@ForYourIT Yeah, I wasn’t notified because when you mentioned, my name didn’t become a link. :)
@colinr You’re welcome and don’t worry, the reason behind those warnings is that the code editor in the Platform UI seems to be old and doesn’t support the spread operator (the 3 dots) which is an ES6 feature.
Replace it with this one and it should remove the warnings: