[R] Using R for cURL commands

Ben Tupper btupper at bigelow.org
Fri Apr 1 17:28:12 CEST 2016


Hi,

Have you looked at httr?  I have been very happy using it with RESTful systems.

https://cran.r-project.org/web/packages/httr/index.html


Cheers,
Ben

> On Apr 1, 2016, at 10:05 AM, Martijn Broeks <MBroeks at kza.nl> wrote:
> 
> Hello,
> 
> 
> I'm looking for a way in which R can make my live easier.
> 
> Currently i'm using R convert data from a dataframe to json's and then sending these json's to a rest api using a curl command in the terminal (i'm on a mac).
> 
> 
> I've been looking for a way to use R for sending data from R to the rest api. My primairy focus was on using R for executing the curl command, however, I'm open to other approaches. The method I've been using so far:
> 
> 
> 
> I found some information online suggesting i'd use this code:
> 
> *js is a json from my R environment
> 
> 
> Library(RCurl)
> 
> postForm("https://MYWEBSITE.eu/api/v2/organisations/abc/projects/cosson/datasets/DATABASE",
> 
> .opts = list(postfields = js,
> 
> httpheader = c('Content-Type' = 'application/json', Accept = 'application/json'),
> 
> userpwd = "name:pwd",
> 
> ssl.verifypeer = FALSE))
> 
> (userpwd and url have been changed to hide sensitive information)
> 
> 
> This leads to the following error: "Error: Unauthorized". I've filled out the correct username and password, but I can't figure out why I'm getting this error. This is the curl command I'm using:
> 
> 
> curl -X POST -s --user "USERNAME:PASSWORD" -H "Content-type: application/xml" -d at test.json "https://MYWEBSITE.eu/api/v2/organisations/abc/projects/cosson/datasets/DATABASE"
> 
> (userpwd and url have been changed to hide sensitive information)
> 
> 
> The json file is build up like this:
> 
> {\n    \"ID\": 601,\n    \"100-100\": 0 }
> 
> But this is a small part, the actual json contains 555 variables
> 
> 
> Thanks in advance for the help and let me know if something is unclear.
> 
> 
> 
> Disclaimer | The information transmitted is intended only for use by the addressee and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of it, or the taking of any action in reliance upon this information by persons and/or entities other than the intended recipient is prohibited. If you received this in error, please inform the sender and/or addressee immediately and delete the material. Thank you.
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org



More information about the R-help mailing list