Using Postman
How to use Postman for server REST API testing
You can use Postman to work with our REST API. Follow the screenshots below to see how to use Postman for our Create notification API endpoint.
Public OneSignal Postman Collection Is Now Available 🙌
If you want to test our OneSignal API, we have made a OneSignal Postman collection that will allow you to start testing our API now!
To learn more about the collection and the OneSignal API, visit the OneSignal Postman docs
Create notification
This example will explain how to target single or multiple OneSignal Apps.
For multiple apps, make sure to check out how to use Postman's Collections to send to all apps at once. Be careful when testing not to spam all users on all apps!
Select New Collection (name the collection) > Click Add request (name the request)
1. Select POST
add:
https://onesignal.com/api/v1/notifications
2. Create the Headers
Line 1 key: Authorization
value: Basic ONESIGNAL_REST_API_KEY
- Replace ONESIGNAL_REST_API_KEY with the value found in Keys & IDs
- If targeting multiple Apps, set:
Basic {{REST_API_KEY}}
to device the VariableREST_API_KEY
Line 2 key: Content-Type
value: application/json
You MUST use this value with postman for our API.
3. Add the Body
select raw
add your JSON
See the Create notification API docs for all parameters.
If targeting multiple Apps, set the {{appId}} and {{url}} variables along with any other variables you would like. Otherwise all apps will get the same data.
4. Save and Send
Click the "Save" button to reuse this request multiple times.
You can now press the "Send" button to send to everyone in the "Subscribed Users" segment defined in the above example or replace with the Segments you want to include.
If targeting multiple Apps, create a .csv
file with at least 3 columns: REST_API_KEY
, appId
, and url
(as shown in the above example). Any other variable data will need to be added to the .csv
file as well. You can find the App ID and Rest API Key within Keys & IDs or use the View apps API endpoint.
Example:
Once you have the CSV data of your variable values, in Postman, select the Collections Arrow and click Run
Next to "Data" click Select File, upload the .csv
file with all the variables.
Next to "Delay" add 30000
ms.
POINT OF SENDING once you click Run Create ... it will start to send the push.
View Notifications
1. Select GET
add:
https://onesignal.com/api/v1/notifications?app_id=YOUR_APP_ID&limit=:limit&offset=:offset&kind=:kind
2. Set Params
Under the VALUE Column put the following data you want to collect.
Key | Value |
---|---|
app_id | Your OneSignal App Id to get the notifications from |
limit | How many notifications you want. Default: 50 Max: 50 Minimum: 1 |
offset | Page offset ie How many notifications to skip over. If you got 50 notifications in the last call. You can offset by 50 to get the next 50 notifications. |
kind | The kind of notifications you want. Default: blank - all kinds of notifications0 - Dashboard Sent Notifications1 - REST API Sent Notifications3 - Automated Messages. |
3. Set Headers
For the KEY set Authorization
and VALUE set Basic YOUR_REST_API_KEY
where YOUR_REST API_KEY
can be found in Keys & IDs.
4. Press Send
You will get the results similar to here: https://documentation.onesignal.com/reference#section-result-format-view-notifications
View Apps
OneSignal has an API for viewing all your apps or only specific apps you want.
In this quick example, we will look at viewing all app data.
1. Setup GET Url
In the Postman interface, select the GET call and add the url: https://onesignal.com/api/v1/apps
2. Add User Auth Key
This call Requires your OneSignal User Auth Key, (not REST API Key) which is available in Keys & IDs.
In Postman under Headers use the Authorization key and for value use: Basic YOUR_USER_AUTH_KEY
Make sure to put your User Auth key.
3. Send and Save
Once you do that, you can click Send on Postman to get all your app data.
Common important data would be:
"id" | OneSignal App Id |
"players" | Total Users |
"messageable_players" | Subscribers |
Don't forget to press Save to keep this call for later.
CSV User Export
1. Download Postman (if you have not done so already).
You can download postman here: https://www.getpostman.com/
2. Create Collection
Open Postman and Select Collections > + New Collection
Name the collection "CSV User Export" and click "Create"
3. Create the Request
Select the collection and click "Add request"
Name the Request "CSV User Export" and "Save to CSV User Export"
Select the Request in the Collection
Now that this is created, you can re-use it as much as you like.
4. Setup the Request
1 - Select POST
2 - Past this url https://onesignal.com/api/v1/players/csv_export?app_id=
3 - Select Headers
4 - Add Authorization
and Content-Type
keys
5 - Next to Authorization set Basic YOUR_REST_API_KEY
replace with your actual REST API Key
6 - Next to "Content-Type" add application/json
Optional Add Extra Data - use this if you need the p256, web_auth, country, location and/or ip address.
7 - Select Body
8 - Select raw
9 - add this json
{"extra_fields": ["country","location","notification_types","ip", "external_user_id", "web_auth", "web_p256"]}
5. Send the request and open the file
Click "Send" and copy-paste the provided URL into a browser.
The URL you need to put in the browser will look like this:
https://onesignal.s3.amazonaws.com/csv_exports/3beb3078-e0f1-4629-af17-fde833b9f716/users_59891cdc338b8b5eb128438512a60b83_2020-01-22.csv.gz
When you add this URL To the browser, you might see this page:
This means the data is loading, please wait 10 to 20 minutes (depending on how big the app is) and refresh the page, eventually this will download the list.
Notification History
1 In OneSignal Dashboard, navigate to Settings > Analytics and check that "Send History via OneSignal API" is enabled. Only data for notifications sent after this is set to Active will be available.
2 Open Postman and click the + button inside the "Collections" page. You can name this collection Notification History
or whatever you like.
3 Select the 3-dot Options button and Add request
4 Setup the request Params:
4.1 Name the request Sent Data
or whatever you like.
4.2 Change the request to POST.
4.3 Past this URL into the field: https://onesignal.com/api/v1/notifications/:notification_id/history
4.4 Press Save
4.5 Under "Path Variables" you should see notification_id
already populated. This is where you put the OneSignal notification_id under "Value".
5 Setup the Headers
5.1 Under "Key" input Authorization
you should see this auto-populate with suggestions.
5.2 Under "Value" type Basic
and paste your OneSignal REST API Key found in the Settings > Keys and Ids of your OneSignal Dashboard. Make sure there is a space between Basic and your REST API key.
6 Setup the Body
6.1 Click form-data.
6.2 Add the following 3 Keys: app_id
, email
, events
6.3 Add the following Values for each key:
- Your OneSignal App Id found in Settings > Keys and Ids
- Your email or an email to send the list to
sent
event.
6.4 Press Save
7 Send the request and open the file
The last input you need is the notification_id
. You can get this within the Dashboard by viewing the Message Report for the notification and getting the UUID in the URL. For example, go to Messages or Delivery tab and click a notification, you will see the Message Report and the URL will look like this:
https://app.onesignal.com/apps/5e605fcd-de88-4b0a-a5eb-5c18b84d52f3/notifications/06c38df3-e2f2-4e71-8075-2a30a2188e0f#outcomes=os__click__count,os__session_duration__count
In this case 06c38df3-e2f2-4e71-8075-2a30a2188e0
is the notification_id.
7.1 Go to the Params tab
7.2 Paste the notification_id
UUID into the VALUE column.
7.3 Press Send
8 Getting the results.
You should see a success: true
response with a destination_url
. This should also be emailed to you.
Copy the URL only and paste it into a browser.
Depending on how large the audience, you may see an error page, just wait and try again after several minutes.
You will have a list of all player_id
records sent this notification.
You can right click the list and "Save As" a CSV. You will want to add a column header player_id
if you plan to use this list for Importing User Attributes or Tags.
Notification History Done!
If you want to duplicate the request in Postman and save the 2nd request for
clicked
events, just update the request name and setclicked
event in the Body. More details on this request in Notification History.
Updated over 2 years ago