composer require wunder/memsource-php
See http://wiki.memsource.com/wiki/Memsource_API for API documentation.
Background information from the Memsource documentation:
Before calling any API that requires an authenticated user, you have to call auth/login API to obtain an authentication token. Such a token is valid for 24 hours and can be used for all subsequent calls (please, do not acquire a new token for every call).
http://wiki.memsource.com/wiki/Memsource_API#Authentication
Provide a user name and a password to Memsource
constructor. An
authentication attempt is done automatically. On success, a new Memsource
instance is returned. An exception is thrown on failure. The response content
is included in the exception message.
use Memsource\Memsource;
try {
$memsource = new Memsource('username', 'password');
} catch (Exception $e) {
echo $e->getMessage();
}
After successful authentication the token can be retrieved by calling
getToken()
. The token is valid for 24 hours and new one should be acquired
only after the current one is not valid anymore. Store the token somewhere safe
and use it when constructing a new Memsource
instance to avoid unnecessary
authentication calls.
use Memsource\Memsource;
$token = get_token_from_your_token_storage();
if (isset($token)) {
$memsource = new Memsource(NULL, NULL, $token);
}
After successfully constructing a new Memsource
instance, one can call
functions on it. All functions return an instance of
Symfony\Component\HttpFoundation\JsonResponse
.
/** @var $response Symfony\Component\HttpFoundation\JsonResponse */
$json_response = $memsource->whoAmI();
$response_content = $response->getContent();
echo $response_content;