The GET-function works well. So it is possible to get data from Bitrix (e.g. crm.lead.get), here the script:
library(httr)
library(jsonlite)
Url <- "https://bitrixxxxxxx.xx/rest/50/xxxxxxxxxxxxxx/crm.lead.get.json?ID=2470"
GET(Url,accept_json())
But the update (crm.lead.update) does not work. Here is one try:
body <-'{
fields: [
{
"UF_CRM_1999999999999": "Text 1",
"UF_CRM_1999999999998": "Text 2"
} ] }'
or
request_body <- data.frame(
UF_CRM_1999999999999 = c("Text 1"),
UF_CRM_1999999999998 = c("Text 2")
)
request_body_json <- toJSON(list(fields = request_body), auto_unbox = TRUE)
body <- list(
"fields" = request_body_json,
"params" = request_body2_json
)
or
body <- '
{
id: 2470,
fields:
{
"UF_CRM_1999999999999": "Text 1",
"UF_CRM_1999999999998": "Text 2"
},
params: { "REGISTER_SONET_EVENT": "Y" }
}'
POST("https://bitrixxxxxxx.xx/rest/50/xxxxxxxxxxxxxx/crm.lead.update.json?id=2470",encode="json",accept_json(),body=body)
The online-help from Bitrix24 (Link to Bitrix) suggest the following solution:
var id = prompt("Enter ID");
BX24.callMethod(
"crm.lead.update",
{
id: id,
fields:
{
"STATUS_ID": "IN_PROCESS",
"CURRENCY_ID": "USD",
"OPPORTUNITY": 15500
},
params: { "REGISTER_SONET_EVENT": "Y" }
},
function(result)
{
if(result.error())
console.error(result.error());
else
{
console.info(result.data());
}
}
);
I use for the crm.lead.update the PUT function and many combination for the body. Has anybody an idea for a solution or a template for r (crm.lead.update and crm.lead.add)?