I am doing an assignment where I need to interact with a Tastypie API. I have no control over the API, I have just been given the details of it and told it is set up to allow GET’s, POST’s and DELETE’s only.
Example POST – works
curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"email":"test@someemail.com","tr_referral":"SomeFeed","mailing_lists":1,"ip_address":"192.168.1.23"}' http://api.somesite.info/v1/account/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94
Example GET – works
curl http://api.somesite.info/v1/account/202126/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94
GET Response:
{"birth_date": null, "city": "", "country": "nl", "email": "test@someemail.com", "first_name": "", "gender": "", "last_name": "", "lead": true, "mailing_lists": [{"name": "Classic NL", "resource_uri": "/v1/mailing_list/1/"}], "phone": "", "resource_uri": "/v1/account/202126/", "street_number": "", "tr_input_method": "", "tr_ip_address": "192.168.1.23", "tr_language": "", "tr_referral": {"name": "SomeFeed", "resource_uri": ""}, "utm_campaign": "", "utm_medium": "", "utm_source": "SomeFeed", "zipcode": ""}
Now here is one of many POST’s I have tried in order to trigger an update of the record:
curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"email":"test@someemail.com","tr_referral":"SomeFeed","mailing_lists":2,"ip_address":"192.168.1.46"}' http://api.somesite.info/v1/account/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94
It results in:
HTTP/1.1 409 CONFLICT
Server: nginx/1.2.1
Date: Wed, 14 Nov 2012 20:42:35 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Email address test@someemail.com already exists.
I also tried POSTing to the following URL:
http://api.somesite.info/v1/account/202126/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94
That returned:
HTTP/1.1 501 NOT IMPLEMENTED
Server: nginx/1.2.1
Date: Wed, 14 Nov 2012 20:45:01 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
I need to update the record using a POST. What am I doing wrong?
Please note, I have changed some of the data e.g. URL’s, api key, etc
I thought I should come supply an “answer” to this.
It turns out that what was written in the assignment document was misleading and I was not to update the accounts via a POST as this functionality was not allowed.
What they actually wanted was for me to DELETE the account and then re-POST it which doesn’t seem like the best way to go about it as it requires two API calls for every “update” rather than just one. Couldn’t even use the PATCH command.