Our PHP client library is free to use in any project, commercial or otherwise.
Install via Composer:
1 |
composer require mplus-software/mplus-api-client-php |
Or: Download the latest release here
Example of usage:
The following script will connect to the API with your credentials and try to request the currently running version of the API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php // Include the PHP Mplus API Client library require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); $mplusqapiclient->setApiServer($your_api_url); $mplusqapiclient->setApiPort($your_api_port); $mplusqapiclient->setApiIdent($your_api_ident); $mplusqapiclient->setApiSecret($your_api_secret); try { $mplusqapiclient->initClient(); } catch (MplusQAPIException $e) { exit($e->getMessage()); } try { $api_version = $mplusqapiclient->getApiVersion(); echo sprintf('Current API version: %d.%d.%d', $api_version['majorNumber'], $api_version['minorNumber'], $api_version['revisionNumber']); } catch (MplusQAPIException $e) { exit($e->getMessage()); } |
This should output:
Current API version: 1.0.0
In case you used an invalid ident or secret:
1 |
SoapFault occurred: Credentials not accepted! |
Check to make sure you supplied the proper values in your calls to setApiIdent en setApiSecret.
In case the API can’t be reached, or the URL is invalid:
1 |
SoapFault occurred: Not Found |
or:
1 |
Warning: stream_socket_client(): unable to connect to ... |
or:
1 |
Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known ... |
Generating XML formatted requests and responses in the PHP client
First enable the debugger by adding the following line at the top of your code.
1 |
$this->mplusqapiclient->setDebug(true); |
Now you can use the following line to get XML formatted request
1 |
$mplusqapiclient->getLastRequest(); |
And:
1 |
$mplusqapiclient->getLastResponse(); |
to generate the XML formatted response.
Both the request and the response can be generated in the same code block.