Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

REST Admin API Article put returns 200 but fails

Solved

REST Admin API Article put returns 200 but fails

friendscottn
Shopify Partner
28 3 18

The following PUT request to the Admin REST API results in a 200 but does not actually update the article data

URL:

 

https://{{shopify_store_name}}.myshopify.com/admin/api/2023-10/blogs/{{shopify_blog_id}}/articles/{{article_id}}.json

 

Body:

 

{
    "article":{
        "id": {{article_id}},
        "title": "Updated title",
        "body_html": "Updated content",
        "metafields":[
            {
                "key":"author_name",
                "value":"Updated Author Name",
                "type":"single_line_text_field",
                "namespace":"global"
            }
        ]
    }
}

 

 

Accepted Solution (1)

friendscottn
Shopify Partner
28 3 18

This is an accepted solution.

Hey @Shopify ,

It turns out that if you need to update an existing metafield value, at least on a blog article, then you need to include the id of the metafield (not just the key). Otherwise the entire request fails silently, returns a 200 and the response indicates the request worked even though it did not. It seems like this case should instead return a bad request and a validation message.

 

It would also be helpful to add an example of updating a metafield value here: 

https://shopify.dev/docs/api/admin-rest/2023-10/resources/article#Addametafieldtoanexistingarticle

 

This Body works:

 

{
    "article":{
        "id": {{article_id}},
        "title": "Updated title",
        "body_html": "Updated content",
        "metafields":[
            {
                "key":"author_name",
                "value":"Updated Author Name",
                "id": {{metafield_id}},
                "type":"single_line_text_field",
                "namespace":"global"
            }
        ]
    }
}

 

Thanks

View solution in original post

Reply 1 (1)

friendscottn
Shopify Partner
28 3 18

This is an accepted solution.

Hey @Shopify ,

It turns out that if you need to update an existing metafield value, at least on a blog article, then you need to include the id of the metafield (not just the key). Otherwise the entire request fails silently, returns a 200 and the response indicates the request worked even though it did not. It seems like this case should instead return a bad request and a validation message.

 

It would also be helpful to add an example of updating a metafield value here: 

https://shopify.dev/docs/api/admin-rest/2023-10/resources/article#Addametafieldtoanexistingarticle

 

This Body works:

 

{
    "article":{
        "id": {{article_id}},
        "title": "Updated title",
        "body_html": "Updated content",
        "metafields":[
            {
                "key":"author_name",
                "value":"Updated Author Name",
                "id": {{metafield_id}},
                "type":"single_line_text_field",
                "namespace":"global"
            }
        ]
    }
}

 

Thanks