API in PHP

Document created by Kailash Kumar on Jun 6, 2017Last modified by Kailash Kumar on Jun 6, 2017
Version 3Show Document
  • View in full screen mode

// Create multiple users in bridge

 

$url = $bridge['siteurl'].'/api/admin/users';

  $token = base64_encode($bridge['bridge_api_key'].':'.$bridge['bridge_secret']);  $headers = array("content-type" => "application/json", Accept => "application/json", AUTHORIZATION => "Basic ".$token);

  $api = new RestClient();

 

  foreach ($users as $user){

  $userData['uid'] = $user['email'];

  $userData['email'] = $user['email'];

  $userData['first_name'] = $user['firstname'];

  $userData['last_name'] = $user['lastname'];

 

  $payload = array("users" => array($userData));

  $response = $api->post($url, json_encode($payload), $headers);

 

 

  if ($response->info->http_code == 200){

  $result = json_decode($response->response, true);

  }

  elseif ($response->info->http_code == 400){

     echo "fail";

  }

  else{

      echo "error";

  }

  }

Attachments

    Outcomes