When using endpoint API, we are most time required to authenticate the request before it can be process.
In this post I'll show you how to set basic authentication on your php script.
<?php
$basic_1 = base64_encode("username: your_username");
?>
You can now use basic authentication on your php code once you call the variable name like the example below
<?php
$basic_1 = base64_encode("username: your_username");
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.endpoint_url.com/api/v1/auth/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\n \"amount\": 100.00}",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic ".$basic_1,
"Content-Type: application/json"
),
));
?>
Conclusion
This should give a success response
Top comments (0)