Score:1

JSONAPI : Patch node path alias

bd flag

I have content on a Drupal site and I want to patch to change their path alias. Here is how I do. It is giving me a 400 error: Syntax Error. I don't see where the syntax is bad. I am using Python 3 and requests

content = json.loads(data)
nodeEndpoint = endpoint.endpoint_url + f"/jsonapi/node/article/{destination_id}"

patchData = {
    "data": {
        "type": "node--article",
        "id": destination_id,
        "attributes": {
            "path": {
                "alias": content['slug'])
            }
        }
     }
}

articlePatch = requests.patch(
    nodeEndpoint,
    data=patchData,
    headers=headers
)

Thank for your help.

sonfd avatar
in flag
There looks to be an erroneous "f" on this line: `nodeEndpoint = endpoint.endpoint_url + f"/jsonapi/node/article/{destination_id}"`
El Inoubio avatar
bd flag
I found the mistake. I was not serializing the json content. Thank you. data = json.dumps(patchData)
El Inoubio avatar
bd flag
Now my problem is that this code doesn't do anything to Drupal. It is saying that the article is edited and sending the new article content including the defined path but it is not saved in the database. How to save the new path with the article ?
El Inoubio avatar
bd flag
f is not erroneous. It is a formating function in Python. It helps to insert variable content in a string.
berliner avatar
bd flag
Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - [From Review](/review/low-quality-posts/134730)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.