ynab-sdk-php
ynab-sdk-php copied to clipboard
Result from createTransaction
I'm trying out this awesome package. But I cant tell if the response i get from createTransaction i correct?
When sending a JSON with two or more transactions I get the following response/result.
YNAB\Model\TransactionResponse Object ( [container:protected] => Array ( [data] => YNAB\Model\TransactionWrapper Object ( [container:protected] => Array ( [transaction] => ) ) ) )
Is it YNAB API, ynab-sdk-php or my code that is incorrect?
I should point out that the transactions do get written to YNAB and appears in the intended budget.
Hi!
Honestly, I'm not sure. The SDK is generated from the swagger specs they provided. If you're not sure, you could try to reconstruct the request using basic REST API functions: https://api.youneedabudget.com/
You then could try and see if there's a difference in response. If it turns out there's an issue with the code I'll be happy to fix it for you.
Jorijn
Hi! Running the the same JSON threw the REST API web page I do get a correct response. Strange? Anders
OK, that's weird. I'll see if I can free some time to have a look. I expect this to be within about a week.
Done som more testing using both createTransaction and bulkCreateTransactions. With createTransaction passing both single and multiple transactions for creation.
To be able to rule out any issue with my setup I have tried the example code below. You can see the different results also.
Also, looking at the documentation (https://api.youneedabudget.com/v1#/Deprecated) bulkCreateTransactions seems to be deprecated.
createTransaction_single.php
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: bearer
$config = YNAB\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'XXXX');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
$config = YNAB\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');
$apiInstance = new YNAB\Client\TransactionsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$budgetId = "XXXX"; // string | The ID of the Budget. \"last-used\" can also be used to specify the last used budget.
$transaction = new \YNAB\Model\SaveTransactionWrapper(); // \YNAB\Model\SaveTransactionWrapper | The Transaction to create.
$transaction = "{\"transaction\":{\"account_id\":\"22b542b2-02eb-4f52-8dde-0cd061f54a93\",\"date\":\"2019-02-15\",\"amount\":999000,\"payee_name\":\"ora\",\"import_id\":\"TEST02:999000:2019-02-15:1\",\"flag_color\":\"orange\",\"cleared\":\"cleared\"}}";
try {
$result = $apiInstance->createTransaction($budgetId, $transaction);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TransactionsApi->createTransaction: ', $e->getMessage(), PHP_EOL;
}
?>
Result
YNAB\Model\TransactionResponse Object ( [container:protected] => Array ( [data] => YNAB\Model\TransactionWrapper Object ( [container:protected] => Array ( [transaction] => YNAB\Model\TransactionDetail Object ( [container:protected] => Array ( [id] => 00ea3df3-89d2-4105-b939-caf656754619 [date] => DateTime Object ( [date] => 2019-02-15 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [amount] => 999000 [cleared] => cleared [approved] => [accountId] => 22b542b2-02eb-4f52-8dde-0cd061f54a93 [accountName] => My Account [subtransactions] => Array ( ) ) ) ) ) ) )
createTransaction_multi.php
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: bearer
$config = YNAB\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'XXXXX');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
$config = YNAB\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');
$apiInstance = new YNAB\Client\TransactionsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$budgetId = "XXXXX"; // string | The ID of the Budget. \"last-used\" can also be used to specify the last used budget.
$transaction = new \YNAB\Model\SaveTransactionWrapper(); // \YNAB\Model\SaveTransactionWrapper | The Transaction to create.
$transactions = "{\"transactions\":[{\"account_id\":\"22b542b2-02eb-4f52-8dde-0cd061f54a93\",\"date\":\"2019-02-15\",\"amount\":999000,\"payee_name\":\"ora\",\"import_id\":\"TEST04:999000:2019-02-15:1\",\"flag_color\":\"orange\",\"cleared\":\"cleared\"},{\"account_id\":\"22b542b2-02eb-4f52-8dde-0cd061f54a93\",\"date\":\"2019-02-14\",\"amount\":-500000,\"payee_name\":\"YBB YSTAD BILBES\",\"import_id\":\"TEST04:-500000:2019-02-14:1\",\"flag_color\":\"orange\",\"cleared\":\"cleared\"}]}";
try {
$result = $apiInstance->createTransaction($budgetId, $transactions);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TransactionsApi->createTransaction: ', $e->getMessage(), PHP_EOL;
}
?>
Result
YNAB\Model\TransactionResponse Object ( [container:protected] => Array ( [data] => YNAB\Model\TransactionWrapper Object ( [container:protected] => Array ( [transaction] => ) ) ) )
bulkCreateTransactions.php
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: bearer
$config = YNAB\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'xxxx');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
$config = YNAB\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');
$apiInstance = new YNAB\Client\TransactionsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$budgetId = "xxxxxx"; // string | The ID of the Budget. \"last-used\" can also be used to specify the last used budget.
$transactions = new \YNAB\Model\BulkTransactions(); // \YNAB\Model\BulkTransactions | The list of Transactions to create.
$transactions = "{\"transactions\":[{\"account_id\":\"22b542b2-02eb-4f52-8dde-0cd061f54a93\",\"date\":\"2019-02-15\",\"amount\":999000,\"payee_name\":\"ora\",\"import_id\":\"TEST01:999000:2019-02-15:1\",\"flag_color\":\"orange\",\"cleared\":\"cleared\"},{\"account_id\":\"22b542b2-02eb-4f52-8dde-0cd061f54a93\",\"date\":\"2019-02-14\",\"amount\":-500000,\"payee_name\":\"YBB YSTAD BILBES\",\"import_id\":\"TEST01:-500000:2019-02-14:1\",\"flag_color\":\"orange\",\"cleared\":\"cleared\"}]}";
try {
$result = $apiInstance->bulkCreateTransactions($budgetId, $transactions);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TransactionsApi->bulkCreateTransactions: ', $e->getMessage(), PHP_EOL;
}
?>
Result
YNAB\Model\BulkResponse Object ( [container:protected] => Array ( [data] => YNAB\Model\BulkIdWrapper Object ( [container:protected] => Array ( [bulk] => YNAB\Model\BulkIds Object ( [container:protected] => Array ( [transactionIds] => Array ( [0] => aae4b17b-89f0-4c17-b8e9-b366c46f4a5c [1] => f94c78b6-d4d7-4b34-a543-5d80c59edad1 ) [duplicateImportIds] => Array ( ) ) ) ) ) ) )