gohighlevel-php-sdk

Authorization Of the user

Redirect the user to authorize

include 'vendor/autoload.php';

$client_id = "";
$client_secret = "";
$scopes = "";
$callback = "" //callback url
$auth_url = "https://marketplace.gohighlevel.com"; // use: https://marketplace.leadconnectorhq.com for whitelabel 

$url = "$auth_url/oauth/chooselocation?response_type=code&redirect_uri=$callback&client_id=$client_id&scope=$scopes";
echo header("Location: $url");

Get Access Token

$ghl_access = \MusheAbdulHakim\GoHighLevel\GoHighLevel::getAccessToken('https://services.leadconnectorhq.com/oauth/token', 'application/x-www-form-urlencoded', [
    'client_id' => $client_id,
    'client_secret' => $client_secret,
    'grant_type' => 'authorization_code',
    'code' => $code // code obtained from the authorization,
    'redirect_uri' => $callback,
]);

Get Location Access Token from Agency Token

$client->oAuth()->AcessFromAgency($companyId, $locationId)

Get Location Where App is installed

$client = \MusheAbdulHakim\GoHighLevel\GoHighLevel::client($key, '2021-07-28');
$location = $client->oAuth()->location($appId, $companyId)

or

$location = $client->oAuth()->appLocation($appId, $companyId);