Update shopify articles using api

Hello,

I want to update an article author and date.

I am using below code in python .

URL3 = “https://abc:xyz@def.myshopify.com/admin/api/2023-01/blogs/1111/articles/22222.json”

article={‘id’:3333,‘blog_id’:44444,‘published_at’:‘2017-04-26T12:27:42+05:30’,‘title’:‘Is There Any Natural ?’}

data2={‘article’:article}

r = requests.put(data2)//Not exactly like this but data2

I am getting the error.

{‘errors’: {‘article’: ‘Required parameter missing or invalid’}}

Hi @shm :waving_hand:

You’ll need to ensure that data2 dict is passed as the json keyword argument. If the keyword isn’t specified, it will read it as the data (positional) parameter, which expects a encoded dictionary (i.e. data=json.dumps(payload)) and the article payload values may not be read fully. Below is one sample implementation using requests:

headers = {"X-Shopify-Access-Token": ADMIN_ACCESS_TOKEN}
rest_url = lambda r: f"https://{SHOP_NAME}.myshopify.com/admin/api/{VERSION}/{r}.json"
blog, article = 77350109302, 588192252022
endpoint = rest_url(f"blogs/{blog}/articles/{article}")
payload = {
    "article": {
        "id": article,
        "title": "new title",
        "body_html": "

foobar

",
        "published_at": "Jan 1 15:45:47 UTC 2023"
    }
}
requests.put(endpoint, json=payload, headers=headers)

Hope that helps!

You helped me a lot!! Have been trying to fix this issue for almost an hour now, Thank you :slightly_smiling_face: