Level 9
Guzzle will encode the auth for you use 'auth' => ['user', 'pass']
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi Guys
I am trying to integrate to a payment gateway and send sms'es from my application using GuzzleHttp:
i get the error in the tile and suspect is how i am passing the authentication as required by the API
Authentication requirement:
When using an API token, the value to be encoded will be <token-id>:<token-secret>. These values before Base64 encoding look something like this
BBDE1B476E03498AA768F66A286AABDC-01-B:9jSbVDK20!MXdfRGiIIFu#ffUE8*S
My API call:
public function initiateSmsGuzzle($employeeMobile, $message)
{
$client=new Client([
'headers'=>['content-type'=>'application/json','Accept'=>'application/json'],
]);
$ID=base64_encode('******_ID');
$KEY=base64_encode('******_KEY');
$response = $client->request('POST','https://api.bulksms.com/v1', [
'auth'=>[$ID.':'.$KEY],
'form_params' => [
'message' => $message,
'mobiles' => $employeeMobile,
],
]);
$response = json_decode($response->getBody(), true);
}
The error above refers to this part of the Guzzle file:
laravel/vendor/guzzlehttp/guzzle/src/Client.php line 354
and that part contains this:
if (!empty($options['auth']) && is_array($options['auth'])) {
$value = $options['auth'];
$type = isset($value[2]) ? strtolower($value[2]) : 'basic';
switch ($type) {
case 'basic':
// Ensure that we don't have the header in different case and set the new value.
$modify['set_headers'] = Psr7\_caseless_remove(['Authorization'], $modify['set_headers']);
$modify['set_headers']['Authorization'] = 'Basic '
. base64_encode("$value[0]:$value[1]"); //THIS IS LINE 354
break;
case 'digest':
// @todo: Do not rely on curl
$options['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_DIGEST;
$options['curl'][CURLOPT_USERPWD] = "$value[0]:$value[1]";
break;
case 'ntlm':
$options['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_NTLM;
$options['curl'][CURLOPT_USERPWD] = "$value[0]:$value[1]";
break;
}
}
Please or to participate in this conversation.