Thank you,
I fixed the code and got a lot farther. The last thing I need to do is convert the raw data from the API call into JSON format. Then I can parse the JSON using the jsonlite package. Finally convert the parsed JSON to a data frame for analysis. I'm getting this weird lexical error on the 'fromJSON' line. Maybe an encoding issue. An xml issue. I'm not sure.
library(curlconverter)
library(httr)
library(jsonlite)
#Pasting curl command line
flat <- straighten("curl -X POST --user Example123:x https://app.bluefolder.com/api/2.0/customers/list.aspx --data '<request><customerList><listType></listType></customerList></request>'")
#Turns the URL parts list into a fully functional httr call. It's vectorized.
req <- make_req(flat)[[1]]
#Reformat the function source to make it more readable
httr::VERB(verb = "POST",
url = "https://app.bluefolder.com/api/2.0/customers/list.aspx",
body = "<request><customerList><listType></listType></customerList></request>",
httr::authenticate(user = "Example123", password = "x"),
httr::verbose(),
httr::add_headers(),
encode = "json")
#Translate that to a plain POST call without namespacing
getInfoInJson <- POST(url = "https://app.bluefolder.com/api/2.0/customers/list.aspx",
body = "<request><customerList><listType></listType></customerList></request>",
authenticate(user = "Example123", password = "x"),
verbose(),
add_headers(),
encode = "json")
curl_string <- "curl -X POST --user Example123:x https://app.bluefolder.com/api/2.0/customers/list.aspx --data '<request><customerList><listType></listType></customerList></request>'"
make_req(straighten(curl_string))[[1]]()
#accesses the body as a character vector
get_prices_text <- content(getInfoInJson, "text", encoding = "UTF-8")
#converts the raw data from API call into JSON format. Then can parse the JSON using the jsonlite package
#Getting errors from this line below
get_prices_json <- fromJSON(get_prices_text, flatten = TRUE)
#convert the parsed JSON to a data frame for analysis
get_prices_df <- as.data.frame(get_prices_json)
Error:
Error: lexical error: invalid char in json text.
<?xml version="1.0" ?><response
(right here) ------^