How to find and delete a Scheduled Push Notification using the API

Sometimes you may need to cancel or delete a scheduled Push Notification before it sends. If this message had been edited using the API, or if your organization schedules a large number of notifications, it may be difficult or not possible to find and delete this message via the Urban Airship Dashboard. This document will walk through the steps of deleting this scheduled notification via the API.

This method only works for notifications that have not begun to send. We are unable to cancel notifications already in progress under most circumstances. It also assumes you are either the original creator of the notification or the project owner as per Urban Airship’s Team Access roles. If you are not, please contact the appropriate person for your organization


Locate the Schedule ID and App Credentials

You will need to collect a few pieces of information prior in order to delete the scheduled notification:

  • App Key
  • Master Secret
  • Schedule ID

Our guide on How to Find My App Key or Secret will provide the information retrieving the first two items.

Store these credentials securely, as they provide authorization to send notifications and make changes on the application.

You may already know the Schedule ID. If you are creating the Scheduled Pushes through the API we recommend logging the response, which will include the Schedule ID. You may also be able to find it by reviewing the scheduled notifications using the Schedules List API.

If you are unfamiliar with the API or have a large number of scheduled notifications, another option may be to find the Schedule ID based on the Team Activity Log In the Urban Airship Dashboard. This step requires you to be the original scheduler or the owner of the project and that the notification was scheduled in the Urban Airship Dashboard.

To find the Schedule ID from the Team Activity Log:

  1. Follow the Engage: Team Management Guide to access the Team Activity Log.
  2. Locate the desired Message Scheduled event and click on the Reference ID to see the Schedule ID:

    schedule_id.png

 

Now that we have the API Credentials, as well as the Schedule ID, we will use the API to confirm the Schedule ID is correct and to delete the notification.

This guide will provide two methods to do this, one using the tool Postman and one using a cURL request to make calls via the command line.

Confirm and Delete the Scheduled Push Method 1: Using Postman

Postman is a graphical interface tool used for interacting with APIs and is available both as a Google Chrome Extension and a standalone application. It is not built or maintained by Urban Airship but it is a tool we use and recommend. The screenshots in this article are based on the standalone application but should be similar to the Chrome Extension. You may use either.

Confirm the Schedule ID

Before you actually make the call to delete the Schedule ID, you will want to confirm you have the correct Schedule ID. 

This can be done through making a GET request to the
Schedules API Endpoint. You can use the same call to confirm that the Schedule no longer exists after making the delete request.

  1. Open Postman

    postman_console.png

  2. Configure your request:
    1. Set the method type to GET

      select_get.png

    2.  Enter the Schedules API url into the box:
      https://go.urbanairship.com/api/schedules/
    3.  Append the Schedule ID for the notification to delete to the URL. For example:
      https://go.urbanairship.com/api/schedules/c7492f56-ab34-4a25-9c46-8b0e0faea290


      schedule_push_endpoint.png


    4. Next you will need to configure your authentication information:
      1. Confirm you have selected the Authorization Tab
      2. Select Basic Auth from the Authorization Type dropdown
      3. Enter Your App Key for Username and Master Secret for the Password. Alternatively you may set up a Postman Environment and use environmental variables as done in this example.

        auth_config.png

    5. Next configure your other Headers:
      1. Select the Headers Tab
      2. Add the required headers for Accept and Content-Type as per our API Docs:
        Accept:application/vnd.urbanairship+json; version=3
        Content-Type:application/json
        headers_config.png

    6. Send your request:
      With the URL, method type, authentication, and headers configured you should now be able to send the request to GET the information about this specific Scheduled Notification.

      This request makes no changes to the notification, it only retrieves information.


      1. Confirm all information is correct
      2. Click the blue SEND button
      3. Provided that all information is correct, you should see a similar response to this in the bottom of the Postman window (Our guide on Troubleshooting HTTP Response Codes will help if you are not getting the expected response).

        schedule_api_get_response.png


      4. Confirm the information about the scheduled notification is the one you want to delete.

Delete the Scheduled Notification

Now that you have confirmed that you have the correct Schedule ID, you are ready to delete the notification.

Once you delete the scheduled notification, it will be completely removed from our systems and will not be retrievable.
  1. Duplicate the GET request:
    1. Locate the current request tab above the request URL and method type
    2. Right click on the request name and select Duplicate from the menu. You may wish to rename the request to make it easier to distinguish. Do not close the original.
    3. On the new request tab change the method type from GET to DELETE

      select_delete.png


    4. Confirm that the request url including the Schedule ID is still correct
    5. Reselect Basic Auth for the Authorization type if not already selected. Confirm the correct App Key and Master Secret.
    6. If all information is correct, click SEND to complete the DELETE request
    7. If the DELETE was successful you should receive back a blank response body but the HTTP Status Code should be returned as a “204 No Content” as seen here:

      delete_response.png
    8. To confirm that the Schedule was deleted, go back to the original GET request tab and send this request again. You should now get a “404 Not Found” response, confirming the scheduled notification no longer exists:

      get_not_found.png

Your scheduled notification has been successfully deleted. If you had been able to locate the schedule notification in the Message Overview in the Urban Airship Dashboard, refresh the page and you should see it removed from the Dashboard as well.


The rest of this article will provide an alternative process to delete the scheduled notification by making a cURL request in the command line.

Confirm and Delete the Scheduled Push Method 2: Using cURL request

Another method to use our API to delete a scheduled notification is by using the command line tool cURL. This tool is built into most Mac OS and Linux operating systems. A similar tool can be installed for Windows as well.

This method should be completed by someone with some technical knowledge on how to use the command line.


Confirm the Schedule ID

Before you delete the scheduled notification, you will want to confirm you have the correct Schedule ID. To do so you will want to first make a GET request to our API to confirm the information about the scheduled notification is what you expect.

Here is the basic template for this request:

curl -X GET \
    https://go.urbanairship.com/api/schedules/<SCHEDULED-ID> \
    -H 'accept: application/vnd.urbanairship+json; version=3' \
    -H 'authorization: Basic <BASE64 Encoded APP-KEY:MASTER-SECRET>' \
    -H 'content-type: application/json'

To use:

  1. Replace the <SCHEDULED-ID> in the url with the actual Schedule ID for the message being deleted.
  2. Get the Basic Auth string for your app. To create this you can use the base64 command in your Command line (We strongly recommend not using any online tools for this, as they may log requests and might be able to retrieve your auth information.):
    echo “APP-KEY:MASTER-SECRET” | base64
    Remove any equal symbols ("=") from the string and you should have something like:
    ejhGMHJhWlZTTXFDcFCdbZURNdnZpFRpQYmUtMjZrWFF2V3Myb2p5U0szaVJRCg
  3. Replace <BASE64 Encoded APP-KEY:MASTER-SECRET> with the auth string created in step 2.
  4. Enter this request into your command line window. You should receive the information back about this scheduled notification. Confirm that it matches the notification you want to delete.

Delete the Scheduled Notification

Now that you confirmed you know the Schedule ID you need. You are ready to delete the scheduled notification.

Once you delete the scheduled notification, it will be completely removed from our systems and will not be retrievable.
  1. Copy the GET cURL request, and replace the word GET with the word DELETE:
    curl -X DELETE \
        https://go.urbanairship.com/api/schedules/<SCHEDULED-ID> \
        -H 'accept: application/vnd.urbanairship+json; version=3' \
        -H 'authorization: Basic <BASE64 Encoded APP-KEY:MASTER-SECRET>' \
        -H 'content-type: application/json'
  2. Enter this request into your command line terminal. If correct you will not see any response.
  3. Resend the original GET request. If the delete was successful, you will get a 404 Not Found response.

    {"ok":false,"error":"Entity not found","error_code":40401}

Your scheduled push notification is now deleted.

Related Content: