1
I am currently trying to use OneSignal REST API. I would like to use the GET method to invoke the View Apps operation:
I have tried to use PowerShell with the following command, using my own APP_ID:
curl --include \
--header "Authorization: Basic YWUwZDhjNjAtZDQ4ZS00NWI5LWJjMzctYz" \
https://onesignal.com/api/v1/apps
And it outputs:
No position parameter is found that accepts the argument \
Then I have tried to execute:
curl -X GET -H 'Content-Type: application/json' -H 'Authorization: Basic YWUwZDhjNjAtZDQ4ZS00NWI5LWJjMzctYz' -v -i 'https://onesignal.com/api/v1/apps'
And it outputs:
The Headers parameter cannot be linked. Cannot convert the value 'Content-Type:application/json' from type "System.String" to type "System.Collections.IDictionary".
Then I have tried to use Postman, as follows:
Where our request translated to code is:
GET /api/v1/apps HTTP/1.1
Host: onesignal.com
Content-Type: application/json
Authorization: Basic YWUwZDhjNjAtZDQ4ZS00NWI5LWJjMzctYz
User-Agent: PostmanRuntime/7.19.0
Accept: */*
Cache-Control: no-cache
Postman-Token: 32a57eb1-1660-4f7b-b141-7fccf83d0851,537878c7-5135-48a8-a04a-1125824785b9
Host: onesignal.com
Accept-Encoding: gzip, deflate
Cookie: __cfduid=ded10b101ef5b9cd648b95b6d2e88f1261572874737
Connection: keep-alive
cache-control: no-cache
However it answers us: 400 Bad Request:
{
"errors": [
"Please include a case-sensitive header of Authorization: Basic <YOUR-USER-AUTH-KEY-HERE> with a valid User Auth key."
],
"reference": [
"https://documentation.onesignal.com/docs/accounts-and-keys#section-user-auth-key"
]
}
I have read the API documentation given in the response, and I am sure I am using the REST API KEY, as it is requested in the documentation (below an image showing how would look like a REST API KEY).
Finally I have tried a web app, to send the request as:
Where the CURL command generated is:
curl -X GET -H 'Content-Type: application/json' -H 'Authorization: Basic YWUwZDhjNjAtZDQ4ZS00NWI5LWJjMzctYz' -v -i 'https://onesignal.com/api/v1/apps'
However the response stills being:
Error
Error: Bad Request
Response: 400
headers:
{
"cache-control": "no-cache",
"content-type": "application/json; charset=utf-8"
}
body:
{
"errors": [
"Please include a case-sensitive header of Authorization: Basic <YOUR-USER-AUTH-KEY-HERE> with a valid User Auth key."
],
"reference": [
"https://documentation.onesignal.com/docs/accounts-and-keys#section-user-auth-key"
]
I have searched information, and I have read a github thread where it is advised to confirm that you are using the correct REST API KEY.
In addition I have previously read:
PowerShell equivalent of curl cURL example for accessing authenticated Kraken API
How could we send the GET request using PowerShell, or any other command line tool‽
How could we create a well formatted request as shown in OneSignal documentation‽
1Excellent question description. Lots of screen-shots for all of us to enjoy. It takes quite a while to read and to understand. Just for the beginning, the backslash character (
\
) is not a parameter or an argument. Are you sure that the Shell is really the Microsoft Windows Powershell? Its continuation character is the back-tick character (\``) and not the backslash character (
\ `). – None – 2019-11-04T15:13:23.020The "Please include a case-sensitive header of Authorization ..." error message seems to indicate that your API key is wrong. – dirkt – 2019-11-04T16:31:56.690