Hello RStudio Community , I have a question regarding JSON body responses on R using the httr package (specifically the PATCH()).
Objective
The idea is to update (or patch ) a JSON object in an API. To achieve this, I will use PATCH(). Using PATCH(), I have to send the necessary information to the API server. The API requires the body of my response to be of type JSON. The problem here is to replicate the JSON correctly.
Code Samples
The JSON I need to send has to look like this:
{
"data": {"someData": 012345}
}
The R code that I use to replicate this JSON is:
toJSON( list(`data`= list(`someData`=012345)) )
But, when I use the toJSON() I get the following:
{"data":{"someData":[12345]}}
The Problem
The problem here is in the [12345]
, I don't want that data to be inside an array. My response has to be like the first code sample.
I will appreciate any help I can get.
My full PATCH() code, just in case:
PATCH(
url = "https://apidomain.example/apidir/example",
config = add_headers(
Authorization = paste("Auth Type", "API KEY example")
),
body = toJSON(list(`data`= list(`someData`=012345)))
)
I get a 400 error: bad request