$accountName = 'xxxx'; //там мой домен
$secretKey = 'xxxxx'; //Там мой ключ АПИ
$user = [];
$user['user']['email'] = $_POST['email'];
$user['user']['phone'] = $_POST['phone'];
$user['user']['first_name'] = $_POST['name'];
$json = json_encode($user);
$base64 = base64_encode($json);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $accountName . '.getcourse.ru/pl/api/users');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'action=add&key=' . $secretKey . '¶ms=' . $base64);
$out = curl_exec($curl);
echo $curl;
curl_close($curl);
curl -i -H "Accept: application/json; q=1.0, */*; q=0.1" "https://zero-ninja.getcourse.ru/pl/api/users" -d "action=add&key={secret_key}¶ms={params}"
HTTP/2 200
server: nginx/1.20.1
date: Fri, 09 Sep 2022 21:05:08 GMT
content-type: application/json; charset=UTF-8
set-cookie: PHPSESSID5=f754b2ead20ce1842251abac5e383516; expires=Mon, 10-Oct-2022 21:05:08 GMT; Max-Age=2678400; path=/;Priority=High; domain=zero-ninja.getcourse.ru; HttpOnly
expires: Thu, 19 Nov 1981 08:52:00 GMT
cache-control: no-store, no-cache, must-revalidate
pragma: no-cache
x-frame-options: DENY
server-version: 18
set-cookie: dd_bdfhyr=083f8fe6f3db3b15e15625cf4bae4418; expires=Sat, 10-Sep-2022 21:05:08 GMT; Max-Age=86400; path=/; secure; HttpOnly
x-xss-protection: 1
{"success":false,"error":"Неавторизованное API-обращение","trace":"#0 [internal function]: app\\modules\\api\\controllers\\ApiJsonController->actionIndex()\n#1 /home/deploy/www/prod/releases/1/new/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)\n#2 /home/deploy/www/prod/releases/1/new/vendor/yiisoft/yii2/base/Controller.php(151): yii\\base\\InlineAction->runWithParams(Array)\n#3 /home/deploy/www/prod/releases/1/new/vendor/yiisoft/yii2/base/Module.php(455): yii\\base\\Controller->runAction('', Array)\n#4 /home/deploy/www/prod/releases/1/new/vendor/yiisoft/yii2/web/Application.php(84): yii\\base\\Module->runAction('api/users', Array)\n#5 /home/deploy/www/prod/releases/1/new/components/web/Application.php(121): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))\n#6 /home/deploy/www/prod/releases/1/new/vendor/yiisoft/yii2/base/Application.php(375): app\\components\\web\\Application->handleRequest(Object(yii\\web\\Request))\n#7 /home/deploy/www/prod/releases/1/new/web/getcourse.php(37): yii\\base\\Application->run()\n#8 {main}"}
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
> POST /pl/api/users HTTP/1.1
> Host: zero-ninja.getcourse.ru
> User-Agent: curl/7.83.1
> Accept: application/json; q=1.0, */*; q=0.1
> Content-Length: 271
> Content-Type: application/x-www-form-urlencoded
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: nginx/1.20.1
Server: nginx/1.20.1
< Date: Fri, 09 Sep 2022 21:07:23 GMT
Date: Fri, 09 Sep 2022 21:07:23 GMT
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Connection: keep-alive
Connection: keep-alive
< Set-Cookie: PHPSESSID5=54e498c8aed2cecb7314d00f30b64650; expires=Mon, 10-Oct-2022 21:07:23 GMT; Max-Age=2678400; path=/;Priority=High; domain=zero-ninja.getcourse.ru; HttpOnly
Set-Cookie: PHPSESSID5=54e498c8aed2cecb7314d00f30b64650; expires=Mon, 10-Oct-2022 21:07:23 GMT; Max-Age=2678400; path=/;Priority=High; domain=zero-ninja.getcourse.ru; HttpOnly
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
Pragma: no-cache
< X-Frame-Options: DENY
X-Frame-Options: DENY
< Server-version: 11
Server-version: 11
< X-XSS-Protection: 1
X-XSS-Protection: 1
<
* Connection #0 to host zero-ninja.getcourse.ru left intact
curl -i -H "Accept: application/json; q=1.0, */*; q=0.1" "https://zero-ninja.getcourse.ru/pl/api/users" -d "action=add&key={secret_key}¶ms=CgkJewoJCQkidXNlciI6ewogICAgImVtYWlsIjoidGVzdEB0ZXN0LW1haWwuY29tIiwKCQkJCSJwaG9uZSI6Iis3OTk5OTk5LTk5LTk5IiwKCQkJCSJmaXJzdF9uYW1lIjoi0JjQstCw0L0iLAoJCQkJImxhc3RfbmFtZSI6ItCY0LLQsNC90L7QsiIsCgkJCQkiY2l0eSI6ItCY0LLQsNC90L7QstC+IiwKCQkJCSJjb3VudHJ5Ijoi0KDQvtGB0YHQuNGPIgoJCQl9LAoJCQkic3lzdGVtIjp7CiAgICAgICAgICAgICAgICAicmVmcmVzaF9pZl9leGlzdHMiOjEKCQkJfQoJCX0="
curl -i -H "Accept: application/json; q=1.0, */*; q=0.1" "https://zero-ninja.getcourse.ru/pl/api/users" -d "action=add&key=LiJL3dn2rm0acEVfJsRGHKY0IJvvh0QmBRjwsaPfootefwDkD4yzRNJNZaf0cPItl25xQtUVAfHEH6rcWWc4tRkoTSELR7OtJN8JY4UHi9zlJFlAKcunwDUdrSGqkvJr¶ms=CgkJewoJCQkidXNlciI6ewogICAgImVtYWlsIjoidGVzdEB0ZXN0LW1haWwuY29tIiwKCQkJCSJwaG9uZSI6Iis3OTk5OTk5LTk5LTk5IiwKCQkJCSJmaXJzdF9uYW1lIjoi0JjQstCw0L0iLAoJCQkJImxhc3RfbmFtZSI6ItCY0LLQsNC90L7QsiIsCgkJCQkiY2l0eSI6ItCY0LLQsNC90L7QstC+IiwKCQkJCSJjb3VudHJ5Ijoi0KDQvtGB0YHQuNGPIgoJCQl9LAoJCQkic3lzdGVtIjp7CiAgICAgICAgICAgICAgICAicmVmcmVzaF9pZl9leGlzdHMiOjEKCQkJfQoJCX0="
HTTP/1.1 200 OK
Server: nginx/1.20.1
Date: Fri, 09 Sep 2022 21:40:20 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Frame-Options: DENY
Server-version: 25
Set-Cookie: PHPSESSID5=ebbd4005c87fe59a3def2e4a431633fa; expires=Mon, 10-Oct-2022 21:40:20 GMT; Max-Age=2678400; path=/;Priority=High; domain=zero-ninja.getcourse.ru; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
X-XSS-Protection: 1
<?php
$accountName = 'zero-ninja';
$secretKey = 'LiJL3dn2rm0acEVfJsRGHKY0IJvvh0QmBRjwsaPfootefwDkD4yzRNJNZaf0cPItl25xQtUVAfHEH6rcWWc4tRkoTSELR7OtJN8JY4UHi9zlJFlAKcunwDUdrSGqkvJr';
$user = [];
$user['user']['email'] = 'test@testme.ru';
$user['user']['phone'] = '+74951234567';
$user['user']['first_name'] = 'Василий';
$user['user']['last_name'] = 'Пупкин';
$user['user']['city'] = 'Москва';
$user['user']['country'] = 'Россия';
$user['user']['group_name'] = ['Группа1', 'Группа2'];
$user['system']['refresh_if_exists'] = 1;
$json = json_encode($user);
$base64 = base64_encode($json);
if( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, 'https://' . $accountName . '.getcourse.ru/pl/api/users');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json'));
curl_setopt($curl, CURLOPT_VERBOSE,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'action=add&key=' . $secretKey . '¶ms=' . $base64);
$out = curl_exec($curl);
echo $out;
curl_close($curl);
} else {
echo 'Failed initialization';
}
{"success":false,"error":"Пустой параметр action","trace":"#0 [internal function]: app\\modules\\api\\controllers\\ApiJsonController->actionIndex()\n#1 /home/deploy/www/prod/releases/2/new/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)\n#2 /home/deploy/www/prod/releases/2/new/vendor/yiisoft/yii2/base/Controller.php(151): yii\\base\\InlineAction->runWithParams(Array)\n#3 /home/deploy/www/prod/releases/2/new/vendor/yiisoft/yii2/base/Module.php(455): yii\\base\\Controller->runAction('', Array)\n#4 /home/deploy/www/prod/releases/2/new/vendor/yiisoft/yii2/web/Application.php(84): yii\\base\\Module->runAction('api/users', Array)\n#5 /home/deploy/www/prod/releases/2/new/components/web/Application.php(121): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))\n#6 /home/deploy/www/prod/releases/2/new/vendor/yiisoft/yii2/base/Application.php(375): app\\components\\web\\Application->handleRequest(Object(yii\\web\\Request))\n#7 /home/deploy/www/prod/releases/2/new/web/getcourse.php(37): yii\\base\\Application->run()\n#8 {main}"}