0

I am trying to pull some json body with passing an array of string numeric in httr::POST.This has to be an array. For instance, body = toJSON(x=list('_id'="1"), auto_unbox=TRUE) did not work.

How do I pass an array of string numeric like above in the body?

res <-httr::POST(url=some url, 
                 httr::add_headers(
                   "Accept"= "application/json",
                   "Authorization" = my Token, 
                   "Content-Type"= "application/json"),
                 body = ????, #how do i pass ["1"]
                 endoce = ???)
content(res,as = 'text')
Capt.Krusty
  • 597
  • 1
  • 7
  • 26
  • Have a look here: https://stackoverflow.com/questions/56958500/how-to-make-a-post-request-with-header-and-data-options-in-r-using-httrpost/56964855#56964855 – tvdo Jul 10 '19 at 20:19
  • I wanted to AVOID passing JSON. Anyway, I was able to figured out the solution. – Mahesh Imaduwa Jul 10 '19 at 23:14
  • perhaps post your solution then so as to help others? – QHarr Jul 11 '19 at 07:23
  • `myarr <- c("1", "2") ` `httr::POST( url = some_url, httr::add_headers( "Accept" = "application/json", "Authorization" = my_token, "Content-Type" = "application/json" ), body = paste0("[", toString(myarr), "]") ) ` – Mahesh Imaduwa Jul 16 '19 at 23:30

0 Answers0