PHP code example of jpry / ynab-sdk-php

1. Go to this page and download the library: Download jpry/ynab-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jpry / ynab-sdk-php example snippets


use JPry\YNAB\Client\YnabClient;
use JPry\YNAB\Config\ClientConfig;

$config = new ClientConfig(
    baseUrl: 'https://api.ynab.com/v1',
    timeoutSeconds: 30,
    maxRetries: 2,
);

$client = YnabClient::withApiKey('your-api-key', config: $config);
$user = $client->user();
$plans = $client->plans();
$settings = $client->planSettings('plan-id');
$months = $client->months('plan-id');
$moneyMovements = $client->moneyMovements('plan-id');
$scheduled = $client->scheduledTransactions('plan-id');
$payeeLocations = $client->payeeLocations('plan-id');
$category = $client->category('plan-id', 'category-id');
$monthCategory = $client->monthCategory('plan-id', '2026-03-01', 'category-id');
$transactions = $client->transactions('plan-id', ['since_date' => '2026-01-01']);

use JPry\YNAB\Model\Mutation\CreateTransactionsRequest;
use JPry\YNAB\Model\Mutation\TransactionPayload;
use JPry\YNAB\Model\Mutation\UpdateTransactionRequest;

$client->createTransactions(
    'plan-id',
    CreateTransactionsRequest::single(
        new TransactionPayload(accountId: 'account-id', amount: -1000)
    ),
);

$client->updateTransaction(
    'plan-id',
    new UpdateTransactionRequest('transaction-id', new TransactionPayload(memo: 'Updated memo')),
);

use JPry\YNAB\Client\YnabClient;
use JPry\YNAB\Config\ClientConfig;

$config = new ClientConfig();
$client = YnabClient::withOAuthToken(
    accessToken: 'access-token',
    refreshAccessToken: fn (): string => 'new-access-token',
    config: $config,
);

use JPry\YNAB\Http\GuzzleRequestSender;
use JPry\YNAB\OAuth\OAuthClient;
use JPry\YNAB\OAuth\OAuthConfig;
use JPry\YNAB\Config\ClientConfig;

$oauth = new OAuthClient(
    new OAuthConfig(
        clientId: 'client-id',
        clientSecret: 'client-secret',
        redirectUri: 'https://example.com/oauth/callback',
    ),
    new GuzzleRequestSender(new ClientConfig()),
);

$authUrl = $oauth->authorizationUrl('state-value');
$tokens = $oauth->exchangeCodeForTokens('code-from-callback');

use JPry\YNAB\Http\RequestSender;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Psr7\Response;

final class MySender implements RequestSender
{
    public function sendRequest(RequestInterface $request): ResponseInterface
    {
        // Bridge to your own HTTP library
        return new Response(200, [], '{"data":{}}');
    }
}

$client = YnabClient::withApiKey('api-key', requestSender: new MySender());
bash
composer