skip to Main Content

I’m integrating a CRM with Facebook lead Ads using Zapier, and I can create a lead in Facebook and create it in the CRM without any issues.

After a successful post (i.e. successfully creating the lead), I’m curious what I should be returning, I would have thought

          return Ok();

would have been enough. Instead, I get an error message saying:

– Got a non-object result, expected an object from create ()
What happened (You are seeing this because you are an admin):
Executing creates.ZapLead.operation.perform with bundle
Invalid API Response:
– Got a non-object result, expected an object from create ()

What should I be returning?

Code which makes the post is:

perform: (z, bundle) => {
  const promise = z.request({
    url: 'https://{{bundle.authData.subdomain}}.ngrok.io/api/zapier/create/lead/' + bundle.inputData.lead_type + '/' + bundle.inputData.core_customerTypeId,
    method: 'POST',
    body: JSON.stringify({
      fields: bundle.inputData
    }),
    headers: {
      'content-type': 'application/json'
    }
  });

  // return promise.then((response) => JSON.parse(response.content));
  return promise.then((response) => {   
    if (response.status != 200) {
      throw new Error(`Unexpected status code ${response.status}`);
    }
});

Any ideas?

Thanks,

2

Answers


  1. Chosen as BEST ANSWER

    I think I found it. Looks like I need to return this if successful:

    {"Success":"Success","Attempt":null,"Id":null,"RequestId":null}


  2. David here, from the Zapier Platform team.

    While your answer is technically correct, I wanted to add some context about the error and why your solution works.

    Zapier expects a javascript object (basically anything valid and wrapped in {}) to come out of a create function. That’s why JSON.parse(response.content) works, it’s returning whatever the server said. Your code throws an error if it’s not a 200, but doesn’t return anything if it is a 200. Since undefined is not of type Object, the error you’re seeing is thrown.

    While {"Success":"Success","Attempt":null,"Id":null,"RequestId":null} is totally a valid response (it’s an object!), it’s more useful for the end-user to return data about the new lead that was created. That way, it can be used downstream for other actions.

    ​Let me know if you’ve got any other questions!


    As a side note, we’re very open to how to make that error message more clear; it’s one devs struggle with a lot.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search