Best answer

"Got a two or more results with the id of..." - how to combine attributes to make the id unique?


I have a trigger call which returns results with an id value. I add to set it explicitly in the code as it wasn’t returned as the first attribute within each result. My code is as follows:

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

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

The problem however is that it appears that the id’s are not always unique, which then throws the API invalid response error:

“Got a two or more results with the id of...”

This is an example of a result:

{
"date_downloaded": "2022-05-18T14:42:55.145Z",
"id": "string",
"asset_type": "string",
"product_type": "string",
"thumb_uri": "string",
"agreement_name": "string",
"product_id": 0,
"download_details": {
"download_notes": "string",
"project_code": "string"
}

My question: how could I set the Zapier item id to be a combination of the result’s id AND date_downloaded values so that it is always unique?

icon

Best answer by ikbelkirasan 18 May 2022, 17:15

View original

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

3 replies

Userlevel 7
Badge +11

Hi @intelligencebankproduct - You could concatenate the id value with the date_downloaded value to construct a unique ID.

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

const downloads = results["downloads"].map((item) => {
const id = `${item.id}.${item.date_downloaded}`;
return Object.assign(item, {
id,
_id: item.id, // Real item id
});
});

return downloads;
});

 

Thanks a lot for this! How can I prevent this code from returning the array error instead:

- Results must be an array, got: undefined, (undefined)

Response example:

{
"result_count": 8,
"downloads": [
{
"date_downloaded": "2022-05-17T10:13:08.47Z",
"id": "200134172-002",
"asset_type": "Image",
"product_type": "easyaccess",
"thumb_uri": "http://media.gettyimages.com/photos/group-of-friends-jumping-into-ocean-from-rock-cliff-picture-id200134172-002?b=1&k=20&m=200134172-002&s=170x170&h=YXzNQrWr9kHlxB9JSRGnQLv97-rZObNJwQZbdWXmsQo=",
"product_id": 119282,
"download_details": {},
"download_source": "api",
"size_name": "super",
"dimensions": {
"width": 4946,
"height": 3717,
"dpi": 118
}
},
{
"date_downloaded": "2022-05-17T08:57:27.893Z",
"id": "200133933-001",
"asset_type": "Image",
"product_type": "easyaccess",
"thumb_uri": "http://media.gettyimages.com/photos/young-man-doing-somersault-into-water-below-picture-id200133933-001?b=1&k=20&m=200133933-001&s=170x170&h=sgOJZ0p7ZbxBjjp_g8WUpfqlr4RE1nBzkKKlOhYEqW4=",
"product_id": 119282,
"download_details": {},
"download_source": "api",
"size_name": "super",
"dimensions": {
"width": 4898,
"height": 3680,
"dpi": 118
}
},
{
"date_downloaded": "2022-05-17T08:56:31.773Z",
"id": "200133933-001",
"asset_type": "Image",
"product_type": "easyaccess",
"thumb_uri": "http://media.gettyimages.com/photos/young-man-doing-somersault-into-water-below-picture-id200133933-001?b=1&k=20&m=200133933-001&s=170x170&h=sgOJZ0p7ZbxBjjp_g8WUpfqlr4RE1nBzkKKlOhYEqW4=",
"product_id": 119282,
"download_details": {},
"download_source": "api",
"size_name": "super",
"dimensions": {
"width": 4898,
"height": 3680,
"dpi": 118
}
},
{
"date_downloaded": "2022-05-17T08:55:38.307Z",
"id": "200133933-001",
"asset_type": "Image",
"product_type": "easyaccess",
"thumb_uri": "http://media.gettyimages.com/photos/young-man-doing-somersault-into-water-below-picture-id200133933-001?b=1&k=20&m=200133933-001&s=170x170&h=sgOJZ0p7ZbxBjjp_g8WUpfqlr4RE1nBzkKKlOhYEqW4=",
"product_id": 119282,
"download_details": {},
"download_source": "api",
"size_name": "super",
"dimensions": {
"width": 4898,
"height": 3680,
"dpi": 118
}
},
{
"date_downloaded": "2022-05-17T08:53:56.383Z",
"id": "200133933-001",
"asset_type": "Image",
"product_type": "easyaccess",
"thumb_uri": "http://media.gettyimages.com/photos/young-man-doing-somersault-into-water-below-picture-id200133933-001?b=1&k=20&m=200133933-001&s=170x170&h=sgOJZ0p7ZbxBjjp_g8WUpfqlr4RE1nBzkKKlOhYEqW4=",
"product_id": 119282,
"download_details": {},
"download_source": "api",
"size_name": "super",
"dimensions": {
"width": 4898,
"height": 3680,
"dpi": 118
}
},
{
"date_downloaded": "2022-05-17T08:16:17.413Z",
"id": "200133933-001",
"asset_type": "Image",
"product_type": "easyaccess",
"thumb_uri": "http://media.gettyimages.com/photos/young-man-doing-somersault-into-water-below-picture-id200133933-001?b=1&k=20&m=200133933-001&s=170x170&h=sgOJZ0p7ZbxBjjp_g8WUpfqlr4RE1nBzkKKlOhYEqW4=",
"product_id": 119282,
"download_details": {},
"download_source": "gettyimages.com",
"size_name": "medium",
"dimensions": {
"width": 1999,
"height": 1502,
"dpi": 118
}
},
{
"date_downloaded": "2022-05-17T08:15:52.043Z",
"id": "200134172-002",
"asset_type": "Image",
"product_type": "easyaccess",
"thumb_uri": "http://media.gettyimages.com/photos/group-of-friends-jumping-into-ocean-from-rock-cliff-picture-id200134172-002?b=1&k=20&m=200134172-002&s=170x170&h=YXzNQrWr9kHlxB9JSRGnQLv97-rZObNJwQZbdWXmsQo=",
"product_id": 119282,
"download_details": {},
"download_source": "gettyimages.com",
"size_name": "medium",
"dimensions": {
"width": 1999,
"height": 1502,
"dpi": 118
}
},
{
"date_downloaded": "2022-05-17T08:15:46.757Z",
"id": "82775180",
"asset_type": "Image",
"product_type": "easyaccess",
"thumb_uri": "http://media.gettyimages.com/photos/man-in-construction-outfit-on-toy-tractor-picture-id82775180?b=1&k=20&m=82775180&s=170x170&h=VZkbyQ5kKJ9vUCgs95o1xq3-QtM8hh6w4s6ttIIS4G8=",
"product_id": 119282,
"download_details": {},
"download_source": "gettyimages.com",
"size_name": "super",
"dimensions": {
"width": 5120,
"height": 3414,
"dpi": 300
}
}
]
}

 

Userlevel 7
Badge +11

Hey @intelligencebankproduct  - Sorry I just noticed that I didn’t actually return the array. The code snippet is updated now.