I have had success using {httr} to access one of Twilio's APIs. e.g. I have used the code below to grab pages from their "Messages" API:
library(httr)
Twil_dest <- paste0("https://api.twilio.com/2010-04-01/Accounts/",
Twilio_SID, # my SID
"/Messages.json?PageSize=1000")
d <- GET(Twil_dest,
authenticate(Twilio_SID, tok)) # my SID and token
They have another API where you can request a job through POST
, which they then make accessible to a webhook (please clarify my terminology!). The instructions for that API are here for a variety of languages including curl, java, python, php, etc. For instance, for curl it suggests
curl -X POST https://bulkexports.twilio.com/v1/Exports/Messages/Jobs \
--data-urlencode "Email=you@example.com" \
--data-urlencode "WebhookMethod=POST" \
--data-urlencode "WebhookUrl=https://www.company.com/bulkexporthook" \
--data-urlencode "StartDay=2019-11-20" \
--data-urlencode "EndDay=2019-11-30" \
--data-urlencode "FriendlyName=Export1" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
I would like to use httr::POST
to submit that request, but I don't know how to format the parameters in the request.
When I have tried putting them in a list inside query(LIST_OF_MY_PARAMETERS)
, it says all the parameters must be named. When I construct a string where each one is preceded by ?
I get a bad request error 400.
POST(
paste0(
bulk_dest,
"?Email=MY@EMAIL.COM",
"?WebhookMethod=POST",
glue::glue("?WebhookUrl={webhook}"),
"?StartDay=2020-01-01",
"?EndDay=2020-01-10",
"?FriendlyName=Export1"
),
authenticate(Twilio_SID, tok)
)
Many thanks!
Jon