I am using the R package httr to send a POST requests. I know how the body of the reqeust should look like, but I was not able to create it using httr. I am always missing a pair of square brackets (see below).
How do I have to modify my R code to get the desired result?
It seems you need to create a more nested list. the [...] missing are for a missing list level. Cells must be a two levels list before Tuple....
Here an exemple that seems to format correctly the POST data.
cells <- c("Dimensions('Time')/Hierarchies('Time')/Elements('ABC')",
"Dimensions('Currency')/Hierarchies('Currency')/Elements('USD')")
value <- 123
library(magrittr)
httr::POST(
url = "http://httpbin.org/post",
body = list(Cells = list(list(`Tuple@odata.bind` = cells)), Value = value),
httr::content_type("application/json"),
encode = "json"
) %>%
# get content as text
httr::content(as = 'text') %>%
# to select and print nicely
jqr::jq(".json")
#> No encoding supplied: defaulting to UTF-8.
#> {
#> "Cells": [
#> {
#> "Tuple@odata.bind": [
#> "Dimensions('Time')/Hierarchies('Time')/Elements('ABC')",
#> "Dimensions('Currency')/Hierarchies('Currency')/Elements('USD')"
#> ]
#> }
#> ],
#> "Value": 123
#> }
On about I build this example : I used httpbin service to test POST request. What is returned by the request is the request itself. So I get so content as text and use (awesome) jqr to select the json data and print nicely.
If your question's been answered, would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: