Contentful logo

Contentful Community

How to sync product from Shopify

Hi all,
I am trying to sync products from a Shopify store to our Contentful space using Shopify webhooks. So far I’m able to use the Management API SDK to create a new entry (product) with a linked asset (product image) that is uploaded from Shopify. The issue I’m having is creating a new entry and uploading multiple assets (images) that need to link to my entry. What’s the best way to accomplish this?

This is what I’m using to create a new entry with a single asset…
Thank you in advance!!

const newEntry = await client
.getSpace(space.sys.id)
.then((space) => space.getEnvironment(environment.sys.id))
.then((environment) =>
environment
.createAssetWithId(assetId, {
fields: {
title: {
“en-US”: imageTitle,
},
file: {
“en-US”: {
contentType: “image/jpeg”,
fileName: imageName,
upload:
imageUrl,
},
},
},
})
.then((asset) => asset.processForAllLocales())
.then((asset) => asset.publish())
.then((asset) => {
return environment.createEntryWithId(“product”, entryId, {
fields: {
title: { “en-US”: title },
slug: { “en-US”: slug },
images: {
“en-US”: [
{
sys: {
id: asset.sys.id,
linkType: “Asset”,
type: “Link”,
},
},
],
},
},
});
})
.catch((err) => {
console.error(“Error:”, err);
return {
statusCode: 500,
body: “Error”,
};
})
);