Stuck on getting a PUT request to work

Recommended Posts

This is probably not specifically an issue with the RB API and more about something I don't understand in python requests, but I've researched the latter and tried a lot of different things, so I thought I'd ask here for help.  

I'm trying to use a python requests to generate a PUT request to update a part in a partslist (changing the quantity, all else remaining the same). Based on the curl command in the API docs, I've tried:

url = ''
headers = {'Authorization': 'key key_goes_here',
           'Content-Type': 'application/x-www-form-urlencoded',
           'Accept': 'application/json'}
data = {'quantity':17}  #I think the problem is here

r = requests.put(url,headers=headers,data=data)

This structure is working for other http requests (delete, get), but those don't have a the  data element, so I think the problem is there.   I've also tried a few variations on formulating the data element:

data = {'quantity':'17'}
data = '{"quantity":"17"}'
data = '{"quantity":17}'
#and in desperation
data = 'quantity=17'

No matter what I try, I get status code 400, bad request. What am I missing?  Thanks in advance.


Share this post

Link to post
Share on other sites

Your URL needs to end with a / for post/put/patch commands. Unfortunately, the error message you get about the missing quantity field is quite misleading!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now