Last active
December 11, 2017 08:06
-
-
Save pswaine/596265df56c1c31911e1cabe5ddd1c57 to your computer and use it in GitHub Desktop.
M2 Web API Soap Token Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // basic information needed for requests | |
| $soapTokenUri = 'http://magento2ee.dev/soap/default?wsdl&services=integrationAdminTokenServiceV1'; | |
| $soapResourceUri = 'http://magento2ee.dev/soap/default?wsdl&services=cmsBlockRepositoryV1'; | |
| $username = 'admin'; | |
| $password = 'admin123'; | |
| $options = [ | |
| 'soap_version' => SOAP_1_2, | |
| 'trace' => 1, | |
| 'connection_timeout' => 120, | |
| ]; | |
| // create client and get token response using username and password | |
| $cli = new SoapClient($soapTokenUri, $options); | |
| $response = $cli->integrationAdminTokenServiceV1CreateAdminAccessToken([ | |
| 'username' => $username, | |
| 'password' => $password | |
| ]); | |
| $token = $response->result; | |
| // create bearer token Authorization header | |
| $options['stream_context'] = stream_context_create([ | |
| 'http' => [ | |
| 'header' => sprintf('Authorization: Bearer %s', $token) | |
| ] | |
| ]); | |
| // create client and get cms block response | |
| $cli = new SoapClient($soapResourceUri, $options); | |
| $response = $cli->cmsBlockRepositoryV1GetById([ | |
| 'blockId' => '2' | |
| ]); | |
| $block = $response->result; | |
| echo $block; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment