Correct JSON Format for rich_text_field in Shopify GraphQL Mutation?

Correct JSON Format for rich_text_field in Shopify GraphQL Mutation?

mikialem
Tourist
5 0 1

I'm trying to update Shopify product metafields of type rich_text_field using the GraphQL Admin API in a Python script. However, I'm consistently running into issues with the value field formatting.

Here's what I've tried so far:

  1. Plain string value: "value": "Some value"
    Result: "Value is invalid JSON: unexpected token at 'Some value'."
  2. Escaped string as JSON: { "value": "\"Some value\"" }
    Result: "Value is not the correct format: failed schema For '#', \"Some value\" is not an object."
  3. JSON array for Portable Text (as suggested by ChatGPT):"value": "[{\"type\":\"paragraph\",\"children\":[{\"text\":\"A good product\"}]}]"
    Result: "Value is not the correct format: failed schema For '#', [{\"type\" => \"paragraph\", \"children\" => [{\"text\" => \"A good product\"}]}] is not an object."

     

     

 

I’ve tried various encoding styles and payload structures, but none seem to be accepted. It looks like Shopify expects a specific format for rich_text_field values, but I can’t find a working example in the documentation or community.

Has anyone successfully updated a rich_text_field metafield using GraphQL?

 

 

  • What is the correct JSON structure for the value?

  • Does the value need to be a stringified JSON object or just raw JSON

Any guidance or working examples would be greatly appreciated!


 

Thanks in advance.

 
 
 
Reply 1 (1)

agiledigital
Shopify Partner
10 0 2

I'm having the exact same problem and came to find the answer here. If I come across it I will send a further reply.