$webserviceURL, ]); $response = $client->post('v2.php', [ 'form_params' => [ 'action' => 'authenticate', 'username' => $webserviceUsername, 'password' => $webservicePassword, ], ]); if ($response->getStatusCode() !== 200) { throw new Exception('Entry denied with code : '.$response->getStatusCode()); } $jsonResponse = json_decode($response->getBody()->getContents()); if ($jsonResponse->error) { throw new Exception('Authentication failed because : '.$jsonResponse->message); } return $jsonResponse->data->apiKey; } $apiKey = authenticate(); echo 'user API Key: '.$apiKey;