Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Checking/obtaining an OAuth2 session token w/CPD REST API v1
<?php
$params = array(
"client_id" => "683c5835a8d36a5bb974",
"client_secret" => "50ac9cb374989802d3d437c3fe0d7d8829c00e1b",
"username" => "user@theirdomain.co.uk",
"password" => "theirpasswordhere",
"grant_type" => "password",
);
$postData = "";
foreach($params as $k => $v) {
$postData .= $k . '='.urlencode($v).'&';
}
$postData = rtrim($postData, '&');
$url = "https://www.cpd.co.uk/restapi/v1/oauth2/access_token/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$rawdata = curl_exec($curl);
print $rawdata;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment