Code "not_found" with message "No trip with id ..." - uber-api

I get requset_id = XXX with "GET /history" request.
When sending "GET /requests/XXX" request I returns a valid response with all information about requset, but if it's 'PUT /sandbox/requests/XXX' UBER server return {'code':'not_found', 'message':'No trip with id XXX'}

You are looking at a real request with your GET command. However, the Sandbox for PUT /sandbox/requests/{request_id} just allows you to modify sandbox requests only. You have to create a new request with the same body but send it to a different base URL: https://sandbox-api.uber.com, like so:
curl -X POST -H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json" -d \
'{"product_id": "", "start_latitude":"", "start_longitude": "", "end_latitude":"", "end_longitude": "", "seat_count": "", "fare_id":""}' \
https://sandbox-api.uber.com/v1.2/requests

Related

KSQLDB Rest API: return query results as json

I'm issuing the following request:
curl --http2 -X "POST" "http://localhost:8088/query-stream"
-H "Content-Type: application/vnd.ksql.v1+json; charset=utf-8"
-d $'{
"sql": "SELECT * FROM USERS EMIT CHANGES;",
"streamsProperties": {
"ksql.streams.auto.offset.reset": "earliest"
}
}
The result I'm getting is:
{"queryId":"cdfb3ccc-0ab5-4186-a249-b279bfc09587","columnNames":["USERID","NAME"],"columnTypes":["STRING","STRING"]}
["1","Max"]
["2","Alex"]
["13","Andrew"]
...
Is there a way I could get the data in json format?
{"userid":"1","name":"Max"}
{"userid":"2","name":"Alex"}
{"userid":"13","name":"Andrew"}
It is easier to deserialize this data into POCO objects if they are in json than to parse the 'row' format.
Per the docs you can set the Accept header. It defaults to application/vnd.ksqlapi.delimited.v1 but can also be set to application/json:
curl --show-error --silent \
-H "application/vnd.ksqlapi.delimited.v1" \
--http2 'http://localhost:8088/query-stream' \
--data-raw '{"sql":"SELECT * FROM CUSTOMERS WHERE ID=42;"}'
{"queryId":null,"columnNames":["ID","FIRST_NAME","LAST_NAME","EMAIL","GENDER","COMMENTS"],"columnTypes":["INTEGER","STRING","STRING","STRING","STRING","STRING"]}
[42,"Rick","Astley","r.astley#example.com","Male",""]
curl --show-error --silent \
-H "Accept:application/json" \
--http2 'http://localhost:8088/query-stream' \
--data-raw '{"sql":"SELECT * FROM CUSTOMERS WHERE ID=42;"}'
[{"queryId":null,"columnNames":["ID","FIRST_NAME","LAST_NAME","EMAIL","GENDER","COMMENTS"],"columnTypes":["INTEGER","STRING","STRING","STRING","STRING","STRING"]},[42,"Rick","Astley","r.astley#example.com","Male",""]]

"no data provided" error in json PUT request

I am trying to PUT json data through curl request.
Currently I am getting "no data provided" error.
curl --header "Content-Type: application/json" --request PUT -d #a.json https://localhost:8200/api/login
{"errors":["no data provided"]}
cat a.json
{
"key1":"value1",
"key2":"value2"
}
While when I am Posting it with double quotes and not through file its working.
curl -H "Content-Type: application/json" --request PUT -d "{\"data\":{\"key1\":\"value1\",\"key2\":\"value2\"}} " https://localhost:8200/api/login
We need to pass data section in Json.
cat a.json
{
"data": {
"key1":"value1",
"key2":"value2"
}
}

Request using Curl (Windows 10) in Matlab gives error message

I am sending a curl command to a server, but get an error message which I do not understand.
The request I need to send to the server is
body=$(cat << EOF
{
"order": {
"units": "100",
"instrument": "EUR_USD",
"timeInForce": "FOK",
"type": "MARKET",
"positionFill": "DEFAULT"
}
}
EOF
)
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer TOKEN>" \
-d "$body" \
"https://api-fxtrade.oanda.com/v3/accounts/<ACCOUNT>/orders"
What I do is that I translate this into a curl command like :
curlcmd = 'curl -s \ -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d "{"order": {"units": "100", "instrument": "EUR_USD", "timeInForce": "FOK", "type": "MARKET", "positionFill": "DEFAULT" }}" \ "https://api-fxpractice.oanda.com/v3/accounts/AccountID/orders"'
I send the command via resp = system (curlcmd) via Matlab to the server. What I get as an error message is :
errorMessage: 'Invalid JSON, ParseErrorCode: 4, Message: Missing a name for object member.'
Any idea what this means and how I can solve this ? I am using Matlab on Windows 10, so curl is part of Windows 10.
Response should be a placed order and response data of the trade.
The JSON doesn't seem to be properly quoted.
Try this:
curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer " -d "{\"order\": {\"units\": \"100\", \"instrument\": \"EUR_USD\", \"timeInForce\": \"FOK\", \"type\": \"MARKET\", \"positionFill\": \"DEFAULT\" }}" "https://api-fxpractice.oanda.com/v3/accounts/AccountID/orders"
Test with Proxy
With the appropriate escape of the JSON quotes, as shown in the above CURL command line, the JSON looks correct when viewed in an HTTPS proxy:

How to set a related object using HATEOAS?

I fail to consume a restful API with HATEOAS links generated from springboot repositories.
Consider the following model:
public class Order {
private UUID id;
private String orderNumber;
private Location location;
}
public class Location {
private String street;
private String town;
}
Just for the sake of readability I left out any boilerplate code such as getters, setters and constructors.
After starting the service, I created an empty Order, that I can query like:
>curl http://localhost:8080/orders/1
Which returns:
{
"orderNumber": "ON 0815",
"_links": {
"self": {
"href": "http://localhost:8080/orders/1"
},
"location": {
"href": "http://localhost:8080/orders/1/location"
}
}
}
Now if i call curl http://localhost:8080/orders/1/location, it returns HTTP 404 - Not found, which is reasonable, because I didn't set that yet.
Next I create the Location to set via HTTP POST:
curl -XPOST http://localhost/8080/locations \
-H 'Content-Type: application/json' \
-d '{"street": "Bakerstreet 221B", "town": "London"}'
The service answers with:
{
"street": "Bakerstreet 221B",
"town": "London",
"_links": {
"self": {
"href": "http://localhost:8080/locations/1"
}
}
}
Now we get to the point, I am stuck at. How do I link the Location to the Order? None of my attempts worked out. I'd be grateful for any advice.
So far I tried:
1. PUT the object
>curl -XPUT http://localhost:8080/orders/1 \
-H 'Content-Type: application/json' \
-d '{"orderNumber": "ON 0815", "_links": {"self": {"href": "http://localhost:8080/orders/1"}, "location": {"href": "http://localhost:8080/orders/1/location"}}}'
2. PATCH the object
>curl -XPATCH http://localhost:8080/orders/1 \
-H 'Content-Type: application/json' \
-d '{"_links": {"self": {"href": "http://localhost:8080/orders/1"}, "location": {"href": "http://localhost:8080/orders/1/location"}}}'
3. POST to the link
>curl -XPOST http://localhost:8080/orders/1/location \
-H 'Content-Type: application/json' \
-d '{"street": "Bakerstreet 221B", "town": "London"}'
Management Summary
>curl -XPUT http://localhost:8080/orders/1/location \
-H "Content-Type: text/uri-list" \
-d "http://localhost:8080/location/1"
Detailed Description
If I call the nested location uri with a -I flag and a forbidden method, the allowed methods are listed.
>curl -I -XPOST http://localhost:8080/orders/1/location \
-H 'Content-Type: application/json'
HTTP/1.1 405
Allow: GET,PUT,PATCH,DELETE
Content-Length: 0
Date: Mon, 29 Oct 2018 08:59:19 GMT
This means a PUT on this url must be valid. Putting on this url with an empty body yields:
>curl -XPUT http://localhost:8080/orders/1/location \
-H 'Content-Type: application/json' \
-d '{}'
{"cause":null,"message":"Must send only 1 link to update a property reference that isn't a List or a Map."}
After searching for this message, I found, that my Content-Type was wrong. I need to use Content-Type: text/uri-list and add the url of the location to set as body.
>curl -XPUT http://localhost:8080/orders/1/location \
-H "Content-Type: text/uri-list" \
-d "http://localhost:8080/location/1"

Watson internet of things platform: not able to assign standard gateway role to a device

I am trying to assign standard gateway role to a gateway device as per docs available
https://docs.internetofthings.ibmcloud.com/apis/swagger/v0002-beta/security-gateway-beta.html#!/Limited_Gateway/put_authorization_devices_deviceId_roles
But I keep on getting 403 Forbidden error. I am using app credentials (api key and token) which has "Operations application" role and hence privileges to assign roles.
Here are few scripts which are run, where I have replaced org, type, id and token with dummy values
curl -X PUT \
https://dummyorg.internetofthings.ibmcloud.com:443/api/v0002/authorization/devices/g%3Adummyorg%3Adummytype%3Adummyid/roles \
-H 'authorization: Basic dummyauth' \
-H 'content-type: application/json' \
-d '{
"roles": [
{
"roleId": "PD_STANDARD_GW_DEVICE",
"roleStatus": 1
}
]
}'
Response
HTTP 403 forbidden
When I try to get the role of device, it works fine
curl -X GET \
https://dummyorg.internetofthings.ibmcloud.com:443/api/v0002/authorization/devices/g%3Adummyorg%3Adummytype%3Adummyid/roles \
-H 'authorization: Basic dummyauth' \
Response
{
"results": [
{
"roleId": "PD_PRIVILEGED_GW_DEVICE",
"roleStatus": 1
}
],
"rolesToGroups": {}
}
Note the url - you have to use the 'g' and you have to encode it. You need to include a Basic Authorisation header which has your API keys (mine are Standard Application):
PUT /api/v0002/authorization/devices/g%3AOrgID%3Agatewaytype%3AmyGateway/roles HTTP/1.1
Host: OrgID.internetofthings.ibmcloud.com
Authorization: Basic removed
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: removed
{
"roles": [
{
"roleId": "PD_STANDARD_GW_DEVICE",
"roleStatus": 1
}
],
"rolesToGroups": {}
}