Home > Enterprise >  how to make external API call with basic authentification from Symfony 4 controller?
how to make external API call with basic authentification from Symfony 4 controller?

Time:09-22

As mentioned in the question I am trying to call this Adyen API with specific authentification credentials and passing JSON object, Using Curl it is done like this.

curl https://pal-test.adyen.com/pal/servlet/Recurring/v68/disable \
-U "[email protected]":"Pa$$W0rd" \
-H "Content-Type: application/json" \
-d '{
  "merchantAccount": "exampleMerchantAccount",
  "shopperReference": "exampleShopperReference"
    }'

I tried to do this using HTTPClient Request:

$params = array(
        "merchantAccount" => "exampleMerchantAccount",
        "shopperReference" => "exampleShopperReference"
    );
$result = $this->client->request('POST', 'https://pal-test.adyen.com/pal/servlet/Recurring/v68/disable', $params);

But I still can't understand how to pass the basic authentification credentials.

Any help please .

CodePudding user response:

As written in the documentation, add it to the parameters like this:

$result = $this->client->request(
  'POST',
  'https://pal-test.adyen.com/pal/servlet/Recurring/v68/disable',
  [
   'auth_basic' => ['[email protected]', 'Pa$$W0rd'],
   'body' => $params,
  ]
);
  • Related