[R] Using R for cURL commands

Martijn Broeks MBroeks at kza.nl
Fri Apr 1 16:05:58 CEST 2016


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]]



More information about the R-help mailing list