Last active
March 15, 2017 21:52
-
-
Save pitbulk/075a289f9d5cbfd0e8dd1a30397a4c03 to your computer and use it in GitHub Desktop.
Onelogin - Invite Link APi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// URL & credentials | |
$url = "https://api.<us or eu>.onelogin.com/api/1/invites/get_invite_link"; | |
$access_token = "<access_token>"; | |
// Parameters | |
$email = "<email>"; | |
$data = array ( | |
'email' => $email, | |
); | |
$authorization = "bearer:$access_token"; | |
$data_string = json_encode($data); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
$header_opts = array( | |
'Content-Type:application/json', | |
'Authorization:'.$authorization, | |
'Content-Length: ' . strlen($data_string) | |
); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_opts); | |
$result = curl_exec($ch); | |
if ($result !== false) { | |
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | |
$body = substr($result, $header_size); | |
$result_data = json_decode($body); | |
if ($result_data->status->error == true) { | |
$errorMsg = $result_data->status->code. ", ".$result_data->status->type; | |
if ($result_data->status->message instanceof stdClass) { | |
$errorMsg .= " || " . $result_data->status->message->description; | |
} else { | |
$errorMsg .= " || " . $result_data->status->message; | |
} | |
throw new Exception($errorMsg); | |
} else { | |
$link = $result_data->data[0]; | |
} | |
} else { | |
throw new Exception(curl_error($ch), curl_errno($ch)); | |
} | |
curl_close($ch); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// URL & credentials | |
$url = "https://api.<us or eu>.onelogin.com/api/1/invites/send_invite_link"; | |
$access_token = "<access_token>"; | |
// Parameters | |
$email = "<email>"; | |
$personal_email = ""; | |
$data = array ( | |
'email' => $email, | |
); | |
if (isset($personal_email) && !empty($personal_email)) { | |
$data['personal_email'] = $personal_email; | |
} | |
$authorization = "bearer:$access_token"; | |
$data_string = json_encode($data); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
$header_opts = array( | |
'Content-Type:application/json', | |
'Authorization:'.$authorization, | |
'Content-Length: ' . strlen($data_string) | |
); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_opts); | |
$result = curl_exec($ch); | |
if ($result !== false) { | |
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | |
$body = substr($result, $header_size); | |
$result_data = json_decode($body); | |
if ($result_data->status->error == true) { | |
$errorMsg = $result_data->status->code. ", ".$result_data->status->type; | |
if ($result_data->status->message instanceof stdClass) { | |
$errorMsg .= " || " . $result_data->status->message->description; | |
} else { | |
$errorMsg .= " || " . $result_data->status->message; | |
} | |
throw new Exception($errorMsg); | |
} | |
} else { | |
throw new Exception(curl_error($ch), curl_errno($ch)); | |
} | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment