Hi Jonathan
To recap,
I’m using the PHP OAuth2 Client library from Github as mentioned in your
doco at FreeAgent Developer Dashboard.
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
- If I have a single dimension array, as per
array(4) { [“bank_account”]=> string(48)
“https://api.freeagent.com/v2/bank_account/147047” [“paid_invoice”]=>
string(45) “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’.
- 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”
[“paid_invoice”]=> string(45)
“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.
- 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
- 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<javascript:> wrote:
Yep, already tried that
$postarray=json_encode(array(“bank_transaction_explanation” =>
array(“bank_account” => “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.’
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 <javascript:>.
To post to this group, send email to freeag...@googlegroups.com<javascript:>
.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.
–
Jonathan Barrett, Senior Engineer
FreeAgent: Accounting software, simplified
www.freeagent.com
+44 (0)131 447 0011
Follow us on Twitter: @freeagent https://twitter.com/freeagent
FreeAgent Central Ltd, 40 Torphichen Street, Edinburgh EH3 8JB
Registered in Scotland SC316774