# Bank transaction POST not working

**URL:** <https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369>\
**Category:** Uncategorized\
**Created:** [25 February 2014 10:02 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369 "2014-02-25T10:02:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iain\_W](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/i/e274bd/32.png) [@Iain\_W](https://api-discuss.freeagent.com/u/Iain_W)\
**Post date:** [25 February 2014 10:02 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/1 "2014-02-25T10:02:06Z")

</div>

I’m trying to add a bank transaction through the API but have hit a  
problem.

I’m using PHP Oauth2. I have no problem connecting and collecting  
invoices, but when I try to create a bank transaction the response array  
is as follows:

array(3) { [“result”]=\> array(1) { [“errors”]=\> array(1) {  
[“error”]=\> array(1) { [“message”]=\> string(41) “bank\_transaction or  
bank\_account required” } } } [“code”]=\> int(400) [“content\_type”]=\>  
string(31) “application/json; charset=utf-8” }

My code to add the bank transaction is

$postarray=array(“bank\_account” =\>  
“[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”, “paid\_invoice” =\>  
$invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\> $gross );

$updresp =  
$client-\>fetch(‘[https://api.freeagent.com/v2/bank\_transaction\_explanations](https://api.freeagent.com/v2/bank_transaction_explanations)’,  
$postarray,  
‘POST’,  
array(‘Authorization’ =\> 'Bearer '. $access,‘User-Agent’ =\>  
‘My UA’)  
);

It seems to me that the POST parameters are not being recognized. I’m  
able to do a POST transaction to get the company details, but that has no  
parameters.

Appreciate if you can help.

---

<div class="post-metadata">

**Author:** ![Iain\_W](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/i/e274bd/32.png) [@Iain\_W](https://api-discuss.freeagent.com/u/Iain_W)\
**Post date:** [25 February 2014 14:33 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/2 "2014-02-25T14:33:40Z")

</div>

Yep, already tried that

$postarray=json\_encode(array(“bank\_transaction\_explanation” =\>  
array(“bank\_account” =\> “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”,  
“paid\_invoice” =\> $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\>  
$gross )));

Which gives :

string(257)  
“{“bank\_transaction\_explanation”:”{"bank\_account":"https:\/\/api.freeagent.com\/v2\/bank\_account\/147047","paid\_invoice":"https:\/\/api.freeagent.com\/v2\/invoices\/4924409","dated\_on":"2012-09-08","gross\_value":"12.00"}“}”

Then I get the following error:

Fatal error: Uncaught exception ‘OAuth2\InvalidArgumentException’ with  
message ‘You need to give parameters as array if you want to give the token  
within the URI.’

IainOn Tuesday, 25 February 2014 14:19:47 UTC, Jonathan Barrett wrote:

> Hi Iain,
> 
> The correct JSON for what you’re trying to do is:
> 
> { “bank\_account\_explanation”: {“bank\_account”: … } }
> 
> From reading your code, it looks like what you want is probably along the  
> lines of:
> 
> json\_encode(array(“bank\_account\_explanation” =\> array(“bank\_account” =\>  
> …)));
> 
> I.e. JSON-encoding the whole nested array. Can you try that and let me  
> know how you get on?
> 
> -J

---

<div class="post-metadata">

**Author:** ![Iain\_W](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/i/e274bd/32.png) [@Iain\_W](https://api-discuss.freeagent.com/u/Iain_W)\
**Post date:** [26 February 2014 11:04 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/3 "2014-02-26T11:04:52Z")

</div>

Done some more testing and the problem exists on any POST transaction where  
I actually try and post something. Everything else works fine. So I can  
do a company enquiry (which is a POST transaction without any POST  
parameters) and it will work, but any other transaction where I have POST  
parameters doesn’t work.

Any further suggestions?  
IainOn Tuesday, 25 February 2014 10:02:06 UTC, Iain W wrote:

> I’m trying to add a bank transaction through the API but have hit a  
> problem.
> 
> I’m using PHP Oauth2. I have no problem connecting and collecting  
> invoices, but when I try to create a bank transaction the response array  
> is as follows:
> 
> array(3) { [“result”]=\> array(1) { [“errors”]=\> array(1) {  
> [“error”]=\> array(1) { [“message”]=\> string(41) “bank\_transaction or  
> bank\_account required” } } } [“code”]=\> int(400) [“content\_type”]=\>  
> string(31) “application/json; charset=utf-8” }
> 
> My code to add the bank transaction is
> 
> $postarray=array(“bank\_account” =\>  
> “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”, “paid\_invoice” =\>  
> $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\> $gross );
> 
> $updresp =  
> $client-\>fetch(’  
> [https://api.freeagent.com/v2/bank\_transaction\_explanations](https://api.freeagent.com/v2/bank_transaction_explanations)’,  
> $postarray,  
> ‘POST’,  
> array(‘Authorization’ =\> 'Bearer '. $access,‘User-Agent’ =\>  
> ‘My UA’)  
> );
> 
> It seems to me that the POST parameters are not being recognized. I’m  
> able to do a POST transaction to get the company details, but that has no  
> parameters.
> 
> Appreciate if you can help.

---

<div class="post-metadata">

**Author:** ![Iain\_W](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/i/e274bd/32.png) [@Iain\_W](https://api-discuss.freeagent.com/u/Iain_W)\
**Post date:** [26 February 2014 16:59 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/4 "2014-02-26T16:59:50Z")

</div>

Finally nailed it. You were right - the library has been updated since I  
got it and it handles the POST of JSON properly now, which made the  
authentication process a little different too.

The library doesn’t appear to have any way I can get hold of the response  
headers to look at the pagination details, which is a pain

Is there an Oauth library that the majority of your users use? And that  
has access to the pagination in the Link headers?

Thanks  
IainOn Wednesday, 26 February 2014 11:23:43 UTC, Jonathan Barrett wrote:

> Hi Iain,
> 
> Thanks for getting back to me with what you’ve tried so far. Where you’re  
> getting server errors, those are what I’d expect: looking at the logs, the  
> JSON we’re getting isn’t nested. It also appears to be slurping in an  
> access\_token field: not sure where that’s coming from?
> 
> Where you’re getting PHP errors, this is going to be an issue with the  
> library. Looking at the library’s repo, it looks like there was a change  
> made recently that might address the issue you’re seeing:
> 
> [Support for non-array POST parameters added. · athlan/oauth2@15f0cf2 · GitHub](https://github.com/athlan/oauth2/commit/15f0cf2280e94983b4f43cdafba8d930bd1bc39a)
> 
> Can I double check that you’re using the latest version of the library?
> 
> Cheers,
> 
> -J
> 
> PS for retrieving information from the API, you should be using GET  
> requests, not POSTs. We have a quick breakdown of what verbs should be used  
> when in the API docs [https://dev.freeagent.com/docs/introduction](https://dev.freeagent.com/docs/introduction).
> 
> On Wed, Feb 26, 2014 at 11:04 AM, Iain W \<[iain...@googlemail.com](mailto:iain...@googlemail.com)\<javascript:\> wrote:
> 
> > Done some more testing and the problem exists on any POST transaction  
> > where I actually try and post something. Everything else works fine. So I  
> > can do a company enquiry (which is a POST transaction without any POST  
> > parameters) and it will work, but any other transaction where I have POST  
> > parameters doesn’t work.
> > 
> > Any further suggestions?  
> > Iain
> > 
> > On Tuesday, 25 February 2014 10:02:06 UTC, Iain W wrote:
> > 
> > > I’m trying to add a bank transaction through the API but have hit a  
> > > problem.
> > > 
> > > I’m using PHP Oauth2. I have no problem connecting and collecting  
> > > invoices, but when I try to create a bank transaction the response array  
> > > is as follows:
> > > 
> > > array(3) { [“result”]=\> array(1) { [“errors”]=\> array(1) {  
> > > [“error”]=\> array(1) { [“message”]=\> string(41) “bank\_transaction or  
> > > bank\_account required” } } } [“code”]=\> int(400) [“content\_type”]=\>  
> > > string(31) “application/json; charset=utf-8” }
> > > 
> > > My code to add the bank transaction is
> > > 
> > > $postarray=array(“bank\_account” =\>  
> > > “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”, “paid\_invoice” =\>  
> > > $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\> $gross );
> > > 
> > > $updresp =  
> > > $client-\>fetch(‘[https://api.freeagent.com/v2/bank\_](https://api.freeagent.com/v2/bank_)  
> > > transaction\_explanations’,  
> > > $postarray,  
> > > ‘POST’,  
> > > array(‘Authorization’ =\> 'Bearer '. $access,‘User-Agent’ =\>  
> > > ‘My UA’)  
> > > );
> > > 
> > > It seems to me that the POST parameters are not being recognized. I’m  
> > > able to do a POST transaction to get the company details, but that has no  
> > > parameters.
> > > 
> > > Appreciate if you can help.
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “FreeAgent API” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [freeagent\_ap...@googlegroups.com](mailto:freeagent_ap...@googlegroups.com) \<javascript:\>.  
> > To post to this group, send email to [freeag...@googlegroups.com](mailto:freeag...@googlegroups.com)\<javascript:\>  
> > .  
> > Visit this group at [http://groups.google.com/group/freeagent\_api](http://groups.google.com/group/freeagent_api).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> –
> 
> Jonathan Barrett, Senior Engineer
> 
> FreeAgent: Accounting software, simplified  
> [www.freeagent.com](http://www.freeagent.com)
> 
> +44 (0)131 447 0011
> 
> Follow us on Twitter: @freeagent [https://twitter.com/freeagent](https://twitter.com/freeagent)
> 
> FreeAgent Central Ltd, 40 Torphichen Street, Edinburgh EH3 8JB  
> Registered in Scotland SC316774

---

<div class="post-metadata">

**Author:** ![Jonathan\_Barrett](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/jonathan_barrett/32/150_2.png) [@Jonathan\_Barrett](https://api-discuss.freeagent.com/u/Jonathan_Barrett)\
**Post date:** [25 February 2014 15:05 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/5 "2014-02-25T15:05:02Z")

</div>

Hi Iain,

Thanks for that. I’m at a bit of a loss here, as I’m not familiar with the  
php OAuth library. To my reading, the library requires an array of params,  
but when handed a multidimensional array, it complains that it’s not an  
array? To confirm, the following fails with a “you need to give parameters  
as an array…” error, yes?

$postarray = array(“bank\_transaction\_explanation” =\> array(“bank\_account”  
=\> … ) );

-JOn Tue, Feb 25, 2014 at 2:33 PM, Iain W [iain.blot@googlemail.com](mailto:iain.blot@googlemail.com) wrote:

> Yep, already tried that
> 
> $postarray=json\_encode(array(“bank\_transaction\_explanation” =\>  
> array(“bank\_account” =\> “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”,  
> “paid\_invoice” =\> $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\>  
> $gross )));
> 
> Which gives :
> 
> string(257)  
> “{“bank\_transaction\_explanation”:”{"bank\_account":"https:\/\/  
> [api.freeagent.com](http://api.freeagent.com)  
> \/v2\/bank\_account\/147047","paid\_invoice":"https:\/\/  
> [api.freeagent.com](http://api.freeagent.com)  
> \/v2\/invoices\/4924409","dated\_on":"2012-09-08","gross\_value":"12.00"}“}”
> 
> Then I get the following error:
> 
> Fatal error: Uncaught exception ‘OAuth2\InvalidArgumentException’ with  
> message ‘You need to give parameters as array if you want to give the token  
> within the URI.’
> 
> Iain
> 
> On Tuesday, 25 February 2014 14:19:47 UTC, Jonathan Barrett wrote:
> 
> > Hi Iain,
> > 
> > The correct JSON for what you’re trying to do is:
> > 
> > { “bank\_account\_explanation”: {“bank\_account”: … } }
> > 
> > From reading your code, it looks like what you want is probably along the  
> > lines of:
> > 
> > json\_encode(array(“bank\_account\_explanation” =\> array(“bank\_account” =\>  
> > …)));
> > 
> > I.e. JSON-encoding the whole nested array. Can you try that and let me  
> > know how you get on?
> > 
> > -J
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “FreeAgent API” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [freeagent\_api+unsubscribe@googlegroups.com](mailto:freeagent_api+unsubscribe@googlegroups.com).  
> To post to this group, send email to [freeagent\_api@googlegroups.com](mailto:freeagent_api@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/freeagent\_api](http://groups.google.com/group/freeagent_api).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

Jonathan Barrett, Senior Engineer

FreeAgent: Accounting software, simplified

> **[Easy-to-use accounting software for UK small businesses](https://www.freeagent.com)**
>
> FreeAgent's powerful and easy-to-use accounting software for UK businesses brings everything together – from invoices and expenses to Self Assessment tax returns, payroll and MTD-compliant VAT filing. Take a free trial today!

+44 (0)131 447 0011

Follow us on Twitter: @freeagent [https://twitter.com/freeagent](https://twitter.com/freeagent)

FreeAgent Central Ltd, 40 Torphichen Street, Edinburgh EH3 8JB  
Registered in Scotland SC316774

---

<div class="post-metadata">

**Author:** ![Jonathan\_Barrett](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/jonathan_barrett/32/150_2.png) [@Jonathan\_Barrett](https://api-discuss.freeagent.com/u/Jonathan_Barrett)\
**Post date:** [25 February 2014 14:19 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/6 "2014-02-25T14:19:47Z")

</div>

Hi Iain,

The correct JSON for what you’re trying to do is:

{ “bank\_account\_explanation”: {“bank\_account”: … } }

From reading your code, it looks like what you want is probably along the  
lines of:

json\_encode(array(“bank\_account\_explanation” =\> array(“bank\_account” =\>  
…)));

I.e. JSON-encoding the whole nested array. Can you try that and let me know  
how you get on?

-J

---

<div class="post-metadata">

**Author:** ![Jonathan\_Barrett](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/jonathan_barrett/32/150_2.png) [@Jonathan\_Barrett](https://api-discuss.freeagent.com/u/Jonathan_Barrett)\
**Post date:** [26 February 2014 11:23 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/7 "2014-02-26T11:23:43Z")

</div>

Hi Iain,

Thanks for getting back to me with what you’ve tried so far. Where you’re  
getting server errors, those are what I’d expect: looking at the logs, the  
JSON we’re getting isn’t nested. It also appears to be slurping in an  
access\_token field: not sure where that’s coming from?

Where you’re getting PHP errors, this is going to be an issue with the  
library. Looking at the library’s repo, it looks like there was a change  
made recently that might address the issue you’re seeing:

> <https://github.com/athlan/oauth2/commit/15f0cf2280e94983b4f43cdafba8d930bd1bc39a>
>
> Not all API's accepts the POST data in array format, some APIs accepts for examp…le plain text as JSON.

Can I double check that you’re using the latest version of the library?

Cheers,

-J

PS for retrieving information from the API, you should be using GET  
requests, not POSTs. We have a quick breakdown of what verbs should be used  
when in the API docs [https://dev.freeagent.com/docs/introduction](https://dev.freeagent.com/docs/introduction).On Wed, Feb 26, 2014 at 11:04 AM, Iain W [iain.blot@googlemail.com](mailto:iain.blot@googlemail.com) wrote:

> Done some more testing and the problem exists on any POST transaction  
> where I actually try and post something. Everything else works fine. So I  
> can do a company enquiry (which is a POST transaction without any POST  
> parameters) and it will work, but any other transaction where I have POST  
> parameters doesn’t work.
> 
> Any further suggestions?  
> Iain
> 
> On Tuesday, 25 February 2014 10:02:06 UTC, Iain W wrote:
> 
> > I’m trying to add a bank transaction through the API but have hit a  
> > problem.
> > 
> > I’m using PHP Oauth2. I have no problem connecting and collecting  
> > invoices, but when I try to create a bank transaction the response array  
> > is as follows:
> > 
> > array(3) { [“result”]=\> array(1) { [“errors”]=\> array(1) {  
> > [“error”]=\> array(1) { [“message”]=\> string(41) “bank\_transaction or  
> > bank\_account required” } } } [“code”]=\> int(400) [“content\_type”]=\>  
> > string(31) “application/json; charset=utf-8” }
> > 
> > My code to add the bank transaction is
> > 
> > $postarray=array(“bank\_account” =\>  
> > “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”, “paid\_invoice” =\>  
> > $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\> $gross );
> > 
> > $updresp =  
> > $client-\>fetch(‘[https://api.freeagent.com/v2/bank\_](https://api.freeagent.com/v2/bank_)  
> > transaction\_explanations’,  
> > $postarray,  
> > ‘POST’,  
> > array(‘Authorization’ =\> 'Bearer '. $access,‘User-Agent’ =\>  
> > ‘My UA’)  
> > );
> > 
> > It seems to me that the POST parameters are not being recognized. I’m  
> > able to do a POST transaction to get the company details, but that has no  
> > parameters.
> > 
> > Appreciate if you can help.
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “FreeAgent API” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [freeagent\_api+unsubscribe@googlegroups.com](mailto:freeagent_api+unsubscribe@googlegroups.com).  
> To post to this group, send email to [freeagent\_api@googlegroups.com](mailto:freeagent_api@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/freeagent\_api](http://groups.google.com/group/freeagent_api).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

Jonathan Barrett, Senior Engineer

FreeAgent: Accounting software, simplified

> **[Easy-to-use accounting software for UK small businesses](https://www.freeagent.com)**
>
> FreeAgent's powerful and easy-to-use accounting software for UK businesses brings everything together – from invoices and expenses to Self Assessment tax returns, payroll and MTD-compliant VAT filing. Take a free trial today!

+44 (0)131 447 0011

Follow us on Twitter: @freeagent [https://twitter.com/freeagent](https://twitter.com/freeagent)

FreeAgent Central Ltd, 40 Torphichen Street, Edinburgh EH3 8JB  
Registered in Scotland SC316774

---

<div class="post-metadata">

**Author:** ![Jonathan\_Barrett](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/jonathan_barrett/32/150_2.png) [@Jonathan\_Barrett](https://api-discuss.freeagent.com/u/Jonathan_Barrett)\
**Post date:** [26 February 2014 17:12 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/8 "2014-02-26T17:12:14Z")

</div>

Glad we got there!

I’m not sure what our php developers use: feel free to open another thread  
to ask 🙂

-JOn Wednesday, 26 February 2014 16:59:50 UTC, Iain W wrote:

> Finally nailed it. You were right - the library has been updated since I  
> got it and it handles the POST of JSON properly now, which made the  
> authentication process a little different too.
> 
> The library doesn’t appear to have any way I can get hold of the response  
> headers to look at the pagination details, which is a pain
> 
> Is there an Oauth library that the majority of your users use? And that  
> has access to the pagination in the Link headers?
> 
> Thanks  
> Iain
> 
> On Wednesday, 26 February 2014 11:23:43 UTC, Jonathan Barrett wrote:
> 
> > Hi Iain,
> > 
> > Thanks for getting back to me with what you’ve tried so far. Where you’re  
> > getting server errors, those are what I’d expect: looking at the logs, the  
> > JSON we’re getting isn’t nested. It also appears to be slurping in an  
> > access\_token field: not sure where that’s coming from?
> > 
> > Where you’re getting PHP errors, this is going to be an issue with the  
> > library. Looking at the library’s repo, it looks like there was a change  
> > made recently that might address the issue you’re seeing:
> > 
> > [Support for non-array POST parameters added. · athlan/oauth2@15f0cf2 · GitHub](https://github.com/athlan/oauth2/commit/15f0cf2280e94983b4f43cdafba8d930bd1bc39a)
> > 
> > Can I double check that you’re using the latest version of the library?
> > 
> > Cheers,
> > 
> > -J
> > 
> > PS for retrieving information from the API, you should be using GET  
> > requests, not POSTs. We have a quick breakdown of what verbs should be used  
> > when in the API docs [https://dev.freeagent.com/docs/introduction](https://dev.freeagent.com/docs/introduction).
> > 
> > On Wed, Feb 26, 2014 at 11:04 AM, Iain W [iain...@googlemail.com](mailto:iain...@googlemail.com) wrote:
> > 
> > > Done some more testing and the problem exists on any POST transaction  
> > > where I actually try and post something. Everything else works fine. So I  
> > > can do a company enquiry (which is a POST transaction without any POST  
> > > parameters) and it will work, but any other transaction where I have POST  
> > > parameters doesn’t work.
> > > 
> > > Any further suggestions?  
> > > Iain
> > > 
> > > On Tuesday, 25 February 2014 10:02:06 UTC, Iain W wrote:
> > > 
> > > > I’m trying to add a bank transaction through the API but have hit a  
> > > > problem.
> > > > 
> > > > I’m using PHP Oauth2. I have no problem connecting and collecting  
> > > > invoices, but when I try to create a bank transaction the response  
> > > > array  
> > > > is as follows:
> > > > 
> > > > array(3) { [“result”]=\> array(1) { [“errors”]=\> array(1) {  
> > > > [“error”]=\> array(1) { [“message”]=\> string(41) “bank\_transaction or  
> > > > bank\_account required” } } } [“code”]=\> int(400) [“content\_type”]=\>  
> > > > string(31) “application/json; charset=utf-8” }
> > > > 
> > > > My code to add the bank transaction is
> > > > 
> > > > $postarray=array(“bank\_account” =\>  
> > > > “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”, “paid\_invoice” =\>  
> > > > $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\> $gross );
> > > > 
> > > > $updresp =  
> > > > $client-\>fetch(‘[https://api.freeagent.com/v2/bank\_](https://api.freeagent.com/v2/bank_)  
> > > > transaction\_explanations’,  
> > > > $postarray,  
> > > > ‘POST’,  
> > > > array(‘Authorization’ =\> 'Bearer '. $access,‘User-Agent’ =\>  
> > > > ‘My UA’)  
> > > > );
> > > > 
> > > > It seems to me that the POST parameters are not being recognized. I’m  
> > > > able to do a POST transaction to get the company details, but that has no  
> > > > parameters.
> > > > 
> > > > Appreciate if you can help.
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google  
> > > Groups “FreeAgent API” group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [freeagent\_ap...@googlegroups.com](mailto:freeagent_ap...@googlegroups.com).  
> > > To post to this group, send email to [freeag...@googlegroups.com](mailto:freeag...@googlegroups.com).  
> > > Visit this group at [http://groups.google.com/group/freeagent\_api](http://groups.google.com/group/freeagent_api).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > –
> > 
> > Jonathan Barrett, Senior Engineer
> > 
> > FreeAgent: Accounting software, simplified  
> > [www.freeagent.com](http://www.freeagent.com)
> > 
> > +44 (0)131 447 0011
> > 
> > Follow us on Twitter: @freeagent [https://twitter.com/freeagent](https://twitter.com/freeagent)
> > 
> > FreeAgent Central Ltd, 40 Torphichen Street, Edinburgh EH3 8JB  
> > Registered in Scotland SC316774

---

<div class="post-metadata">

**Author:** ![Iain\_W](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/i/e274bd/32.png) [@Iain\_W](https://api-discuss.freeagent.com/u/Iain_W)\
**Post date:** [25 February 2014 13:41 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/9 "2014-02-25T13:41:43Z")

</div>

Hi Jonathan

I tried what you suggested but got “Notice: Array to string conversion” notice  
from PHP Oauth, so serialized the embedded array into JSON as follows:

$postarray=array(“bank\_account\_explanation” =\>  
json\_encode(array(“bank\_account” =\>  
“[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”, “paid\_invoice” =\>  
$invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\> $gross )));

Dumping the array provides this, which looks ok

array(1) { [“bank\_account\_explanation”]=\> string(186)  
“{“bank\_account”:“https://api.freeagent.com/v2/bank\_account/147047”,“paid\_invoice”:“https://api.freeagent.com/v2/invoices/4924409”,“dated\_on”:“2012-09-08”,“gross\_value”:“12.00”}”  
}

But I’m still getting the same error:  
array(3) { [“result”]=\> array(1) { [“errors”]=\> array(1) { [“error”]=\>  
array(1) { [“message”]=\> string(41) “bank\_transaction or bank\_account  
required” } } } [“code”]=\> int(400) [“content\_type”]=\> string(31)  
“application/json; charset=utf-8” }

Kind regards  
IainOn Tuesday, 25 February 2014 12:16:56 UTC, Jonathan Barrett wrote:

> Hi Iain,
> 
> You’ll need to ensure the $postarray is contained in a  
> “bank\_transaction\_explanation” root element:
> 
> $postarray = array(“bank\_account\_explanation” =\> array(“bank\_account” =\> …  
> ));
> 
> If you look at the response in this section of the docs[https://dev.freeagent.com/docs/bank\_transaction\_explanations#create-a-bank-transaction-explanation](https://dev.freeagent.com/docs/bank_transaction_explanations#create-a-bank-transaction-explanation),  
> you’ll see the expected format for submitting resources.
> 
> Cheers,
> 
> -J
> 
> On Tuesday, 25 February 2014 10:02:06 UTC, Iain W wrote:
> 
> > I’m trying to add a bank transaction through the API but have hit a  
> > problem.
> > 
> > I’m using PHP Oauth2. I have no problem connecting and collecting  
> > invoices, but when I try to create a bank transaction the response array  
> > is as follows:
> > 
> > array(3) { [“result”]=\> array(1) { [“errors”]=\> array(1) {  
> > [“error”]=\> array(1) { [“message”]=\> string(41) “bank\_transaction or  
> > bank\_account required” } } } [“code”]=\> int(400) [“content\_type”]=\>  
> > string(31) “application/json; charset=utf-8” }
> > 
> > My code to add the bank transaction is
> > 
> > $postarray=array(“bank\_account” =\>  
> > “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”, “paid\_invoice” =\>  
> > $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\> $gross );
> > 
> > $updresp =  
> > $client-\>fetch(’  
> > [https://api.freeagent.com/v2/bank\_transaction\_explanations](https://api.freeagent.com/v2/bank_transaction_explanations)’,  
> > $postarray,  
> > ‘POST’,  
> > array(‘Authorization’ =\> 'Bearer '. $access,‘User-Agent’ =\>  
> > ‘My UA’)  
> > );
> > 
> > It seems to me that the POST parameters are not being recognized. I’m  
> > able to do a POST transaction to get the company details, but that has no  
> > parameters.
> > 
> > Appreciate if you can help.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Barrett](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/jonathan_barrett/32/150_2.png) [@Jonathan\_Barrett](https://api-discuss.freeagent.com/u/Jonathan_Barrett)\
**Post date:** [25 February 2014 12:16 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/10 "2014-02-25T12:16:56Z")

</div>

Hi Iain,

You’ll need to ensure the $postarray is contained in a  
“bank\_transaction\_explanation” root element:

$postarray = array(“bank\_account\_explanation” =\> array(“bank\_account” =\> …  
));

If you look at the response in this section of the docs[https://dev.freeagent.com/docs/bank\_transaction\_explanations#create-a-bank-transaction-explanation](https://dev.freeagent.com/docs/bank_transaction_explanations#create-a-bank-transaction-explanation),  
you’ll see the expected format for submitting resources.

Cheers,

-JOn Tuesday, 25 February 2014 10:02:06 UTC, Iain W wrote:

> I’m trying to add a bank transaction through the API but have hit a  
> problem.
> 
> I’m using PHP Oauth2. I have no problem connecting and collecting  
> invoices, but when I try to create a bank transaction the response array  
> is as follows:
> 
> array(3) { [“result”]=\> array(1) { [“errors”]=\> array(1) {  
> [“error”]=\> array(1) { [“message”]=\> string(41) “bank\_transaction or  
> bank\_account required” } } } [“code”]=\> int(400) [“content\_type”]=\>  
> string(31) “application/json; charset=utf-8” }
> 
> My code to add the bank transaction is
> 
> $postarray=array(“bank\_account” =\>  
> “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”, “paid\_invoice” =\>  
> $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\> $gross );
> 
> $updresp =  
> $client-\>fetch(’  
> [https://api.freeagent.com/v2/bank\_transaction\_explanations](https://api.freeagent.com/v2/bank_transaction_explanations)’,  
> $postarray,  
> ‘POST’,  
> array(‘Authorization’ =\> 'Bearer '. $access,‘User-Agent’ =\>  
> ‘My UA’)  
> );
> 
> It seems to me that the POST parameters are not being recognized. I’m  
> able to do a POST transaction to get the company details, but that has no  
> parameters.
> 
> Appreciate if you can help.

---

<div class="post-metadata">

**Author:** ![Iain\_W](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/i/e274bd/32.png) [@Iain\_W](https://api-discuss.freeagent.com/u/Iain_W)\
**Post date:** [25 February 2014 15:43 UTC](https://api-discuss.freeagent.com/t/bank-transaction-post-not-working/369/11 "2014-02-25T15:43:38Z")

</div>

Hi Jonathan  
To recap,  
I’m using the PHP OAuth2 Client library from Github as mentioned in your  
doco at [FreeAgent Developer Dashboard](https://dev.freeagent.com/docs/oauth).

Once the authorisation has been done, you have a object that you can call  
the fetch method on as follows:

$object-\>fetch(url, request params, method, header params)

The request parameters are what we appear to be having a problem with

1. If I have a single dimension array, as per

array(4) { [“bank\_account”]=\> string(48)  
“[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)” [“paid\_invoice”]=\>  
string(45) “[https://api.freeagent.com/v2/invoices/4924409](https://api.freeagent.com/v2/invoices/4924409)” [“dated\_on”]=\>  
string(10) “2012-09-08” [“gross\_value”]=\> string(5) “12.00” }

the response provides a failure ‘bank\_transaction or bank\_account required’.

1. If I have a multi dimension array as per

array(1) { [“bank\_transaction\_explanation”]=\> array(4) { [“bank\_account”]=\>  
string(48) “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”  
[“paid\_invoice”]=\> string(45)  
“[https://api.freeagent.com/v2/invoices/4924409](https://api.freeagent.com/v2/invoices/4924409)” [“dated\_on”]=\> string(10)  
“2012-09-08” [“gross\_value”]=\> string(5) “12.00” } }

I’ll get a ‘Notice: Array to string conversion’ warning from OAuth and a  
500 Server Error.

1. If I serialise the embedded array as per

array(1) { [“bank\_transaction\_explanation”]=\> string(186)  
“{“bank\_account”:“https://api.freeagent.com/v2/bank\_account/147047”,“paid\_invoice”:“https://api.freeagent.com/v2/invoices/4924409”,“dated\_on”:“2012-09-08”,“gross\_value”:“12.00”}”  
}

I get a 500 Server Error

1. If I serialise the whole array as per

string(219)  
“{“bank\_transaction\_explanation”:{“bank\_account”:“https://api.freeagent.com/v2/bank\_account/147047”,“paid\_invoice”:“https://api.freeagent.com/v2/invoices/4924409”,“dated\_on”:“2012-09-08”,“gross\_value”:“12.00”}}”

I get a 'Fatal error: Uncaught exception ‘OAuth2\InvalidArgumentException’  
with message ‘You need to give parameters as array if you want to give the  
token within the URI.’ error

Could you perhaps just verify what your API expects for an insert bank  
transaction call, because in reading your documentation it really doesn’t  
look like I need a multidimensional parameter list - it just looks like  
that is what is returned in the response.

Kind regards  
IainOn Tuesday, 25 February 2014 15:05:02 UTC, Jonathan Barrett wrote:

> Hi Iain,
> 
> Thanks for that. I’m at a bit of a loss here, as I’m not familiar with the  
> php OAuth library. To my reading, the library requires an array of params,  
> but when handed a multidimensional array, it complains that it’s not an  
> array? To confirm, the following fails with a “you need to give parameters  
> as an array…” error, yes?
> 
> $postarray = array(“bank\_transaction\_explanation” =\> array(“bank\_account”  
> =\> … ) );
> 
> -J
> 
> On Tue, Feb 25, 2014 at 2:33 PM, Iain W \<[iain...@googlemail.com](mailto:iain...@googlemail.com)\<javascript:\> wrote:
> 
> > Yep, already tried that
> > 
> > $postarray=json\_encode(array(“bank\_transaction\_explanation” =\>  
> > array(“bank\_account” =\> “[https://api.freeagent.com/v2/bank\_account/147047](https://api.freeagent.com/v2/bank_account/147047)”,  
> > “paid\_invoice” =\> $invoice, “dated\_on” =\> “2012-09-08”, “gross\_value” =\>  
> > $gross )));
> > 
> > Which gives :
> > 
> > string(257)  
> > “{“bank\_transaction\_explanation”:”{"bank\_account":"https:\/\/  
> > [api.freeagent.com](http://api.freeagent.com)  
> > \/v2\/bank\_account\/147047","paid\_invoice":"https:\/\/  
> > [api.freeagent.com](http://api.freeagent.com)  
> > \/v2\/invoices\/4924409","dated\_on":"2012-09-08","gross\_value":"12.00"}“}”
> > 
> > Then I get the following error:
> > 
> > Fatal error: Uncaught exception ‘OAuth2\InvalidArgumentException’ with  
> > message ‘You need to give parameters as array if you want to give the token  
> > within the URI.’
> > 
> > Iain
> > 
> > On Tuesday, 25 February 2014 14:19:47 UTC, Jonathan Barrett wrote:
> > 
> > > Hi Iain,
> > > 
> > > The correct JSON for what you’re trying to do is:
> > > 
> > > { “bank\_account\_explanation”: {“bank\_account”: … } }
> > > 
> > > From reading your code, it looks like what you want is probably along  
> > > the lines of:
> > > 
> > > json\_encode(array(“bank\_account\_explanation” =\> array(“bank\_account” =\>  
> > > …)));
> > > 
> > > I.e. JSON-encoding the whole nested array. Can you try that and let me  
> > > know how you get on?
> > > 
> > > -J
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “FreeAgent API” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [freeagent\_ap...@googlegroups.com](mailto:freeagent_ap...@googlegroups.com) \<javascript:\>.  
> > To post to this group, send email to [freeag...@googlegroups.com](mailto:freeag...@googlegroups.com)\<javascript:\>  
> > .  
> > Visit this group at [http://groups.google.com/group/freeagent\_api](http://groups.google.com/group/freeagent_api).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> –
> 
> Jonathan Barrett, Senior Engineer
> 
> FreeAgent: Accounting software, simplified  
> [www.freeagent.com](http://www.freeagent.com)
> 
> +44 (0)131 447 0011
> 
> Follow us on Twitter: @freeagent [https://twitter.com/freeagent](https://twitter.com/freeagent)
> 
> FreeAgent Central Ltd, 40 Torphichen Street, Edinburgh EH3 8JB  
> Registered in Scotland SC316774
