Search code examples
iosiphonerpushbullet

RPushullet is not working: 400: Bad Request - Usually this results from missing a required parameter


I have been using pushbullet in the software R (RPushbullet package) to message me when a script finishes. It worked nicely with my notebook and Iphone, however, with the workstation it is not working. The followiing message is returned:

Warning message:
400: Bad Request - Usually this results from missing a required parameter.

I have installed pushbullet in three devices: my workstation, my personal notebook and in my Iphone.

From this, I have observed some things that can be related to the problem: 1) The Access Token is lost every time I restart a session in my online account; 2) Although the setup return a valid key message from my .rpushbullet.json file after the configuration, the API key cannot be retrieved by another code.

My R script:

> require(RPushbullet)
> require(jsonlite)

> pbSetup() #Creating my setup to "~/.rpushbullet.json" file
Please enter your API key (aka 'Access Token': "my API key"
[1] "1. iPhone de XXXXX"
[1] "2. XXXXX"
Select a default device (0 for none): 1

> pbValidateConf(conf = "~/.rpushbullet.json")
key is VALID
device XXX is VALID
device XXX is VALID
[1] TRUE

> pbPost("note", "The R Script worked")
Warning message:
400: Bad Request - Usually this results from missing a required parameter.

> pbGetUser(apikey = .getKey())
Error in .getKey() : could not find function ".getKey"

"my API key" and XXX are valid things that I omitted in the example code

pbPost("note", "The R Script worked")

This code is enough to post to all my devices (when using my notebook), even lacking the other parameters


Solution

  • apparently pbPost() is a little bit picky about the parameter it receives. You need to at least specify type, title and body. As in:

    pbPost(type="note", title="testTitle", body="testBody")
    

    If you enter these 3 parameters it should work fine.

    Regarding your points 1) and 2), indeed the token is lost and you need to force RPushbullet to read your .json file again. This next workaround works for me, though: I don't create a .json file but instead I pass the key and device id directly to the pbPost().

    gimme_a_shout_when_finished = TRUE
    
    if (gimme_a_shout_when_finished){
      library(jsonlite)
      library(RPushbullet)
      my_phone_id = "xxx...myphoneid...xxx"
      my_PB_apikey = "xxx...myapikey...xxx"
      pbPost(type = "note", title = "my tile", body = "my body",
             apikey = my_PB_apikey, devices = my_phone_id, verbose = FALSE,
             debug = FALSE)
    }
    

    This has been working for me so far. Regarding getting the apikey directly... no ideas for the moment.

    Hope this helps.