Sending transaction ID as integer rather than string

Just been chasing this error for ages and finally figured it out. If you
sent a “transaction_id” as an integer instead of a string you get a blank
response from the API with no error message, if you send it as a string
then it’s just fine. Compare these two nearly identical json posts:

{“bank_transaction_explanation”:{“bank_transaction”:“59691067”,“dated_on”:“2015-01-22”,“description”:“yearly membership test”,“entry_type”:“Sales”,“gross_value”:100}}

{“bank_transaction_explanation”:{“bank_transaction”:59691067,“dated_on”:“2015-01-22”,“description”:“yearly membership test”,“entry_type”:“Sales”,“gross_value”:100}}

The only difference between the two is the bank_transaction is wrapped in quotes, in one and not the other.

Both are completely valid JSON, but the API returns a blank page with no response to the second one, but works out the first one perfectly.

I would recommend either 1) giving an appropriate error message or 2) (more preferably) accepting integers for id’s.

Just wasted over an hour trying to figure out why one method worked and another didn’t :smiley:

Hi Rob,

Thanks for highlighting this and sorry for the confusion.

I’ve had a look in the code and I can see what’s happening.
The API is designed to use absolute URLs when referencing existing
entities, such as unexplained bank_transactions.

For example:

https://api.freeagent.com/v2/bank_transactions/8

As you’ve spotted, passing just a string version of the
bank_transaction ID works on this occasion, though I don’t think that
could be guaranteed on all API end-points.

You’re right, of course, we should be returning an error message
rather than an empty response. I’ll document this internally.

Going forward, to avoid other unexpected behaviour, could you
reference bank_transactions, bank_accounts, contacts etc using their
absolute URLs?

Hope this helps!,
Dave JOn 23 January 2015 at 17:07, Rob Brain pinkmunkeys@gmail.com wrote:

Just been chasing this error for ages and finally figured it out. If you
sent a “transaction_id” as an integer instead of a string you get a blank
response from the API with no error message, if you send it as a string
then it’s just fine. Compare these two nearly identical json posts:

{“bank_transaction_explanation”:{“bank_transaction”:“59691067”,“dated_on”:“2015-01-22”,“description”:“yearly membership test”,“entry_type”:“Sales”,“gross_value”:100}}

{“bank_transaction_explanation”:{“bank_transaction”:59691067,“dated_on”:“2015-01-22”,“description”:“yearly membership test”,“entry_type”:“Sales”,“gross_value”:100}}

The only difference between the two is the bank_transaction is wrapped in quotes, in one and not the other.

Both are completely valid JSON, but the API returns a blank page with no response to the second one, but works out the first one perfectly.

I would recommend either 1) giving an appropriate error message or 2) (more preferably) accepting integers for id’s.

Just wasted over an hour trying to figure out why one method worked and another didn’t :smiley:


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.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/d/optout.

David Jones
Senior Support Engineer

FreeAgent

Hi David,

Thanks for the reply, however functionality seems to be limited using the
end points you suggest.

What I am trying to do is add a manual transaction to a bank account, there
is no create transaction endpoint, but if an explanation is sent, then a
transaction gets created along with the explanation, which is great.

This works just fine to achieve this. Note that the “bank_account” id is
not given in the endpoint only in the POST

Endpoint: https://api.freeagent.com/v2/bank_transaction_explanations

“bank_transaction_explanation” => array(
“bank_account”=>‘297073’,
“dated_on”=>‘2015-01-12’,
“description”=>“another test”,
“entry_type”=>“Sales”,
“gross_value”=>200
)

But this does not work. This time the id is in the endpoint as you suggest.

Endpoint: https://api.freeagent.com/v2/bank_transaction_explanations/297073

“bank_transaction_explanation” => array(
“dated_on”=>‘2015-01-12’,
“description”=>“another test”,
“entry_type”=>“Sales”,
“gross_value”=>200
)

Like I said, it works the way i’m doing it now (so long as it’s a string
not an integer). But the way you say it should work doesn’t work.On Monday, 26 January 2015 12:07:46 UTC, David Jones wrote:

Hi Rob,

Thanks for highlighting this and sorry for the confusion.

I’ve had a look in the code and I can see what’s happening.
The API is designed to use absolute URLs when referencing existing
entities, such as unexplained bank_transactions.

For example:

https://api.freeagent.com/v2/bank_transactions/8

As you’ve spotted, passing just a string version of the bank_transaction ID works on this occasion, though I don’t think that could be guaranteed on all API end-points.

You’re right, of course, we should be returning an error message rather than an empty response. I’ll document this internally.

Going forward, to avoid other unexpected behaviour, could you reference bank_transactions, bank_accounts, contacts etc using their absolute URLs?

Hope this helps!,
Dave J

On 23 January 2015 at 17:07, Rob Brain <pinkm...@gmail.com <javascript:>> wrote:

Just been chasing this error for ages and finally figured it out. If you
sent a “transaction_id” as an integer instead of a string you get a blank
response from the API with no error message, if you send it as a string
then it’s just fine. Compare these two nearly identical json posts:

{“bank_transaction_explanation”:{“bank_transaction”:“59691067”,“dated_on”:“2015-01-22”,“description”:“yearly membership test”,“entry_type”:“Sales”,“gross_value”:100}}

{“bank_transaction_explanation”:{“bank_transaction”:59691067,“dated_on”:“2015-01-22”,“description”:“yearly membership test”,“entry_type”:“Sales”,“gross_value”:100}}

The only difference between the two is the bank_transaction is wrapped in quotes, in one and not the other.

Both are completely valid JSON, but the API returns a blank page with no response to the second one, but works out the first one perfectly.

I would recommend either 1) giving an appropriate error message or 2) (more preferably) accepting integers for id’s.

Just wasted over an hour trying to figure out why one method worked and another didn’t :smiley:


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/d/optout.


David Jones
Senior Support Engineer

FreeAgent