Uber API: Endpoint requests returns Not supported in sandbox environment - uber-api

I have successfully completed the first three steps of the authentication process: step one(authorize), step two (receive redirect ) and step three (get an access token).
But, doing the following request gives me an error:
curl -H 'Authorization: Bearer xxxxoKnAKxxxxxndQNRZgRa0Dxxxxx' 'https://sandbox-api.uber.com/v1/requests'
Response:
{"message":"Not supported","code":"not_found"}
I have the same message with all required params:
curl -H 'Authorization: Bearer xxxxoKnAKxxxxxndQNRZgRa0Dxxxxx' 'https://sandbox-api.uber.com/v1/requests?product_id=5b451799-a7c3-480e-8720-891f2b51abb4&start_latitude=48.869576&start_longitude=2.30825&end_latitude=48.84839&end_longitude=2.395921'
Am I missing something?
Edit:
Ruby version with HTTParty:
def request(bearer, product_id="5b451799-a7c3-480e-8720-891f2b51abb4", start_latitude=48.869576, start_longitude=2.30825, end_latitude=48.84839, end_longitude=2.395921)
parameters = { product_id: product_id,
start_latitude: start_latitude,
start_longitude: start_longitude,
end_latitude: end_latitude,
end_longitude: end_longitude
}
self.class.post('/v1/requests', query: parameters, headers: { "Authorization" => "Bearer #{bearer}", 'Content-Type' => 'application/json' })
end

A GET to 'https://sandbox-api.uber.com/v1/requests' won't work since you need to include a such as https://sandbox-api.uber.com/v1/requests/request_id
A POST to 'https://sandbox-api.uber.com/v1/requests' requires you to post the parameters as part of the JSON body.
Once you have the request ID as part of the response, you will able poll for details using the first command.

Related

Bitbucket API - Unable to Generate Access Token from JWT

I'm using Bitbucket Connect App and getting JWT token from webhook event.
When I am using the latest JWT to get access token, the access token API returning blank in response.
API:
curl -X POST -H "Authorization: JWT {jwt_token}" \ https://bitbucket.org/site/oauth2/access_token \ -d grant_type=urn:bitbucket:oauth2:jwt
Example:
curl -X POST -H "Authorization: JWT ey*****XVCJ9.eyJpc3MiOi****asdfQ.**BBD**" \
https://bitbucket.org/site/oauth2/access_token \
-d grant_type=urn:bitbucket:oauth2:jwt
Response
{blank}
API Reference:
https://developer.atlassian.com/cloud/bitbucket/oauth-2/
Thanks
I had the same problem until I added the sub key to the payload. Set the value to the value received in clientKey during the app installation lifeycle event.
I followed this documentation to generate Access Token and it worked.
https://pawelniewiadomski.com/2016/06/06/building-bitbucket-add-on-in-rails-part-7/
Most of the Part for generating access token using Bitbucket Cloud API
def get_access_token
unless current_jwt_auth
raise 'Missing Authentication context'
end
# Expiry for the JWT token is 3 minutes from now
issued_at = Time.now.utc.to_i
expires_at = issued_at + 180
jwt = JWT.encode({
iat: issued_at,
exp: expires_at,
iss: current_jwt_auth.addon_key,
sub: current_jwt_auth.client_key
}, current_jwt_auth.shared_secret)
response = HTTParty.post("#{current_jwt_auth.base_url}/site/oauth2/access_token", {
body: {grant_type: 'urn:bitbucket:oauth2:jwt'},
headers: {
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => 'JWT ' + jwt
}
})
if response.code == 200
Response.new(200, response.parsed_response)
else
Response.new(response.code)
end
end

How to put raw data in a http get request in Flutter(Dart)?

I'm trying to execute the following curl in dart but I can't find a way to achieve that:
curl --location --request GET 'https://someurl.com/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer xxxx' \
--data-raw '{
"query":"test_value",
"size":10
}'
The only way I've found to achieve this is to use POST and put the raw data inside the body but I was wondering if there is a real way to achieve that since the POST request with a body seems to be about 220ms slower than the GET one(I know that they should be almost equal, it may be something from the server when recieving the request).
The default get() method of the http package doesn't allow you to add data since that isn't a common thing to do. You can get around this by using the Request object directly for more fine-grained control, as stated in the docs:
Request req = Request('GET', Uri.parse('https://someurl.com/query'))
..body = json.encode(data)
..headers.addAll({
"Content-type": "application/json",
"Authorization": "Bearer xxxx"
});
var response await req.send();
if (response.statusCode == 200) {
// do something with valid response
}
I'd look at getting the POST variant working properly, since a GET method semantically shouldn't do anything with the provided body. But that's a different discussion of course.
import 'package:http/http.dart' as http;
// Define the raw data to be sent in the request
String rawData = '{ "key": "value" }';
// Send the GET request with the raw data as the body
http.Response response = await http.get(
'https://example.com/endpoint',
headers: {'Content-Type': 'application/json'},
body: rawData,
);
// Check the status code of the response to see if the request was successful
if (response.statusCode == 200) {
// The request was successful, process the response
} else {
// The request was not successful, handle the error
}

Getting "HTTP method not allowed, supported methods: GET" when request is successful

I am working on a Akka-Http project in which I am writing a POST endpoint http://localhost:8080/api/v1/internal/admin/import which requires a header with an access token.
My curl request is as follows
curl --location --request POST 'http://localhost:8080/api/v1/internal/admin/import' \
--header 'Content-Type: application/json' \
--header 'Accept: text/plain' \
--header 'Authorization: correct-token' \
--data-raw '{
"id": 100,
"name": "test"
}'
When the access token is incorrect, I get the http response in the exact format that is expected
"status": {
"code": 403,
"error": "authorization_error",
"details": "Invalid token"
}
}
But as soon as I provide a correct token in the header, the http request is successful, but I get a weird message HTTP method not allowed, supported methods: GET.
Just before sending the correct response, I tried to print the json and its correct. My code looks as follows :
onComplete(futureR) {
case Success(result) =>
println(s"Success response json is ${Json.toJson(result)}")
complete(result)
case Failure(ex) => complete(
500 -> StatusResponse(ApiStatus(500, None, None))
)
}
The result I am getting on terminal is Success response json is {"status":{"code":0}} which is correct, however in Postman, I keep on getting the error HTTP method not allowed, supported methods: GET.
Any pointers to this problem ? TIA

How to add request options in Angular 2?

I am trying to implement Auto search in Angular 2. I am trying to get data from API to populate in suggestion list. My API accepts headers with token. Below is a sample url:
curl -X GET --header 'Accept: application/json' --header 'Authorization: USERNAME PASSWORD' 'https://apsapi.azurewebsites.net/api/searchusers?searchstring=anil'
I am using npm ng2-completer plugin. This is my API Call:
constructor(private completerService: CompleterService, private translationService: AppTranslationService, private alertService: AlertService, private useronboardService: UserOnboard)
{
let options = new RequestOptions({ headers: new Headers() });
options.headers.set("Authorization",'Bearer0l4B9VpOnJMBzxMee8SQdU8pFW_L8wBAyQ');
let url = "https://arsapi.azurewebsites.net/api/searchusers?searchstring="
this.dataService = completerService.remote(url, 'userName', 'userName');
this.dataService.requestOptions(options);
}
I do not see any header attached in request. Below is image.
image
Above piece of code results in error and it tells: (method)RemoteData.requestoptions(requestOptions:any):void (TS)Expected 1 arguments but got 2.
Can someone help me to add header in the above code?

loopback access_token not found

followed by the access documentation
both are not working by using
Authorization Header
Query Parameter
Using the latest version of loopback 2.1.X.
I turned off the email verification and successfully got the AccessToken object from the initial login. The header and the query request are not working now.
ACCESS_TOKEN=6Nb2ti5QEXIoDBS5FQGWIz4poRFiBCMMYJbYXSGHWuulOuy0GTEuGx2VCEVvbpBK
Authorization Header
curl -X GET -H "Authorization: $ACCESS_TOKEN" \
http://localhost:3000/api/widgets
Query Parameter
curl -X GET http://localhost:3000/api/widgets?access_token=$ACCESS_TOKEN
In header pass key as authorization not ACCESS_TOKEN
In query params pass key as accessToken not access_token
Here is what works for me in Angular 2 :
initRequestOptions(accessToken:any) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Authorization', accessToken);
return new RequestOptions({headers: headers});
}
makeRequest(accessToken:any){
let options = this.initRequestOptions(accessToken);
this.http.get('http://' + apiUrl + '/api/MyModel, options)
.subscribe(
//...
)
}
So basically you need to create a headers object , add an 'Authorization' item whoes value is the access token , and use the headers object to create a RequestOptions object to be inserted in the request.
Also loopback explorer passes the access token as a url encoded parameter so this should work too :
http://localhost:3000/api/MyModel?access_token=X3Ovz4G1PfmPiNGgU5YgORPwPGLaVt9r8kU7f4tu1bDMyA4zbqiUEgeDAC3qkZLR