Sample code for 30+ languages & platforms
PHP

SugarCRM Logout

See more SugarCRM Examples

Demonstrates how to logout of a session.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\JsonObject;
use Chilkat2\Rest;
use Chilkat2\StringBuilder;

$success = false;

$rest = new Rest();

try {
    $rest->Connect('your.site.domain', 443, true, true);

    $rest->AddHeader('Cache-Control', 'no-cache');
    $rest->AddHeader('OAuth-Token', '<access_token>');

    $sbReq = new StringBuilder();

    $sbJson = new StringBuilder();
    $rest->FullRequestSb('POST', '/rest/v10/oauth2/logout', $sbReq, $sbJson);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

if ($rest->ResponseStatusCode != 200) {
    echo 'Received error response code: ', $rest->ResponseStatusCode, "\n";
    echo "Response body:\n";
    echo $sbJson->GetAsString(), "\n";
    exit;
}

$json = new JsonObject();
$json->LoadSb($sbJson);

// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.

$success = $json->BoolOf('success');

// A sample JSON response body that is parsed by the above code:

// {
//   "success": true
// }

echo "Example Completed.\n";