Skip to content

apideck-libraries/sdk-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apideck-libraries/sdk-php

Developer-friendly & type-safe Php SDK specifically catered to leverage apideck-libraries/sdk-php API.



Important

This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.

Summary

Apideck: The Apideck OpenAPI Spec: SDK Optimized

For more information about the API: Apideck Developer Docs

Table of Contents

SDK Installation

The SDK relies on Composer to manage its dependencies.

To install the SDK and add it as a dependency to an existing composer.json file:

composer require "apideck-libraries/sdk-php"

SDK Example Usage

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Apideck\Unify;
use Apideck\Unify\Models\Components;
use Apideck\Unify\Models\Operations;

$security = '<YOUR_BEARER_TOKEN_HERE>';

$sdk = Unify\Apideck::builder()
    ->setConsumerId('test-consumer')
    ->setAppId('dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX')
    ->setSecurity($security)->build();

$request = new Operations\AccountingTaxRatesAllRequest(
    serviceId: 'salesforce',
    filter: new Components\TaxRatesFilter(
        assets: true,
        equity: true,
        expenses: true,
        liabilities: true,
        revenue: true,
    ),
    passThrough: [
        'search' => 'San Francisco',
    ],
    fields: 'id,updated_at',
);

$responses = $sdk->accounting->taxRates->list(
    request: $request
);


foreach ($responses as $response) {
    if ($response->httpMeta->response->getStatusCode() === 200) {
        // handle response
    }
}

Available Resources and Operations

Available methods
  • get - Get Aged Debtors
  • get - Get BalanceSheet
  • create - Create Bill Payment
  • list - List Bill Payments
  • delete - Delete Bill Payment
  • get - Get Bill Payment
  • update - Update Bill Payment
  • get - Get company info
  • create - Create Credit Note
  • list - List Credit Notes
  • delete - Delete Credit Note
  • get - Get Credit Note
  • update - Update Credit Note
  • create - Create Department
  • list - List Departments
  • delete - Delete Department
  • get - Get Department
  • update - Update Department
  • create - Create Invoice Item
  • list - List Invoice Items
  • delete - Delete Invoice Item
  • get - Get Invoice Item
  • update - Update Invoice Item
  • create - Create Journal Entry
  • list - List Journal Entries
  • delete - Delete Journal Entry
  • get - Get Journal Entry
  • update - Update Journal Entry
  • create - Create Ledger Account
  • list - List Ledger Accounts
  • delete - Delete Ledger Account
  • get - Get Ledger Account
  • update - Update Ledger Account
  • get - Get Profit and Loss
  • create - Create Purchase Order
  • list - List Purchase Orders
  • delete - Delete Purchase Order
  • get - Get Purchase Order
  • update - Update Purchase Order
  • create - Create Subsidiary
  • list - List Subsidiaries
  • delete - Delete Subsidiary
  • get - Get Subsidiary
  • update - Update Subsidiary
  • create - Create Tracking Category
  • list - List Tracking Categories
  • delete - Delete Tracking Category
  • get - Get Tracking Category
  • update - Update Tracking Category
  • create - Create Application
  • list - List Applications
  • delete - Delete Application
  • get - Get Application
  • update - Update Application
  • get - Get API Resource Coverage
  • get - Get API Resource
  • get - Get Connector Doc content
  • get - Get Connector Resource
  • list - List Connectors
  • get - Get Connector
  • create - Create opportunity
  • list - List opportunities
  • delete - Delete opportunity
  • get - Get opportunity
  • update - Update opportunity
  • list - List pipelines
  • list - List Customers
  • get - Get Customer
  • list - List Orders
  • get - Get Order
  • list - List Products
  • get - Get Product
  • get - Get Store
  • create - Create DriveGroup
  • list - List DriveGroups
  • delete - Delete DriveGroup
  • get - Get DriveGroup
  • update - Update DriveGroup
  • create - Create Shared Link
  • list - List SharedLinks
  • delete - Delete Shared Link
  • get - Get Shared Link
  • update - Update Shared Link
  • create - Start Upload Session
  • delete - Abort Upload Session
  • finish - Finish Upload Session
  • get - Get Upload Session
  • create - Create Department
  • list - List Departments
  • delete - Delete Department
  • get - Get Department
  • update - Update Department
  • list - List Employee Payrolls
  • get - Get Employee Payroll
  • list - List Employee Schedules
  • list - List Payroll
  • get - Get Payroll
  • create - Create Time Off Request
  • list - List Time Off Requests
  • delete - Delete Time Off Request
  • get - Get Time Off Request
  • update - Update Time Off Request
  • list - List Collections
  • get - Get Collection
  • list - List connection custom mappings
  • list - Get all connections
  • delete - Deletes a connection
  • imports - Import connection
  • get - Get connection
  • token - Authorize Access Token
  • update - Update connection
  • list - Get resource settings
  • update - Update settings
  • list - Consumer request counts
  • state - Create Callback State
  • list - Get resource custom fields
  • list - List custom mappings
  • list - Get all consumer request logs
  • state - Validate Connection State
  • create - Create webhook subscription
  • list - List webhook subscriptions
  • delete - Delete webhook subscription
  • get - Get webhook subscription
  • update - Update webhook subscription

Pagination

Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the returned object will be a Generator instead of an individual response.

Working with generators is as simple as iterating over the responses in a foreach loop, and you can see an example below:

declare(strict_types=1);

require 'vendor/autoload.php';

use Apideck\Unify;
use Apideck\Unify\Models\Components;
use Apideck\Unify\Models\Operations;

$security = '<YOUR_BEARER_TOKEN_HERE>';

$sdk = Unify\Apideck::builder()
    ->setConsumerId('test-consumer')
    ->setAppId('dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX')
    ->setSecurity($security)->build();

$request = new Operations\AccountingTaxRatesAllRequest(
    serviceId: 'salesforce',
    filter: new Components\TaxRatesFilter(
        assets: true,
        equity: true,
        expenses: true,
        liabilities: true,
        revenue: true,
    ),
    passThrough: [
        'search' => 'San Francisco',
    ],
    fields: 'id,updated_at',
);

$responses = $sdk->accounting->taxRates->list(
    request: $request
);


foreach ($responses as $response) {
    if ($response->httpMeta->response->getStatusCode() === 200) {
        // handle response
    }
}

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide an Options object built with a RetryConfig object to the call:

declare(strict_types=1);

require 'vendor/autoload.php';

use Apideck\Unify;
use Apideck\Unify\Models\Components;
use Apideck\Unify\Models\Operations;
use Apideck\Unify\Utils\Retry;

$security = '<YOUR_BEARER_TOKEN_HERE>';

$sdk = Unify\Apideck::builder()
    ->setConsumerId('test-consumer')
    ->setAppId('dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX')
    ->setSecurity($security)->build();

$request = new Operations\AccountingTaxRatesAddRequest(
    taxRate: new Components\TaxRateInput(
        name: 'GST on Purchases',
        passThrough: [
            new Components\PassThroughBody(
                serviceId: '<id>',
                extendPaths: [
                    new Components\ExtendPaths(
                        path: '$.nested.property',
                        value: [
                            'TaxClassificationRef' => [
                                'value' => 'EUC-99990201-V1-00020000',
                            ],
                        ],
                    ),
                ],
            ),
        ],
        customFields: [
            new Components\CustomField(
                id: '2389328923893298',
                name: 'employee_level',
                description: 'Employee Level',
                value: true,
            ),
        ],
        id: '1234',
        code: 'ABN',
        description: 'Reduced rate GST Purchases',
        effectiveTaxRate: 10,
        totalTaxRate: 10,
        taxPayableAccountId: '123456',
        taxRemittedAccountId: '123456',
        components: [
            new Components\Components(
                name: 'GST',
                id: '10',
                rate: 10,
                compound: true,
            ),
        ],
        type: 'NONE',
        reportTaxType: 'NONE',
        originalTaxRateId: '12345',
        status: Components\TaxRateStatus::Active,
        rowVersion: '1-12345',
    ),
    serviceId: 'salesforce',
);

$response = $sdk->accounting->taxRates->create(
    request: $request,
    options: Utils\Options->builder()->setRetryConfig(
        new Retry\RetryConfigBackoff(
            initialInterval: 1,
            maxInterval:     50,
            exponent:        1.1,
            maxElapsedTime:  100,
            retryConnectionErrors: false,
        ))->build()
);

if ($response->createTaxRateResponse !== null) {
    // handle response
}

If you'd like to override the default retry strategy for all operations that support retries, you can pass a RetryConfig object to the SDKBuilder->setRetryConfig function when initializing the SDK:

declare(strict_types=1);

require 'vendor/autoload.php';

use Apideck\Unify;
use Apideck\Unify\Models\Components;
use Apideck\Unify\Models\Operations;
use Apideck\Unify\Utils\Retry;

$security = '<YOUR_BEARER_TOKEN_HERE>';

$sdk = Unify\Apideck::builder()
    ->setRetryConfig(
        new Retry\RetryConfigBackoff(
            initialInterval: 1,
            maxInterval:     50,
            exponent:        1.1,
            maxElapsedTime:  100,
            retryConnectionErrors: false,
        )
  )
    ->setConsumerId('test-consumer')
    ->setAppId('dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX')
    ->setSecurity($security)->build();

$request = new Operations\AccountingTaxRatesAddRequest(
    taxRate: new Components\TaxRateInput(
        name: 'GST on Purchases',
        passThrough: [
            new Components\PassThroughBody(
                serviceId: '<id>',
                extendPaths: [
                    new Components\ExtendPaths(
                        path: '$.nested.property',
                        value: [
                            'TaxClassificationRef' => [
                                'value' => 'EUC-99990201-V1-00020000',
                            ],
                        ],
                    ),
                ],
            ),
        ],
        customFields: [
            new Components\CustomField(
                id: '2389328923893298',
                name: 'employee_level',
                description: 'Employee Level',
                value: true,
            ),
        ],
        id: '1234',
        code: 'ABN',
        description: 'Reduced rate GST Purchases',
        effectiveTaxRate: 10,
        totalTaxRate: 10,
        taxPayableAccountId: '123456',
        taxRemittedAccountId: '123456',
        components: [
            new Components\Components(
                name: 'GST',
                id: '10',
                rate: 10,
                compound: true,
            ),
        ],
        type: 'NONE',
        reportTaxType: 'NONE',
        originalTaxRateId: '12345',
        status: Components\TaxRateStatus::Active,
        rowVersion: '1-12345',
    ),
    serviceId: 'salesforce',
);

$response = $sdk->accounting->taxRates->create(
    request: $request
);

if ($response->createTaxRateResponse !== null) {
    // handle response
}

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default an API error will raise a Errors\APIException exception, which has the following properties:

Property Type Description
$message string The error message
$request ?\Psr\Http\Message\RequestInterface The HTTP request
$response *?\Psr\Http\Message\ResponseInterface * The HTTP response

When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the create method throws the following exceptions:

Error Type Status Code Content Type
Errors\BadRequestResponse 400 application/json
Errors\UnauthorizedResponse 401 application/json
Errors\PaymentRequiredResponse 402 application/json
Errors\NotFoundResponse 404 application/json
Errors\UnprocessableResponse 422 application/json
Errors\APIException 4XX, 5XX */*

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Apideck\Unify;
use Apideck\Unify\Models\Components;
use Apideck\Unify\Models\Operations;

$security = '<YOUR_BEARER_TOKEN_HERE>';

$sdk = Unify\Apideck::builder()
    ->setConsumerId('test-consumer')
    ->setAppId('dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX')
    ->setSecurity($security)->build();

try {
    $request = new Operations\AccountingTaxRatesAddRequest(
        taxRate: new Components\TaxRateInput(
            name: 'GST on Purchases',
            passThrough: [
                new Components\PassThroughBody(
                    serviceId: '<id>',
                    extendPaths: [
                        new Components\ExtendPaths(
                            path: '$.nested.property',
                            value: [
                                'TaxClassificationRef' => [
                                    'value' => 'EUC-99990201-V1-00020000',
                                ],
                            ],
                        ),
                    ],
                ),
            ],
            customFields: [
                new Components\CustomField(
                    id: '2389328923893298',
                    name: 'employee_level',
                    description: 'Employee Level',
                    value: true,
                ),
            ],
            id: '1234',
            code: 'ABN',
            description: 'Reduced rate GST Purchases',
            effectiveTaxRate: 10,
            totalTaxRate: 10,
            taxPayableAccountId: '123456',
            taxRemittedAccountId: '123456',
            components: [
                new Components\Components(
                    name: 'GST',
                    id: '10',
                    rate: 10,
                    compound: true,
                ),
            ],
            type: 'NONE',
            reportTaxType: 'NONE',
            originalTaxRateId: '12345',
            status: Components\TaxRateStatus::Active,
            rowVersion: '1-12345',
        ),
        serviceId: 'salesforce',
    );

    $response = $sdk->accounting->taxRates->create(
        request: $request
    );

    if ($response->createTaxRateResponse !== null) {
        // handle response
    }
} catch (Errors\BadRequestResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\UnauthorizedResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\PaymentRequiredResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\NotFoundResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\UnprocessableResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\APIException $e) {
    // handle default exception
    throw $e;
}

Server Selection

Override Server URL Per-Client

The default server can also be overridden globally using the setServerUrl(string $serverUrl) builder method when initializing the SDK client instance. For example:

declare(strict_types=1);

require 'vendor/autoload.php';

use Apideck\Unify;
use Apideck\Unify\Models\Components;
use Apideck\Unify\Models\Operations;

$security = '<YOUR_BEARER_TOKEN_HERE>';

$sdk = Unify\Apideck::builder()
    ->setServerURL('https://unify.apideck.com')
    ->setConsumerId('test-consumer')
    ->setAppId('dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX')
    ->setSecurity($security)->build();

$request = new Operations\AccountingTaxRatesAddRequest(
    taxRate: new Components\TaxRateInput(
        name: 'GST on Purchases',
        passThrough: [
            new Components\PassThroughBody(
                serviceId: '<id>',
                extendPaths: [
                    new Components\ExtendPaths(
                        path: '$.nested.property',
                        value: [
                            'TaxClassificationRef' => [
                                'value' => 'EUC-99990201-V1-00020000',
                            ],
                        ],
                    ),
                ],
            ),
        ],
        customFields: [
            new Components\CustomField(
                id: '2389328923893298',
                name: 'employee_level',
                description: 'Employee Level',
                value: true,
            ),
        ],
        id: '1234',
        code: 'ABN',
        description: 'Reduced rate GST Purchases',
        effectiveTaxRate: 10,
        totalTaxRate: 10,
        taxPayableAccountId: '123456',
        taxRemittedAccountId: '123456',
        components: [
            new Components\Components(
                name: 'GST',
                id: '10',
                rate: 10,
                compound: true,
            ),
        ],
        type: 'NONE',
        reportTaxType: 'NONE',
        originalTaxRateId: '12345',
        status: Components\TaxRateStatus::Active,
        rowVersion: '1-12345',
    ),
    serviceId: 'salesforce',
);

$response = $sdk->accounting->taxRates->create(
    request: $request
);

if ($response->createTaxRateResponse !== null) {
    // handle response
}

Override Server URL Per-Operation

The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:

declare(strict_types=1);

require 'vendor/autoload.php';

use Apideck\Unify;
use Apideck\Unify\Models\Components;
use Apideck\Unify\Models\Operations;

$security = '<YOUR_BEARER_TOKEN_HERE>';

$sdk = Unify\Apideck::builder()
    ->setConsumerId('test-consumer')
    ->setAppId('dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX')
    ->setSecurity($security)->build();

$request = new Operations\FileStorageUploadSessionsAddRequest(
    createUploadSessionRequest: new Components\CreateUploadSessionRequest(
        name: 'Documents',
        parentFolderId: '1234',
        driveId: '1234',
        size: 1810673,
        passThrough: [
            new Components\PassThroughBody(
                serviceId: '<id>',
                extendPaths: [
                    new Components\ExtendPaths(
                        path: '$.nested.property',
                        value: [
                            'TaxClassificationRef' => [
                                'value' => 'EUC-99990201-V1-00020000',
                            ],
                        ],
                    ),
                ],
            ),
        ],
    ),
    serviceId: 'salesforce',
);

$response = $sdk->fileStorage->uploadSessions->create(
    request: $request,
    'https://upload.apideck.com'
);

if ($response->createUploadSessionResponse !== null) {
    // handle response
}

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

SDK Created by Speakeasy