Z
Z
zahar_922020-05-21 12:23:56
PHP
zahar_92, 2020-05-21 12:23:56

How to make Bitrix url request?

Hello!
Tell me how to execute a URL request after registering a user in 1C-Bitrix?
Tried like this:

AddEventHandler("main", "OnAfterUserRegister", Array("Unisender", "OnAfterUserRegisterHandler"));
class Unisender
{
    function OnAfterUserRegisterHandler(&$arFields)
    {
            $unisender = file_get_contents('https://api.unisender.com/ru/api/subscribe?format=json&api_key=6o5qtwwi5tgtgr4jw97xc8ypocjbq8fz3u3e48ra&list_ids=20662459,14498425&fields[email]='.$arFields["EMAIL"].'&fields[Name]='.$arFields["NAME"].'');
            return $unisender;
   }
}

But the URL fails.
Inside the function tried to execute via cURL
$ch = curl_init('https://api.unisender.com/ru/api/subscribe?format=json&api_key=6o5qtwwi5tgtgr4jw97xc8ypocjbq8fz3u3e48ra&list_ids=20662459,14498425&fields[email]='.$arFields["EMAIL"].'&fields[Name]='.$arFields["NAME"].'');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    $data = curl_exec($ch);
    curl_close($ch);

My knowledge is not enough to figure out what the problem is. After executing the URL, a subscriber should be created in the Unisender.

This is how it works
spoiler

$arFields["EMAIL"] = '[email protected]';
$arFields["NAME"] = 'test1';

$info = file_get_contents('https://api.unisender.com/ru/api/subscribe?format=json&api_key=6o5qtwwi5tgtgr4jw97xc8ypocjbq8fz3u3e48ra&list_ids=20662459,14498425&fields[email]='.$arFields["EMAIL"].'&fields[Name]='.$arFields["NAME"].'');
//$info = json_decode($info, true);
print_r($info);


But this works just when the page is loaded, but it should after the user registers. I read in the docs about the standard URL execution method, but I didn’t understand how to implement it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question