I'm trying to make a post call like this to return a jwt bearer token. But in php using cURL. So I can save the bearer token to a variable for use in the API calls.
$.ajax({
type: 'POST',
url: 'http://www.your-site.com/siteguard/api/prepare-public-jwt',
data: { api_key: 'YOUR_PUBLIC_API_KEY' },
dataType: 'json',
success: function (data) {
//Returns encoded JWT
console.log(data);
}
});
Php Code Im using
$url = $this->getTokenUrl();
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = ["api_key" => "xOMjVpz83rxDKjJUX9qNClB2BwadcRWjm09YSCdasdabdasdasdasdgTR8fuvR7jQHP8ZVpbOOmdXqKEt0AVX"];
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
The Return is this
{"code":401,"status":"error","response":"Invalid Public API key","link":"http:\/\/localhost\/siteguard\/api\/prepare-public-jwt"}"
Codebutton, located (in Windows) on the top right corner (about 2PM from the SEND button) 3. Select the desired programming language (PHP- cURL in your case). 4. ??? 5. Profit!json_encode($data)beforecurl_setopt($curl, CURLOPT_POSTFIELDS, $data);