
Nitin Iyer • about 8 years ago
Put Request Not working in Sandbox API
I'm trying to change the status of a Request I make using the Sandbox API and am getting the following error when I make my put request:
{"message":"Method not supported for this endpoint.","code":"method_not_allowed"}
I'm using Objective-C, Below is the code I'm using to make the PUT request, any help would be great!
NSString *url = [NSString stringWithFormat:@"https://sandbox-api.uber.com/v1/requests/%@?access_token=%@", _requestId, _perma_access_token];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"PUT"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSDictionary* requestDictionary = @{@"status" : @"accepted"};
[request setHTTPBody:[NSJSONSerialization dataWithJSONObject:requestDictionary options:NSJSONWritingPrettyPrinted error:nil]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *requestData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
Comments are closed.
6 comments
Ahmed Nizam • about 8 years ago
You can use the curl itself to put some data into sandbox API right?
I am curious to know why should you write them in objective C?
Its more of manipulating the server side info to get various scenarios like "processing", "accepted", "arriving", etc..
https://developer.uber.com/v1/sandbox/
Nitin Iyer • about 8 years ago
I'm building an iOS app and so Objective-C is the language necessary.
I went and tried making the PUT request in Python, and here I think it works, I get a 204 http status. So must be something to do with the iOS request? Here's the code for that.
import requests
import json
params = {'status': 'accepted'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer cNirl0W7g5zmAROEroBFLMbqeBpy6L'}
res = requests.put('https://sandbox-api.uber.com/v1/sandbox/requests/00c4ebca-73ea-4617-904a-87420b38aaf4', data=json.dumps(params), headers=headers)
print res
Ahmed Nizam • about 8 years ago
"Currently the sandbox does not change states automatically the way a real Request in production would, so this endpoint gives the ability to walk an application through the different states of a Request."
This is the use of the sandbox APIs PUT request as per documentation. Effectively, you need this only on server side not on client side. Because final client will be using non sandbox API, and they don't need this cookup.
Anyway in your Objective C code, you are sending Authorization header in header only?
I see it being sent as part of url.
https://sandbox-api.uber.com/v1/requests/[request_id]?access_token=[access_token]
NSString *url = [NSString stringWithFormat:@"https://sandbox-api.uber.com/v1/requests/%@?access_token=%@", _requestId, _perma_access_token];
P.S: I don't know any iOS code but this looks like a string replacement code to me.
Uber Developer Manager • about 8 years ago
Looks like this is because your URL is incorrect. The difference between your iOS code and the Python example is a missing `/sandbox`.
You must send PUTs to manipulate the sandbox with the following URL:
https://sandbox-api.uber.com/v1/sandbox/requests/[request_id]
Where you currently have:
https://sandbox-api.uber.com/v1/requests/[request_id]
Ahmed Nizam • about 8 years ago
For me, I get a 204 http status. But the server is not receiving any callback. Why is that?
This issue is there in this thread.
http://uberhackathon.challengepost.com/forum_topics/4561-webhooks-not-working
Amit Mohite • about 8 years ago
I have used same url in IOS with PUT request with objective c language now getting empty response from server side.
https://sandbox-api.uber.com/v1/sandbox/requests/[request_id]?access_token