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 = resultsl"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
}
}
]
}
Hey @intelligencebankproduct - Sorry I just noticed that I didn’t actually return the array. The code snippet is updated now.