Magento 2 SOAP Credentials – API and OAuth Setup Guide

apimagento2oauthsoap

Poking around the codebase and some questions here it looks like Magento 2 — much to the chagrin of certain segments of the web development community — will still support SOAP API endpoint. (However, it looks like this SOAP API is completely new code — probably implemented with the same service contracts as the RESTful API)

Are there credentials for this new API? If so, where can a user create these credentials in the admin UI?

Or do the credentials for this API also tie into oAuth somehow? If so, how do the Magento 2 oAuth credentials tie into making SOAP API requests.

Best Answer

Alan, you are right, SOAP framework is completely different from the one in Magento 1 and was created specifically for Magento 2 needs to have Service layer interfaces same for REST, SOAP and PHP clients.

SOAP Authentication uses oAuth 2.0-like style of authentication using Bearer token. This is simple example on how to configure the SOAP client on PHP side:

    $opts = ['http' => ['header' => "Authorization: Bearer " . $token]];
    $context = stream_context_create($opts);
    $soapClient = new \Zend\Soap\Client($wsdlUrl);
    $soapClient->setSoapVersion(SOAP_1_2);
    $soapClient->setStreamContext($context);

Now, to the question where to get this token. There are few ways to obtain it, first one is to create manually in the Admin Backend. For this go to the System -> Integrations, click "Add New Integration", fill the form, select resources which you want to share with this integration and save. Then, click on "Activate" button. After few steps in the wizard, you will be provided with Four tokens. You should use Access Token as a Bearer token.

Another way to get a token is to complete oAuth registration http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-oauth.html#get-access-token

Related Topic