Question

Invalid API Response: - Got a result missing the "id" property

  • 22 June 2020
  • 8 replies
  • 3020 views

Userlevel 2
Badge

Hello!

 

I am having trouble with getting data from a GET call for an array related to lists in an email platform. I am not sure if the array if formatted properly causing the issue. 

 

Here is the error:

 

Invalid API Response: - Got a result missing the "id" property ({"ListID":19962972,"Name":"Hank Only Test List","Description":"Hank","ActiveMembers":5,"IsActive":true,"Links":[]}) What happened (You are seeing this because you are an admin): Executing triggers.retrieve_lists.operation.perform with bundle Invalid API Response: - Got a result missing the "id" property ({"ListID":19962972,"Name":"Hank Only Test List","Description":"Hank","ActiveMembers":5,"IsActive":true,"Links":[]}) Console logs:

← Test Again

Finish Testing & Continue

----

Here is the code: 

const options = {
  url: 'https://edapi.campaigner.com/v1/Lists',
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'X-API-KEY': bundle.authData.ApiKey
  },
  params: {
    'ApiKey': bundle.authData.ApiKey
  }
};

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.Lists;
});
 

 

--

 

Here is what is returned normally from an API call:

 

{

"Lists": [  {

"ListID": 19962972,

"Name": "Hank Only Test List",

"Description": "Hank",

"ActiveMembers": 5,

"IsActive": true,

"Links": [],

},

 

Can someone help with the formatting of the API call in Zapier?

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

8 replies

Userlevel 7
Badge +12

@hank3rd - Each returned item must have an ID. Try the code below instead.

const options = {
url: "https://edapi.campaigner.com/v1/Lists",
method: "GET",
headers: {
Accept: "application/json",
"X-API-KEY": bundle.authData.ApiKey,
},
params: {
ApiKey: bundle.authData.ApiKey,
},
};

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;

const lists = results["Lists"].map((item) => {
return {
...item,
id: item["ListID"],
};
});

return lists
});

 

Userlevel 2
Badge

@ikbelkirasan that seems to work even though there are some errors about missing }’s ect. Do I need to resolve them?

 



I am going to fully test this in a call now. I will report back. 

 

Userlevel 7
Badge +12

@hank3rd - The code is correct and doesn’t have errors but that editor doesn’t support recent JavaScript syntax (yet) which is supported by Zapier Platform. You can use the code snippet below instead to eliminate those errors and warnings:

const options = {
url: "https://edapi.campaigner.com/v1/Lists",
method: "GET",
headers: {
Accept: "application/json",
"X-API-KEY": bundle.authData.ApiKey,
},
params: {
ApiKey: bundle.authData.ApiKey,
},
};

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;

const lists = results["Lists"].map((item) => {
return Object.assign(item, {
id: item["ListID"],
});
});

return lists;
});

 

Userlevel 2
Badge

I think that I will keep it as is for now. Thank you for your help.

 

I am now trying to use that in an Action to add subscribers to a list and I am getting a error about Email Address not being valid. I think that it might be similar and need to add more code. 

This is the API output:

 

const options = {
  url: 'https://edapi.campaigner.com/v1/Subscribers',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'X-API-KEY': bundle.authData.ApiKey
  },
  params: {
    'ApiKey': bundle.authData.ApiKey
  },
  body: {
    'EmailAddress': bundle.inputData.EmailAddress,
    'Lists': bundle.inputData.Lists
  }
}

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;
  });

 

Here is a sample Post call:

 


 

I think that I need at least an email address and List “ID” from the LIST trigger you helped with. Would you be able to help?

 

POST https://edapi.campaigner.com/v1/Import/Subscribers HTTP/1.1
ApiKey: 67*************8e
Content-Type: application/jsonW

{
"Subscribers": [
{
"EmailAddress":"contact1@example.net",
"CustomFields": [
{
"FieldName":"FirstName",
"Value":"Bob"
},
{
"FieldName":"Age",
"Value":"32"
}
],
"Publications":[
3
],
"Lists": [
2,
12,
44
],
Userlevel 2
Badge

I am going to try working with this, which is a combo from the CONTACT Action I have, need to get the syntax right to add the list. 

 

const options = {
  url: 'https://edapi.campaigner.com/v1/Subscribers',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'X-API-KEY': bundle.authData.ApiKey
  },
  params: {
    'ApiKey': bundle.authData.ApiKey
  },
   body: {
    'EmailAddress': bundle.inputData.EmailAddress,
    
    'CustomFields':[
    {
   
      'FieldName':'FirstName',
      'Value':bundle.inputData.FirstName,
      "Lists":bundle.inputData.ListID,
    
  }]
}};
}

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;
  });

Userlevel 2
Badge

@ikbelkirasan I think that I was able to correct the input and call to pass some data. I am good for now, but will open a new thread if another issue comes up. 

In a previous app I built years ago, nested call data was not necessary, so this is a little bit of a struggle for me!

 

 

Userlevel 2
Badge

@ikbelkirasan I was hoping that you might be able to help me format another item. I am trying to pull custom fields to be able to offer up as a line item in the Zap. The struggle is that it is not a simple api string. I think that I need to use a call to “Database” items. 

Here is the info from the API documentation:

 

Sample: GET https://edapi.campaigner.com/v1/Database HTTP/1.1
ApiKey: 67c27802(******4196-b44c-460245d4978e

 

Response:

 

HTTP/1.1 200 OK

Content-Type: application/json; charset=utf-8

{
"DatabaseColumns":[
{
"ColumnName":"EmailID",
"ColumnType":"Int",
"ColumnSize":0,
"IsCustom":false,
"Variable":"[
Contact!EmailID
]",
"Links":[
{
"rel":"self",
"href":"https://edapi.campaigner.com/v1/Database/EmailID"
}
]
},

Here is what I have that is not working. I think that I need the Database columns where the IsCustom is true. 

 

 

// Configure a request to an endpoint of your api that
// returns custom field meta data for the authenticated
// user.  Don't forget to congigure authentication!

const options = {
  url: 'https://edapi.campaigner.com/v1/Database',
  method: 'GET',
  headers: {
    'Accept': 'application/json'
  },
  params: {

  }
};

return z.request(options).then((response) => {
  response.throwForStatus();
  const results = response.json;

  const data = results["Database"].map((item));

    

  return data;
});

 


If I need to start a new thread let me know. 

 

Thank you for your help. 

Userlevel 2
Badge

I was able to get the API test to pull the data, but it is not showing in the forms for the end user?

Here is the code:

return z.request(options).then((response) => {
  response.throwForStatus();
  const results = response.json;

  const col = results["DatabaseColumns"].map((item) => {
    return {
      ...item,
      id: item["ColumnName"],
    };
  });

  return col
});
 

And it looks like this in the Zap:

 

 

I am sure I am missing something simple.