1

The following POST works via cURL from the terminal:

curl
--header 'Authorization: Bearer <access token here>' 
--header 'Content-Type: application/json' 
-X POST https://api.pushbullet.com/v2/pushes 
--data-binary '{"type": "note", "title": "Note Title", "body": "Note Body"}'

However, I have been unable to replicate this in the Arduino IDE (in C). I thought I would be able to use the HTTPClient object, however I only see a method for GET in the documentation, and not POST.

I would appreciate any nod in the right direction.

vikzilla
  • 3,998
  • 6
  • 36
  • 57

4 Answers4

3

I would try this:

HttpClient client;
client.setHeader("Authorization: Bearer <access token here>");
client.addHeader();
client.setHeader("Content-Type: application/json");
client.addHeader();
client.post("https://api.pushbullet.com/v2/pushes", "{\"type\": \"note\", \"title\": \"Note Title\", \"body\": \"Note Body\"}"

I don't have a Yún to test with. Despite the post method not being documented, it does appear to exist..

m01
  • 9,033
  • 6
  • 32
  • 58
  • 1
    I can confirm this works on the Yun. However, you don't need to use the client.addHeader() function as it is private and called automatically by the class when needed. – genepool99 Nov 22 '16 at 22:24
  • any idea how you do this with octet-stream data. like for an image, do you need to post each byte? – 4m1r Mar 22 '17 at 19:44
  • You could try to find some shell escape sequence and encode the data appropriately (look at the [bridge library source](https://github.com/arduino-libraries/Bridge). Or, a better option would be to write the data to a file using [YunFileIOWrite](https://www.arduino.cc/en/Reference/YunFileIOWrite) and then do something like `client.post("https://api.pushbullet.com/v2/pushes", "@/path/to/file.png")`, making use of the fact that the data is passed in as `curl`'s `--data` argument. Needless to say, this probably isn't exactly how it's intended to be used... – m01 Mar 23 '17 at 21:20
0

In questo modo funziona :-):

Process avviso;


if (!avviso.running())
  {
    avviso.begin("curl");
    avviso.addParameter("-k");
    avviso.addParameter("-H");
    avviso.addParameter("Authorization: Bearer v1EhAXIVEhms05l97PTHkQFRNWiK5q6L6fujzny9qxWvc");
    avviso.addParameter("-X");
    avviso.addParameter("POST");
    avviso.addParameter("https://api.pushbullet.com/v2/pushes");
    avviso.addParameter("-H");
    avviso.addParameter("Content-Type:application/json");
    avviso.addParameter("--data-binary");
    String titolo = "Arduino";
    avviso.addParameter("{\"type\": \"note\", \"title\": \""+titolo+ "\", \"body\": \"Note Body\"}");
    avviso.run(); 
  }
  • Welcome to Stack Overflow! Stack Overflow is an English speaking site, so it requires that all questions and answers be in English. Please translate your answer to English if you can, we can help edit to improve the english if necessary. Your code may work but having it explained properly to the OP is an important part of answering. – SuperBiasedMan Jul 09 '15 at 09:25
0

The Bridge library only supports GET requests, however you can use the Process class to curl POST requests...

These articles explain how to use the Process class to send data to the ThingSpeak and Carriots apis respectively, but you should be able to hit whatever api you want using the same techniques...

Hope this helps... I'll be trying this out as well and follow up with results.

http://starter-kit.nettigo.eu/2014/arduino-yun-sending-data-thingspeak-post/ https://www.carriots.com/tutorials/send_stream/arduino_yun

Be Free Studios
  • 110
  • 1
  • 8
0

Also remember to call client.noCheckSSL(); before calling post() or get() if your endpoint is an httpS!

This will make the bridge lib to add a -K flag to curl so it ignores security ssl certs etc...

This one is undocumented as well!

mim
  • 1,301
  • 14
  • 24