Streaming live at 10am (PST)

Problem with Webflow API Call / Python

Dear Sir/Madam,

I use your API by Python 3.7. I try to update some items in collection and try to use put and patch requests as describe in your API describer. Unfortunately, I get error 400 every time. I try to use several option like encode, binarize, etc. There is no result, only error 400. I present part of my code, please let me know what’s my mistake:

Request:

import requests

headers = {

‘Authorization’: ‘Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’,

‘accept-version’: ‘1.0.0’,

‘Content-Type’: ‘application/json’,

}

data = ‘${\n “fields”: {\n “name”: “testname”,\n }\n }’

response = requests.patch(‘https://api.webflow.com/collections/5ce2ceab0b5f0b71f828c4ba/items/5ce2d1710b5f0bcfae28cd8c’, headers=headers, data=data)

response.status_code, response.text

Answer:

(400,

‘{“msg”:“Invalid request body”,“code”:400,“name”:“ValidationError”,“path”:"/collections/5ce2ceab0b5f0b71f828c4ba/items/5ce2d1710b5f0bcfae28cd8c",“err”:“ValidationError: Invalid request body”}’)

Hi @monolith23, welcome to the forums.

I would suggest you try using escaped quotes on the field name and value.

Here is a successful payload I just pushed via a patch to an item;

payload = "{\r\n      \"fields\": {\r\n    \t\"name\": \"Updated postname via patch\"\r\n    \r\n      }\r\n}\r\n    \r\n"

It can also be helpful to workout formatting issues with a tool like Postman.