Thank you Tyler!
I have a functional custom flow for the simple items, but still working on the variant/parent flow to see if I can do them in a single flow. This is done in a custom flow I but would obviously love to see this become built in functionality on Celigos end so it could use the metafields under Product > Settings.
The basic structure is to create or modify your saved search in Netsuite. Then in the custom name column use this naming convention.
namespace.key (Meta)
So if your metafield is in the namespace facts and your metafields API name is product_line the custom name would be facts.product_line (Meta). Additionally make sure to include the Shopify Product Id from the Celigo Shopify Item Id Map in the saved search as it is needed in the next step.
Once the saved search is setup and ready to be used in the import step then you can populate the mock output with live data and save the step. Then add a transformation and use this javascript.
function transformToMetafields(options) {
const { record } = options;
const metafields = [];
const ownerId = `gid://shopify/Product/${record.product_id}`;
Object.keys(record).forEach((key) => {
const metaMatch = key.match(/^(.*?)\.(.*?) \(Meta\)$/);
if (metaMatch) {
const [, namespace, rawKey] = metaMatch;
metafields.push({
ownerId: ownerId,
namespace: namespace,
key: rawKey.replace(/\s+/g, "_"),
value: String(record[key]),
});
}
});
return { metafields };
}
This should return data that looks like this.
{
"metafields": [
{
"ownerId": "gid://shopify/Product/12345",
"namespace": "facts",
"key": "product_line",
"value": "Foundations"
},
{
"ownerId": "gid://shopify/Product/12345",
"namespace": "facts",
"key": "series",
"value": "Learning SQL"
}
}
Finally create an import step for the Shopify store. Set HTTP method to POST with a relative URI of /graphql.json.
This method is using the MetafieldsSet mutation which can set up to 25 metafields at a time. If you have more than that you will have to run multiple flows or split the record somehow. The query should be set to the following string.
{
"query": "mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message code } } }",
"variables": {{{jsonSerialize record}}}
}