#Is there a reference somewhere for how to update a record over the API in Python?
30 messages · Page 1 of 1 (latest)
You basically do a PATCH request to your directus instance.
https://docs.directus.io/reference/items.html#update-an-item
REST and GraphQL API documentation to access and manage Items in Directus.
Thanks. This doesn't seem to work. Log shows 200 PATCH and the endpoint, but nothing in the record changes. I'm backing up my VPS and upgrading to the latest version just in case.
Updated to latest Directus, no change.
Do you have any flows setup that would revert this?
I don't have any flows set up at all.
What is the response body from the api?
{'data': {'catalognumber': '3-3-F', 'date_created': '2021-11-24T10:55:11.000Z', 'date_updated': '2022-12-14T19:54:52.000Z', 'donated': False, 'donor_id': None, 'filmdamaged': False, 'filmincomplete': False, 'firstdraftdone': False, 'firstdraftneeded': False, 'firstdrafturlpatreon': None, 'firstdrafturlvideo': None, 'iadescription': None, 'iaframescansuploaded': False, 'iakeywordsdone': False, 'iareadmeuploaded': False, 'iasoundtrackuploaded': False, 'iauploadverified': False, 'iaurl': None, 'id': 1000, 'notes': None, 'originalyoutubetitle': None, 'orphanfilm': True, 'orphansound': False, 'patreonpostbody': None, 'presound': False, 'problem': False, 'publisher_id': 2, 'releasevideouploaded': False, 'restoredone': False, 'restoreurlpatreon': None, 'restoreurlyoutube': None, 'scanned': True, 'series_id': 1000, 'slug': 'tips-on-writing-the-short-story-by-howard-f-decker', 'sort': None, 'sounddamaged': False, 'soundincomplete': False, 'soundtrack_media_type_id': None, 'title': 'Tips on Writing the Short Story by Howard F. Decker', 'uploadedtoia': False, 'user_created': '8f72bdd1-5be0-4f3d-90fa-9e186bc3df37', 'user_updated': '8f72bdd1-5be0-4f3d-90fa-9e186bc3df37', 'year': 1966, 'youtubedescription': None, 'youtubeuploaddate': None}}
That's odd. Seems like everything is working. Maybe try turning that dict into a string and passing that to the body.
I'm ashamed to say I probably don't know how to do that.
Changing the values variable assignment to values = {'data':{'problem': True}} doesn't change anything either.
Oh, try requests.patch(api_url, data=values)
Unfortunately doesn't change anything. Directus still returning 200, no change to data.
And requests.patch(api_url, data="{'problem': true}")?
Nope.
I wish I could see how Directus is interpreting what I'm sending it.
You could set LOG_LEVEL=debug in the .env file of directus to get more details
I'll try that.
Maybe a clue? I changed the loglevel in .env and it doesn't produce more info in the log.
Did you restart directus?
Yes. I have it running straight off the command line so I can watch the log. I control-C'ed it and re-ran npx directus start
You could also use a rest client to see if you can manually update directus outside of python.
Let me give that a try
Then you at least know if it is a problem in Directus or something not working as expected with python 😄
Okay, so it works in a REST client.
So my guess was correct that python is doing something weird. ^^
Yeah. The question is what. Thanks for the suggestion though.
Try using a incoming request inspector like https://webhook.site/ and compare the not working python request and the working rest client request and see if there are any differences