SDK Migration Guide for PHP
This comprehensive guide helps you transition from the previous PHP SDK to the new PHP SDK.
Key Changes
- Package Name and Installation
# Old package
composer require apideck-libraries/php-sdk
# New package
composer require apideck-libraries/sdk-php
- SDK Initialization
// Old SDK
use Apideck\Client\Apideck;
use Apideck\Client\ApideckConfiguration;
$config = new ApideckConfiguration('<api-key>', '<application-id>', '<consumer-id>');
$apideck = new Apideck($config);
// New SDK
use Apideck\Unify;
$sdk = Unify\Apideck::builder()
->setConsumerId('test-consumer')
->setAppId('your-app-id')
->setSecurity('your-api-key')
->build();
- Method Naming Changes
// Old SDK
$crmApi = $apideck->getCrmApi();
$response = $crmApi->contactsAll(false, null, null, $serviceId, null, 10);
// New SDK
$response = $sdk->crm->contacts->list(
new Operations\CrmContactsAllRequest(
serviceId: 'salesforce',
filter: new Components\ContactsFilter(
firstName: 'John',
lastName: 'Doe'
)
)
);
- Response Structure
// Old SDK
$response = $crmApi->contactsAll();
$data = $response->getData();
// New SDK
$responses = $sdk->crm->contacts->list(
request: $request
);
foreach ($responses as $response) {
if ($response->httpMeta->response->getStatusCode() === 200) {
// handle response
// $response.getContactsResponse...s
}
}
- Method Naming Convention Changes
Old Method | New Method |
---|---|
contactsAll | contacts->list |
contactsAdd | contacts->create |
contactsOne | contacts->get |
contactsUpdate | contacts->update |
contactsDelete | contacts->delete |
...
- Error Handling
// Old SDK
try {
$response = $crmApi->contactsAll();
} catch (\Exception $e) {
echo $e->getMessage();
}
// New SDK
try {
$response = $sdk->crm->contacts->list($request);
} catch (Errors\BadRequestResponse $e) {
// handle $e->$container data
} catch (Errors\UnauthorizedResponse $e) {
// handle $e->$container data
} catch (Errors\APIException $e) {
// handle default exception
}
For more details on error handling, please refer to the Error Handling Documentation.
Breaking Changes
- Package name has changed from
apideck-libraries/php-sdk
toapideck-libraries/sdk-php
- Configuration and initialization process has been completely revamped
- All API method names have been restructured for consistency and better organization
- Response structure now includes typed response wrappers
- Error handling has been improved with specific error types
- Method calls now require structured request objects
Need help?
If you encounter any issues during migration:
- Checkout out our documentation
- Open an issue on our GitHub repository
- Contact our support at
support@apideck.com