S
S
Soniked2020-07-10 11:40:30
1C-Bitrix
Soniked, 2020-07-10 11:40:30

Why does 1C-Bitrix REST API not accept POST?

There is a 1C-Bitrix distribution kit installed on your server.

With grief in half, I set up the API and created a Webhook.

But the problem is that the hook refuses to accept POST requests - only GET. Took a standard example from the reference book:

$queryUrl = sute.ru/catalog.section.add
$queryData = http_build_query(array(
    'fields' => array(
        "iblockId"=>1,
        "name"=>'NAME',
        "code"=>'CODE',
        "image"=>'image_base64'
    ),
    'params' => array("REGISTER_SONET_EVENT" => "Y")
));

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_POST => 1,
    CURLOPT_HEADER => 1,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $queryUrl,
    CURLOPT_POSTFIELDS => $queryData,
));

$result = curl_exec($curl);
curl_close($curl);

var_dump($result);


This request works on the demo version of Bitrix24, but on 1C-Bitrix I get the error {"error":100,"error_description":"Could not find value for parameter {fields}"} .

Full text of the answer:

string(840) "HTTP/1.1 100 Continue HTTP/1.1 400 Bad Request Date: Fri, 10 Jul 2020 08:32:32 GMT Server: Apache/2.4.29 (Ubuntu) P3P: policyref="/bitrix/p3p.xml", CP="NON DSP COR CUR ADM DEV PSA PSD OUR UNR BUS UNI COM NAV INT DEM STA" X-Powered-CMS: Bitrix Site Manager (DEMO) Set-Cookie: PHPSESSID=##############; path=/; HttpOnly Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Access-Control-Allow-Origin: * Access-Control-Allow-Headers: origin, content-type, accept X-Content-Type-Options: nosniff Set-Cookie: BITRIX_SM_SALE_UID=1; expires=Mon, 05-Jul-2021 08:32:32 GMT; Max-Age=31104000; path=/ Content-Length: 79 Connection: close Content-Type: application/json; charset=utf-8 {"error":100,"error_description":"Could not find value for parameter {fields}"}"

Googling the code/text of the error did not yield any results. Just learned how to send data using the GET method, writing fields in the link in the format "?fields[iblockId]=8&fields[name]...". However, I need to transfer images, and there is no way to transfer them via GET.

Please tell me, what am I doing wrong, how should I make up an array of data so that Bitrix understands what I want?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kontrael, 2020-07-10
@Kontrael

Dig towards the redirect, for example in .htaccess. When redirecting, the body of the POST request is lost.
Perhaps you have redirects for all requests without a slash at the end, to an analogue with a slash. Or "without www" to "c www"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question