Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. # Список пользователей, которых нужно импортировать
  2. # Первый элемент - User ID из вашей системы
  3. $users = array(
  4.     array('id' => 123,
  5.           'email' => 'mail1@mail.ru',
  6.           'phone' => '891xxxxxx',
  7.           'name' => 'Test'
  8.     ),
  9.     array('id' => 456,
  10.           'email' => 'mail2@mail.ru',
  11.           'phone' => '891xxxxxx',
  12.           'name' => 'Test2'
  13.     )
  14. );
  15. $auth_token = 'xxx'  # TODO: ПОДСТАВЬТЕ СЮДА ВАШ AUTH_TOKEN, его можно найти в разделе Настройки > API КЛЮЧИ
  16.  
  17.  
  18. for ($i =0; $i < count($users); ++$i ) {
  19.     $url = 'http://api.carrotquest.io/v1/users/'.$users[$i]['id'].'/props?auth_token='.$auth_token;
  20.     $operations = json_encode(array(
  21.             array('op' => 'update_or_create',
  22.                   'key' => '$email',
  23.                   'value' => $users[$i]['email']
  24.             ),
  25.             array('op' => 'update_or_create',
  26.                   'key' => '$phone',
  27.                   'value' => $users[$i]['phone']
  28.             ),
  29.             array('op' => 'update_or_create',
  30.                   'key' => '$name',
  31.                   'value' => $users[$i]['name']
  32.             ),
  33.         )
  34.     );
  35.    
  36.     $result = file_get_contents($url, false, stream_context_create(array(
  37.       'http' => array(
  38.         'method'  => 'POST',
  39.         'header'  => 'Content-type: application/x-www-form-urlencoded',
  40.         'content' =>http_build_query(array('operations' => $operations,'by_user_id'  => 'true')),
  41.       )
  42.     )));
  43.    
  44.    
  45.     print $result;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement