r-lib / httr

httr: a friendly http package for R
https://httr.r-lib.org
Other
988 stars 1.99k forks source link

auto_unbox isn't being overcome by I() #678

Closed benrwoodard closed 3 years ago

benrwoodard commented 3 years ago

I have a json string that includes a single sub-list item so it is being unboxed. The result is a 400 error. I've tried to overcome the error by adding I() around the list object but when it encodes it still auto unboxes the item.

req <- httr::RETRY("POST",
                       url = request_url,
                       body = I(body),
                       encode = "json",
                       config(token = token),
                       verbose(data_out = TRUE),
                       httr::add_headers(
                         `x-api-key` = client_id,
                         `x-proxy-global-company-id` = company_id
                       ))

This is the intial 'body' argument image

This is the resulting json string from the retry() function

{"rsid":"ageo1xxpnwsdi2020prod","globalFilters":[{"type":"dateRange","dateRange":"2020-10-01T00:00:00.000/2020-10-16T00:00:00.000"}],"metricContainer":{"metrics":[{"columnId":"1","id":"metrics/visits","filters":"0"}],"metricFilters":[{"id":"0","type":"breakdown","dimension":"variables/page","itemId":"2056971154"}]},"dimension":"variables/daterangeday","settings":{"countRepeatInstances":true,"limit":400,"page":0,"dimensionSort":"asc","nonesBehavior":"return-nones"},"statistics":{"functions":["col-max","col-min"]}}
benrwoodard commented 3 years ago

It must have been something in my process of reading the json file. I used upload_file=("filepath.json") and it worked perfectly without adding I().