June 04, 2020


Thinking Magento

DPD API Login Using Zend Framework

Now I'm posting this because I don't want someone else to go through the same hardship as I did when it came getting the geosession from the DPD api. It may look easy enough, but if you've not had a whole lot of experience with using Zend_Http_Client (POST) it may be a bit of a nightmare taking that initial first step. Once you have the geosession, you can start using more POST and GET calls to get the information that you require.

$method = '/user/?action=login';
$url = $base.$method;
$client = new Zend_Http_Client($url);
$client->setHeaders('Host', 'api.dpd.co.uk');
$client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'application/json');
$client->setHeaders('Accept', 'application/json');
$client->setHeaders('Authorization', 'Basic '. base64_encode('username:password'));
$client->setHeaders('GEOClient', 'account name/account number');
$client->setHeaders('Content-Length', '0');
$response = $client->request();
$body = Zend_Json::decode($response->getBody());
$geoSession = $body['data']['geoSession'];