简体   繁体   中英

php api Unauthorized request json rpc 2.0

I want to access api with my api key that is correct but still geting back error 401 unauthorized. Api using json rpc 2.0.

This is example request from api docs.

Request:
{
  "jsonrpc": "2.0",
  "method": "getBoards",
  "params": {
       "clientId": "apikey"
 },
 "id": 1
}

And this is my php code.

$apiKey = 'apikey';
$apiUrl = 'apiUrl';

$data =  array(
        "jsonrpc" => "2.0",
        "method" => "getBoards",
        "params" => array(
            "clientId" => $apiKey
        ),
        "id" => "1"
);

$data_string = json_encode($data);
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

$response = curl_exec($ch);
curl_close($ch);

print_r($response);

Okey my client made a mistake and api key was wrong so at least this is the correct way how to use php with protocol jsonrpc 2.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM