ixodid
ixodid

Reputation: 2400

Send cURL command from R

mailerLite is a SaaS that manages contacts and sends email. I am trying to use their API to add content to my account.

Their API is built on HTTP and it is RESTful. According to their documentation here, I can see how I have segmented my list. There is a PHP and cURL example:

curl -v https://api.mailerlite.com/api/v2/segments
-H "X-MailerLite-ApiKey: my-api-key"

This works successfully from the Terminal prompt on my Mac. Now I wish to do the same thing from R.

I tried this:

apiKey <- "my-api-key"
result <- GET("https://api.mailerlite.com/api/v2/segments", add_headers(Authorization = paste("X-MailerLite-ApiKey", apiKey)))
result
# Status 401: Unauthorized

Also, I am confused about the differences between the R packages: RCurl, httr, curl, and crul.

Upvotes: 0

Views: 143

Answers (1)

ekoam
ekoam

Reputation: 8844

Perhaps try

GET("https://api.mailerlite.com/api/v2/segments", add_headers(`X-MailerLite-ApiKey` = apiKey))

Upvotes: 1

Related Questions