FilipW
FilipW

Reputation: 1535

--user curl equivalent in httr

This is, I presume, some really simple curl code that I am trying to translate into a httr format.

curl -X POST \
  --user '<email>:<password>' \
  --header 'user-key: <user_key>' \
  --url https://api.m.com/v1/clients

So far I have tried

library(httr)    
POST(url = "https://api.m.com/v1/clients",
                 add_headers('user-key' = "userkey",
                             user = 'email:password'))

But without success. Any hints on what is wrong here? Is there an httr equivalent to --user in the curl code?

Upvotes: 4

Views: 1840

Answers (1)

Rodrigo Araujo
Rodrigo Araujo

Reputation: 106

library(httr)  

username <- 'my_user_name'
password <- 'my_password'

POST(url = "https://api.m.com/v1/clients", 
                 config = authenticate(username, password), add_headers("Content-Type: application/json"),
                 body = upload_file('./my_file.json'),
                 encode = 'json')

Upvotes: 9

Related Questions