Programmatically contextualize json templates

Hi everyone,

I am trying to create a script to programmatically contextualize json templates. My client has got a markets structure that doesn’t match their content areas structure. For example they have a content area in America which includes 2 markets: US and CA (due to the currency difference). If they use the customizer to add content to US market, i want to copy over the json template content to CA, this saves the client the job to add the same content to CA market manually.

This is even more relevant for “Rest of the world” content area where the currencies are 5, so the client would to replicate the content 5 times ( that’s a lot of manual work).

I managed to create a node script but:

  • if I leave section or blocks “type” property in the contextualized json the CLI complains that some of the sections (in a random fashion) types cannot be contextualized.

  • If instead I remove all type properties it randomly returns an error saying the section X is missing a type field. Plus uploading via cli templates that contain sections without a type property, Shopify removes those sections.

Anybody had this problem before? the errors look random so I can’t really get my head around the logics for contextualizing a json template.

Thank you