I'm trying to follow this example, but i'm stucked on Get Scooter Locations
https://github.com/ubahnverleih/WoBike/blob/master/Beam.md
I get the access code, but when I try to get scooter location, it fails
Here's the code I wrote
curl --request GET \
--url 'https://gateway.ridebeam.com/api/vehicles/getForH3/rider/detail' \
--header 'User-Agent: escooterapp/latest-app-version; ios' \
--header 'Authorization: <access code>' | jq''
The result of this code is,
{
"message": "Unauthorized",
"messageKey": "",
"messageArgs": {}
}
I thought it will get authorization as I paste access code, but it doesn't.
If I type like this,
curl --request GET \
--url 'https://gateway.ridebeam.com/api/vehicles/getForH3/rider/detail/{"latitude":"latitude", "longitude":"longitude"}' \
--header 'User-Agent: escooterapp/latest-app-version; ios' \
--header 'Authorization: <access code>' | jq''
the result is,
[1/2]: https://gateway.ridebeam.com/api/vehicles/getForH3/rider/detail/"latitude":"0" --> <stdout>
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 59 100 59 0 0 210 0 --:--:-- --:--:-- --:--:-- 210
parse error: Invalid numeric literal at line 1, column 16
[2/2]: https://gateway.ridebeam.com/api/vehicles/getForH3/rider/detail/ "longitude":"0" --> <stdout>
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 273 100 273 0 0 2814 0 --:--:-- --:--:-- --:--:-- 2814
(23) Failed writing body
it makes (23) error. I can't figure out what is wrong with code. Or did api block this curl?
First, drop --request GET from the command line since curl uses GET by default anyway.
Then: the use of {} in the URL causes curl to do globbing on it, and you don't want that for this. Switch it off using curl's -g/--globoff
But more importantly: the docs for the API seems to say that 'lattitude' and 'longitude' should be URL parameters, not passed as JSON in the URL. So asking for latitude 22 and longitude 23 might look like this:
curl \
--url "https://gateway.ridebeam.com/api/vehicles/getForH3/rider/detail/?latitude=22&longitude=23" \
--header 'User-Agent: escooterapp/latest-app-version; ios' \
--header 'Authorization: <access code>' | jq''
The fact that the server reports "unauthorized" is probably because you don't provide the correct authorization/headers but as you pass on such a header I suspect you just do it wrongly (like maybe using a wrong "access code") and that the server detects that.
Related
I have request in Insomnia. When I send it via Insomnia, no problemo. But when I generate source code for curl, it shows me this.
curl --request POST \
--url URL \
--header 'Authorization: bearer XXX' \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--cookie JSESSIONID=XXX \
--form datasetFile=#FOLDER/producthierarchyl1-1.zip
{"message":"Bad Request","logref":null,"path":null,"_embedded":{"errors":[{"message":"Required argument [Publisher datasetFile] not specified","logref":null,"path":"/datasetFile","_embedded":{},"_links":{}}]},"_links":{"self":{"href":"/data-api/public-api/v4/datasets/ingestion/","templated":false,"profile":null,"deprecation":null,"title":null,"hreflang":null,"type":null,"name":null}}}
Insomnia output is like this.
> POST PATH HTTP/2
> Host: URL
> user-agent: insomnia/2022.3.0
> cookie: JSESSIONID=XXX
> authorization: bearer XXX
> content-type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> accept: */*
> content-length: 407
* STATE: DO => DID handle 0x170404b14008; line 2077 (connection #27)
* multi changed, check CONNECT_PEND queue!
* STATE: DID => PERFORMING handle 0x170404b14008; line 2196 (connection #27)
| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="datasetFile"; filename="producthierarchyl1-1.zip"
| Content-Type: application/zip
| PK�QU�}�%+producthierarchyl1-1.csvUT բ�b
| --X-INSOMNIA-BOUNDARY--
* We are completely uploaded and fine
* HTTP/2 found, allow multiplexing
Where is the catch?
Thanks.
Remove the --header 'content-type: multipart/form-data; boundary=---011000010111000001101001 option.
It really should not be used like this: curl manages that header and the boundary on its own so changing it should only be done in the rare event you truly want and need to fiddle around with it.
A more minor second thing: --request POST should be dropped from the command line, as it is superfluous and easily cause problems if you add --location later on.
Updated
This flaw is said to have been fixed in a later version of Insomnia
For any folks bumping into this issue again, this answer correctly explains the reason for the problem.
Fortunately this should only be reproducible in versions 2022.3.0 and older versions of Insomnia.
If you use the latest one, 2022.5.1, the generated curl will no longer have this problem, example of a multipart request generated:
curl --request GET \
--url http://mockbin.org/request/anything \
--header 'Content-Type: multipart/form-data' \
--form test=test \
--form test=#/Users/yourUserName/Desktop/somefile.txt
I already successfully scheduled a lot of jobs using the REST API of the Azure IoT-Hub as described in https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-jobs. Namely I scheduled jobs to execute direct methods.
But, when I try to query the status of the scheduled jobs (as described on the same page), I always get only one entry: the status of the first successfully scheduled job. How do I get the status of all jobs?
My query was:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' -o response.json
The SAS Token I used above was the same as for scheduling the job. Thus, there is no authentication issue.
The formatted response just contains 1 entry despite that I already scheduled 11 jobs:
[
{
"jobId": "job02",
"queryCondition": "deviceId = simple_thermostat",
"createdTime": "2022-03-02T15:59:27.4093129Z",
"startTime": "2022-03-02T15:20:15Z",
"endTime": "2022-03-02T15:59:34.5969497Z",
"maxExecutionTimeInSeconds": 10000,
"type": "scheduleDeviceMethod",
"cloudToDeviceMethod": {
"methodName": "getMaxMinReport",
"payload": "hello",
"responseTimeoutInSeconds": 300,
"connectTimeoutInSeconds": 0
},
"status": "completed",
"deviceJobStatistics": {
"deviceCount": 0,
"failedCount": 0,
"succeededCount": 0,
"runningCount": 0,
"pendingCount": 0
}
}
]
PS: Getting the status of a single job works as expected. Like using this request:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/job11?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' -o response.json
But, job11 is never returned in the query above.
As pointed out by Roman Kiss, the continuation token can be found in the header of the first response. To save the header via curl one must specify the option -D. So, the first query must look like:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' \
-D response_hdr.txt -o response.json
Then response_hdr.txt will contain a line like this:
x-ms-continuation: eyJzb3VyY2UiOiJkZGIiLCJ0b3RhbFJldHJpZXZlZENvdW50Ijo4LCJjb250aW51YXRpb25Ub2tlbiI6Ilt7XCJ0b2tlblwiOm51bGwsXCJyYW5nZVwiOntcIm1pblwiOlwiMDVDMUU3RkZGRkZGRkFcIixcIm1heFwiOlwiRkZcIn19XSJ9
But, this continuation token must not be specified in the URL as stated in the Microsoft docs. Instead it must be provided in the header of the subsequent query:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'x-ms-continuation: <continuation_token_from_previous_query>' \
-D response_hdr.txt -o response.json
This query will deliver a new continuation token. It looks pretty similar, but it is not identical.
Is there a GitHub API I can use to retrieve the number of days X in
GitHub Actions
Included minutes quota resets in X days
which you can find on the https://github.com/settings/billing page?
Performing the following API call
# GITHUB_TOKEN with "Update ALL user data" permission
curl \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/users/$GITHUB_USER/settings/billing/actions
I get all info except for the billing period expiration date:
{
"total_minutes_used": 228,
"total_paid_minutes_used": 0,
"included_minutes": 2000,
"minutes_used_breakdown": {
"UBUNTU": 228
}
}
Many thanks.
I've figured out the "number of days left in the billing cycle" can be retrieved from the /users/<user>/settings/billing/shared-storage endpoint.
E.g.
curl \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/users/$GITHUB_USER/settings/billing/shared-storage
returns
{
"days_left_in_billing_cycle": 5,
"estimated_paid_storage_for_month": 0,
"estimated_storage_for_month": 0
}
I try to get twitch api with following website https://api.twitch.tv/kraken/streams/ chennal name ,but nothing happened and get error
{"error":"Bad Request","status":400,"message":"No client id specified"}
I expect to get viewers count and follower count
it's necessary to include your client ID with the request. For example:
curl -H 'Accept: application/vnd.twitchtv.v5+json' \
-H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
-X GET 'https://api.twitch.tv/kraken/streams/44322889'
See here for details on setting up your client ID.
I'm making a restful api call, but I'm getting an error.
Warning: Invalid character is found in given range. A specified range MUST
Warning: have only digits in 'start'-'stop'. The server's response to this
Warning: request is uncertain.
HTTP/1.1 200 OK
Date: Thu, 22 Aug 2013 17:43:19 GMT
Server: Apache
Content-Length: 208
Allow: GET, HEAD, POST
Vary: Authorization
Content-Type: application/json
Has anyone seen this WARNING error before about an invalid character? How do I fix it?
I was calling:
curl https://my/url/for/api --include -H "Content-Type:application/json" -request POST '{ \"type\": \"code\", \"objects\" : [ \"123456\" ] } ' -u user:pass
More info:
extra response at the end of return
curl: (6) Could not resolve host: POST; nodename nor servname provided, or not known
curl: (3) [globbing] nested braces not supported at pos 33
I had a similar situation - my curl request was essentially working, and returning the information I needed, but with warnings, using the following code:
curl -request http://...
It turned out to be the -request parameter, which I'd incorrectly typed. It either needs to be something like:
curl --request GET http://...
or simply not there at all (because GET is the default):
curl http://...
A corrected command line probably looks something like:
curl https://my/url/for/api \
--include \
-H "Content-Type:application/json" \
-d '{ \"type\": \"code\", \"objects\" : [ \"123456\" ] } ' \
-u user:pass
(I split it to multiple lines for readability.) The changes I did:
1 - --request needs two dashes but since you set POST, it was superfluous and I removed it
2 - use -d (or --data) to specify what to POST. --request only takes a single method string
that you can replace POST with in the HTTP request but I don't think you want that.
cURL gets confused about the square brackets in your command. It interprets them as a range of characters it should process. Either way your question would probably fit better on SuperUser than on Stackoverflow.