1

I am currently trying to use OneSignal REST API. I would like to use the GET method to invoke the View Apps operation:

View Apps description

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 \

Curl error in PowerShell

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". curl second request result

Then I have tried to use Postman, as follows:

Postman request

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).

REST API KEY

Finally I have tried a web app, to send the request as:

ApiRequest.io

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. info

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‽

2
  • 1
    Excellent 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 (\ ).
    – user1018743
    Nov 4, 2019 at 15:13
  • The "Please include a case-sensitive header of Authorization ..." error message seems to indicate that your API key is wrong.
    – dirkt
    Nov 4, 2019 at 16:31

1 Answer 1

3

This API endpoint requires your User Auth Key, not your App Auth Key. The reason is that this API endpoint is to list all of your OneSignal apps, not just a particular one.

Please refer to the documentation page here for details on how to get your User Auth Key: https://documentation.onesignal.com/docs/accounts-and-keys#section-user-auth-key

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .