Search code examples
rapircurlhttrpushbullet

Access Pushbullet API to delete pushes using R


I am using the RPushbullet package to send push notifications to several devices (smartphones) from R. This works perfectly fine.

Now: Before every new push message I want to delete the previous push. I want to do this by accessing Pushsbullet's API. The according Pushbullet documentation can be found here (in the navigation bar on the left go to "Push" -> "delete-push") but let me as well post it below:

enter image description here

I have tried to implement this with either of the httr, RCurl and Curl packages for R but I did not succeed. For example I have tried various alterations of the following codes:

library(httr)
r <- GET("https://api.pushbullet.com/v2/pushes/{device_ID}", 
      add_headers('Access-Token: x.X1XxXxXx1xxxX1xxxxxxXX1XxXXxXx1x'))

or

library(RCurl)
library(RJSONIO)
postForm("https://api.pushbullet.com/v2/pushes/{device_ID}",
     .opts = list(httpheader = c(Authorization = 'x.X1XxXxXx1xxxX1xxxxxxXX1XxXXxXx1x', Accept = 'application/json')))

but I always get a response saying something like "Access token is missing or invalid", e.g.:

Response [https://api.pushbullet.com/v2/pushes/{device_ID}]
  Date: 2017-01-30 09:44
  Status: 401
  Content-Type: application/json; charset=utf-8
  Size: 176 B

The status code 401 means "Unauthorized", i.e. I am not able to pass the access token to the form.

Any help on how to access this Pushbullet API in R would be greatly appreciated.

EDIT:

OS: Windows 10 Home, 64-bit

Curl command: curl --header 'Access-Token: x.X1XxXxXx1xxxX1xxxxxxXX1XxXXxXx1x' https://api.pushbullet.com/v2/users/me

Curl output: curl: (6) Could not resolve host: x.X1XxXxXx1xxxX1xxxxxxXX1XxXXxXx1x' {"error":{"code":"invalid_access_token","type":"invalid_request","message":"Access token is missing or invalid.","cat":"(=^´¢Ñ¤ë´¢Ñ^)y´╝Ø"},"error_code":"invalid_access_token"}


Solution

  • As you are on Windows, make sure to use double instead of single quotation marks ("..." instead of '...'). Also in your example you submit {device_ID} but from looking at the API you should probably specify the push_ID that you want to delete.