Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No response from request->send() when no content is returned from xero #868

Open
arunmanivel opened this issue Aug 28, 2022 · 2 comments
Open

Comments

@arunmanivel
Copy link

arunmanivel commented Aug 28, 2022

I am using BankStatement API to sync bank statements from Xero for a given account ID. It works fine except when there is no content returned from Xero. Please see below my code. The program dies after $request->send().

function xero_get_bank_statements($fromDate,$toDate,$accountID)
{
$url = new URL($xero, 'Reports/BankStatement');
$request = new Request($xero, $url, Request::METHOD_GET);
$request->setParameter('bankAccountID', $accountID);
$request->setParameter('fromDate', $fromDate);
$request->setParameter('toDate', $toDate);
$request->send();
$elements = $request->getResponse()->getElements();
return $elements;
}

I troubleshooted the issue and noticed that send() function first sends data to xero and then creates a response object using $guzzleResponse->getBody()->getContents(). For me, there is nothing returned from Xero. I am guessing there is no statements for that account ID, but I am not sure.

After creating response object, parse() function is called to parse the response. This is where the execution stops. There is no return value or response. I guess parse is failing as there is no content. There is no check for response from xero in parse function. I think we should not allow parsing if there is no content returned from Xero.

@calcinai
Copy link
Owner

Hi @arunmanivel is there a reason you're manually constructing this request rather than using the query builder (like in the readme?)

$xero->load(BankStatement::class)
    ->where('bankAccountID', $accountID)
    ->where('fromDate', $fromDate)
    ->where('toDate', $toDate)
    ->execute();

As far as I know, the above souls work for reports, too.

@arunmanivel
Copy link
Author

arunmanivel commented Aug 29, 2022

@calcinai No specific reason. The code was written few years back by another developer. I have just inherited it. Thanks for pointing it out though. We will start using it for upcoming features. But will that solve the problem that I reported?
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants