0
votes

When trying to revoke the oauth access_token for Box, I get the error : Client id was not found in the headers or body

This is the curl-command (which works fine) :

curl https://api.box.com/oauth2/revoke -d 'client_id=CLIENT_ID&client_secret=CLIENT_SECRET&token=access_token' -X POST

When trying the same with php curl, I get the error.

<?php
$revokeurl="https://api.box.com/oauth2/revoke";
$dataq = array(
    'client_id' => $client_id,
    'client_secret' => $client_secret,
    'token' => $access_token
        );
$dataqjson= json_encode($dataq);

$headers=array(
    "Content-Type: application/json"
    );

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => $revokeurl,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $dataqjson,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_SSL_VERIFYPEER => FALSE,
    CURLOPT_SSL_VERIFYHOST => FALSE
));

$response = curl_exec($curl);
$json_response = json_decode( $response, TRUE );
curl_close($curl);
?>

Why is my POST with json body not correct ?

1

1 Answers

1
votes

Data should be set as application/x-www-form-urlencoded rather than JSON-encoded. Example:

<?php

$revokeurl = "https://api.box.com/oauth2/revoke";

$dataq = array(
    'client_id'     => 'client_id',
    'client_secret' => 'client_secret',
    'token'         => 'access_token',
);

$curl = curl_init();

curl_setopt_array(
    $curl,
    array(
        CURLOPT_URL            => $revokeurl,
        CURLOPT_CUSTOMREQUEST  => "POST",
        CURLOPT_POSTFIELDS     => http_build_query($dataq),
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false
    )
);

$response = curl_exec($curl);
$json_response = json_decode($response, false);
print_r($json_response);
curl_close($curl);