Skip to content

midday-ai/midday-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Midday PHP SDK to interact with APIs.

Midday PHP SDK


Learn more about the Midday PHP SDK in the official documentation.

Summary

Midday is a platform for Invoicing, Time tracking, File reconciliation, Storage, Financial Overview & your own Assistant.

Table of Contents

SDK Installation

Tip

To finish publishing your SDK you must run your first generation action.

The SDK relies on Composer to manage its dependencies.

To install the SDK first add the below to your composer.json file:

{
    "repositories": [
        {
            "type": "github",
            "url": "<UNSET>.git"
        }
    ],
    "require": {
        "midday/midday-php": "*"
    }
}

Then run the following command:

composer update

SDK Example Usage

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Midday\Midday;
use Midday\Midday\Models\Operations;

$sdk = Midday\Midday::builder()
    ->setSecurity(
        'MIDDAY_API_KEY'
    )
    ->build();

$request = new Operations\ListTransactionsRequest(
    cursor: 'eyJpZCI6IjEyMyJ9',
    sort: [
        'date',
        'desc',
    ],
    pageSize: 50,
    q: 'office supplies',
    categories: [
        'office-supplies',
        'travel',
    ],
    tags: [
        'tag-1',
        'tag-2',
    ],
    start: '2024-04-01T00:00:00.000Z',
    end: '2024-04-30T23:59:59.999Z',
    accounts: [
        'account-1',
        'account-2',
    ],
    assignees: [
        'user-1',
        'user-2',
    ],
    statuses: [
        'pending',
        'completed',
    ],
    recurring: [
        'monthly',
        'annually',
    ],
    attachments: Operations\Attachments::Include,
    amountRange: [
        100,
        1000,
    ],
    amount: [
        '150.75',
        '299.99',
    ],
    type: Operations\ListTransactionsType::Expense,
);

$response = $sdk->transactions->list(
    request: $request
);

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

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
token http HTTP Bearer

To authenticate with the API the token parameter must be set when initializing the SDK. For example:

declare(strict_types=1);

require 'vendor/autoload.php';

use Midday\Midday;
use Midday\Midday\Models\Operations;

$sdk = Midday\Midday::builder()
    ->setSecurity(
        'MIDDAY_API_KEY'
    )
    ->build();

$request = new Operations\ListTransactionsRequest(
    cursor: 'eyJpZCI6IjEyMyJ9',
    sort: [
        'date',
        'desc',
    ],
    pageSize: 50,
    q: 'office supplies',
    categories: [
        'office-supplies',
        'travel',
    ],
    tags: [
        'tag-1',
        'tag-2',
    ],
    start: '2024-04-01T00:00:00.000Z',
    end: '2024-04-30T23:59:59.999Z',
    accounts: [
        'account-1',
        'account-2',
    ],
    assignees: [
        'user-1',
        'user-2',
    ],
    statuses: [
        'pending',
        'completed',
    ],
    recurring: [
        'monthly',
        'annually',
    ],
    attachments: Operations\Attachments::Include,
    amountRange: [
        100,
        1000,
    ],
    amount: [
        '150.75',
        '299.99',
    ],
    type: Operations\ListTransactionsType::Expense,
);

$response = $sdk->transactions->list(
    request: $request
);

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

Available Resources and Operations

Available methods
  • list - List all bank accounts
  • create - Create a bank account
  • get - Retrieve a bank account
  • delete - Delete a bank account
  • update - Update a bank account
  • list - List all customers
  • create - Create customer
  • get - Retrieve a customer
  • delete - Delete a customer
  • update - Update a customer
  • list - List all documents
  • get - Retrieve a document
  • delete - Delete a document
  • list - List all inbox items
  • get - Retrieve a inbox item
  • delete - Delete a inbox item
  • update - Update a inbox item
  • list - List all teams
  • get - Retrieve a team
  • update - Update a team
  • members - List all team members
  • delete - Delete a tracker entry
  • list - List all tracker entries
  • list - List all tracker projects
  • create - Create a tracker project
  • get - Retrieve a tracker project
  • delete - Delete a tracker project
  • update - Update a tracker project
  • get - Retrieve the current user
  • update - Update the current user

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
$statusCode int The HTTP status code
$rawResponse ?\Psr\Http\Message\ResponseInterface The raw HTTP response
$body string The response content

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 list method throws the following exceptions:

Error Type Status Code Content Type
Errors\APIException 4XX, 5XX */*

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Midday\Midday;
use Midday\Midday\Models\Operations;

$sdk = Midday\Midday::builder()
    ->setSecurity(
        'MIDDAY_API_KEY'
    )
    ->build();

try {
    $request = new Operations\ListTransactionsRequest(
        cursor: 'eyJpZCI6IjEyMyJ9',
        sort: [
            'date',
            'desc',
        ],
        pageSize: 50,
        q: 'office supplies',
        categories: [
            'office-supplies',
            'travel',
        ],
        tags: [
            'tag-1',
            'tag-2',
        ],
        start: '2024-04-01T00:00:00.000Z',
        end: '2024-04-30T23:59:59.999Z',
        accounts: [
            'account-1',
            'account-2',
        ],
        assignees: [
            'user-1',
            'user-2',
        ],
        statuses: [
            'pending',
            'completed',
        ],
        recurring: [
            'monthly',
            'annually',
        ],
        attachments: Operations\Attachments::Include,
        amountRange: [
            100,
            1000,
        ],
        amount: [
            '150.75',
            '299.99',
        ],
        type: Operations\ListTransactionsType::Expense,
    );

    $response = $sdk->transactions->list(
        request: $request
    );

    if ($response->object !== null) {
        // handle response
    }
} catch (Errors\APIException $e) {
    // handle default exception
    throw $e;
}

Server Selection

Override Server URL Per-Client

The default server can 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 Midday\Midday;
use Midday\Midday\Models\Operations;

$sdk = Midday\Midday::builder()
    ->setServerURL('https://api.midday.ai')
    ->setSecurity(
        'MIDDAY_API_KEY'
    )
    ->build();

$request = new Operations\ListTransactionsRequest(
    cursor: 'eyJpZCI6IjEyMyJ9',
    sort: [
        'date',
        'desc',
    ],
    pageSize: 50,
    q: 'office supplies',
    categories: [
        'office-supplies',
        'travel',
    ],
    tags: [
        'tag-1',
        'tag-2',
    ],
    start: '2024-04-01T00:00:00.000Z',
    end: '2024-04-30T23:59:59.999Z',
    accounts: [
        'account-1',
        'account-2',
    ],
    assignees: [
        'user-1',
        'user-2',
    ],
    statuses: [
        'pending',
        'completed',
    ],
    recurring: [
        'monthly',
        'annually',
    ],
    attachments: Operations\Attachments::Include,
    amountRange: [
        100,
        1000,
    ],
    amount: [
        '150.75',
        '299.99',
    ],
    type: Operations\ListTransactionsType::Expense,
);

$response = $sdk->transactions->list(
    request: $request
);

if ($response->object !== 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

About

Official Midday PHP SDK

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages