Shopify GraphQL - Clears Metafields if Not Included

Was having a conversation with many people under this article but they apparently turned off comments or something.

If you are not aware the new GraphQL will clear out all metafields that are not mapped. This is apparently expected functionality with the productSet mutation. I'm looking for anything to make this work as we do not have any plans to integrate every Metafield and need to find a work around.

@nickhilbelink sorry about that and thanks for bringing the conversation over here. It has always been hard to follow comments on documentation so with the new community we decided to turn off doc comments and guide users to the community for questions.

Here is a pdf output of the conversation that was there:
Configure the new GraphQL-based Product flows – Celigo Help Center.pdf (3.1 MB)

Tagging users that were on that thread: @nileshkumar @craigscott @emilyminck @sandrahill @jasoncraveiro @joshuadrew @sairachamalla @michaelsen @stevebasler @dipalimose @timothyblevins @vincearnone

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

Hi @nickhilbelink

Thanks so much for opening this thread here, it took me a while to find it, as although I was tagged I didn't receive any notification. I was part of that original conversation, but the PDF does not include my response to your last comment.

Since the comments were removed I have opened a ticket with support on this issue as it is a major concern for our integration (241304):

I have realised I have a significant issue with the new graphQL product flows. The flows seem to be updating ALL meta-fields and not just those individually specified on the flow/saved search. This is a major cause for concern. I only happened to spot this as another user posted a comment on the support page:“Configure the new GraphQL-based Product flows”. I was about to switch our flows over. I am so glad I did not - we would have lost so much content and data that has taken years to build and it would have rendered our website useless.

Please do update your support document to let users know of this huge risk with the flows as they currently stand.

I need technical support to please look at this as a matter of urgency please. I cannot move to graphQL as it stands. I need to ensure only those specified metafields are updated in Shopify. Those not specified must be ignored. From what I can see on the Shopify API pages the mutation MetafieldsSet is available to determine which meta-fields are updated?

As background, we have around 50 product metafields in Shopify. They drive content and feed into meta-objects and are used by Shopify scripts in some instances. Most of the data is created by our Product and Marketing team that do not have access to NetSuite. The data is pretty static and once created hardly changes. It is therefore not practical (or necessary) to have this data in NetSuite.

However a small handful of metafields do change regularly, such as stock delivery timeframes. This is dependent upon supplier data, which we poll into NetSuite via an API and then apply script based logic to populate associated fields on the item records, which in turn are currently passed to Shopify via the Celigo product flows. As these are changing regularly these need to be automated and we need to pass the data from NetSuite.

Support have confirmed this is expected behaviour due to using productSet mutation and suggested I pay for a custom flow to be built to handle my use case, which is somewhat disappointing as a response.

Here is part of my latest response to them

Metafields are the Shopify equivalent of NetSuite custom fields, where you can send ad-hoc / custom data and then drive flows/ scripts etc from them. Therefore the ability to update and write to these is pretty fundamental. There is no other way to send custom data to Shopify – in order to customise the data you hold in Shopify you add a metafield. Therefore it is imperative one can map fields from NetSuite to Shopify but without overwriting a significant proportion of your content! If Celigo remove the ability to send custom data to Shopify the value we can get from our Shopify store, and by association Celigo is significantly deminished.

They have advised this is being reviewed internally and they will get back to me.

In summary, as you have shown, it is possible to update ONLY those metafields included in the saved search. Why therefore, are the Celigo flows written on an all or nothing basis?

Please Celigo - can this be addressed as a matter of urgency. The new flows as they stand will fundamentally break our website and we do not have sufficient time to reengineer our processes to overcome this new limitation.

Sandra

Hi @sandrahill and @nickhilbelink ,

We understand the concern, thanks for highlighting this to us.
We are working internally on a fix to ensure that pre-existing metafields in Shopify, which are not mapped in IO or present in Saved Search, are not deleted.
This fix should be available to all by the third week of March. We will update the KB and this post once the changes are rolled out to customers.

Nilesh.

1 Like

@nileshkumar ,
We have implemented a custom flow to manage this for now, but we are so glad to hear an official implementation is coming!

1 Like

You should be getting notifications now. We were in beta prior to yesterday so we had notifications disabled, but we reenabled then a couple days ago. If you still aren't getting them, let us know. You can also check your notification settings by going to your profile in the top right. Check under "email" and "notifications".

Thank you @nileshkumar (such a relief to hear) and @tylerlamparter (am receiving notifications now)

Much appreciated.

2 Likes

Our setup is similar to @sandrahill where only select metafields are mapped from NetSuite in product flows. This is very intentional. Other metafields are managed directly in Shopify by web staff. And other metafields are created/edited by apps.

I agree the documentation should be updated to flag this issue (or even an emergency email to all possibly impacted customers) because it's a critical issue to consider when switching to the new flows and a major change to the functionality. If the issue can not be fixed, our Celigo integration would become unusable and need to be disconnected before the April 1 deadline.

@nileshkumar Please consider making a fix available sooner than the third week of March. Or extend the April 1 migration deadline. A one week migration window is not enough time.

Has anyone been able to successfully map product cost using the GraphQL API? Our solution using the REST API doesn't work anymore, and I've played with different syntax for the destination field (cost and costPerItem), but haven't been able to post values correctly.

Important that we get this functional, as we rely on this data to be posted to Shopify for merchandising and other decisions related to margin.

1 Like

The product flows use the productSet mutation. Look at the documentation on this page. The field should exist inside the inventoryItem object.

product object
->variants object
-->inventoryItem object
-->cost field

Yep, thanks Nick. Pulled that documentation right after I posted that comment. Here's what I'm working with currently. Haven't been able to get it to post yet, but still working on it.

Just making sure, there is a product object and variants object surrounding the Inventory Item correct? I've uploaded the majority of the mapping that I used so you can see the full hierarchy.

If your hierarchy looks like mine then enable debugging on the import to Shopify step and see if it gives any feedback. It should give you some sort of error in there if it is rejecting your value based on format. I hardcoded 10 as a price and sent a matrix item with 3 child products over using the setup in the image and it went into the Cost per item column cleanly.

Thank you for taking the time to detail your mapping. Switching the output from number to string fixed the issue and it posted correctly. Thanks again @nickhilbelink !

1 Like

@stevebasler @sandrahill did either of you have any luck implementing better error handling with the weight mapping? I'm getting an error when no weight value exists on the item record in NetSuite. Obviously that is the root cause, and should be resolved, but just curious if you guys implemented anything to avoid this error:

"Variable $input of type ProductSetInput! was provided invalid value for variants.2.inventoryItem.measurement.weight.value (Expected value to not be null)"

Hi @Jason_C
The solution for no weight value existing in NetSuite is documented in the KB for the specific error.
Please navigate to collapsable section: Syncing Weight from NetSuite to Shopify using GraphQL-based product flows. Sharing screenshot for reference.

Thanks
Nilesh.

Hi @nileshkumar

The metafield issue has me questioning some other similar scenarios (tags/collections/images) so I'm hoping to get some clarification if possible. If better to open up a new thread then I am happy to do that. I could also open a support ticket but I think this information might be useful to other customers because our mappings are pretty standard.

I'm most concerned about the product edit/update scenario with the GraphQL flows because, similar to metafields being updated outside of the Celigo integration as mentioned previously, our Shopify store has other custom product data that is added after an item is created and it's critical this data remains in Shopify as-is when an item is edited/updated in NetSuite.

Tags: We use the standard mapping currently (REST) and plan to use the standard mapping with the new flows (GraphQL). That mapping is set to "Action to take if source field has no value = Do nothing". This currently works perfectly with REST flows. Our Saved Search in NetSuite has a custom formula for the tags field that passes initial tag values on item creation in Shopify but then intentionally goes blank on product edit/update to avoid overriding existing values in Shopify (tags added manually in Shopify or via Flows/Automations -- these "additional" tags are added outside of our Celigo integration). I am expecting the GraphQL-flows to behave similarly to REST but please confirm.

Images: Similar to tags above, our images use the standard mapping and are configured to "Do nothing" when no value exists in the corresponding NetSuite saved search field. This works as expected currently (REST). Image values flow to Shopify if populated in NetSuite. Otherwise the existing Shopify images remain as-is on product update. 95% of our product images are uploaded directly to Shopify so just want to confirm this behavior will be the same with GraphQL-based flows.

Collections: We don't map collections in our integration/flows. Most are smart/automated collections based on product tags. Others are controlled manually. Just want to confirm that editing/updating an item in NetSuite will not impact existing Shopify collections.

Thank you for your help and please let me know if need any other information.

P.S. Not sure if helpful for the metafield issue/fix, but our custom (non-mapped) product metafields have known namespace and keys. So I'm wondering if simply mapping them in our GraphQL flows, then confirming they are set to "Do nothing" when the NetSuite saved search field is empty might help prevent their deletion on product update?

HI @David_C - a quick observation on your final point re "do nothing" for meta-fields - I tested this, and on product update I found meta-fields being overwritten to "undefined". Test carefully!

@nileshkumar - support are still telling me I need to develop a custom flow to handle the use case when not all metafields are to be mapped. Please would you confirm this NOT the case. And also that the flows will be update to handle passing only given metafields for at the PRODUCT and VARIANT level.

Thank you

Glad to hear this, we just had to turn off our GraphQL flows that we'd gotten fully working, when we found out we were losing valuable metafields. Are we really looking at just having one week window to make sure this works before REST is fully deprecated?

I opened a support ticket and confirmed all my questions re: tags/images/collections/metafields.

Shopify tags and images mappings will function the same as they do now with advanced settings (e.g. Do nothing if source field has no value). Shopify collections are not mapped so will not be impacted by GraphQL flows.

And the non-mapped metafields clearing issue should be patched soon to align with REST-based flows behavior.