# Issue obtaining a token

**URL:** <https://api-discuss.freeagent.com/t/issue-obtaining-a-token/6637>\
**Category:** Authentication\
**Created:** [31 July 2026 10:21 UTC](https://api-discuss.freeagent.com/t/issue-obtaining-a-token/6637 "2026-07-31T10:21:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecoleman](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/ecoleman/32/1253_2.png) [@ecoleman](https://api-discuss.freeagent.com/u/ecoleman)\
**Post date:** [31 July 2026 10:21 UTC](https://api-discuss.freeagent.com/t/issue-obtaining-a-token/6637/1 "2026-07-31T10:21:36Z")

</div>

Hi all,

I’m fairly competent at PHP but certainly no expert and OAuth has my head spinning, however I did find some useful information here

> **[Using the FreeAgent API with PHP and OAuth2](https://outlandish.com/blog/tutorial/freeagent-api-php-oauth2/)**
>
> FreeAgent, the online business accounting software that we use, has just released a new version of its developer API.

but I’m running into a problem. My needs are quite simple, I just want to import invoices from my ecommerce website on a daily basis, either via a cron job or manually, it doesn’t really matter.

Now, using the code example above I am able to complete the first step of getting a code. The issue is exchanging that code for a token. I am getting an error 400 “invalid\_grant”.

Not knowing if this was an issue with the sample code I’m using I tried in the Google playground and here I get the same problem. Getting the code is no problem but getting the same “invalid\_grant” error when trying to exchange it for a token.

Based on this, I’m guessing an issue on Freeagent side?

Any help would be greatly appreciated. I need to move away from Kashflow who are bloody useless with customer service but I need the ability to import my orders as invoices.

TIA, Elliott

---

<div class="post-metadata">

**Author:** ![ecoleman](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/ecoleman/32/1253_2.png) [@ecoleman](https://api-discuss.freeagent.com/u/ecoleman)\
**Post date:** [7 August 2026 17:03 UTC](https://api-discuss.freeagent.com/t/issue-obtaining-a-token/6637/2 "2026-08-07T17:03:53Z")

</div>

Never mind folks. I’ve moved on to Xero. Their API works

---

<div class="post-metadata">

**Author:** ![Carly\_O](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/carly_o/32/703_2.png) [@Carly\_O](https://api-discuss.freeagent.com/u/Carly_O)\
**Post date:** [10 August 2026 08:27 UTC](https://api-discuss.freeagent.com/t/issue-obtaining-a-token/6637/3 "2026-08-10T08:27:22Z")

</div>

Hey Elliot,

Thanks for getting in touch. So for the API we recommend following our own docs, which you can find here: [FreeAgent Developer Dashboard](https://dev.freeagent.com/docs/quick_start)

If you are still having issues setting up using these docs, just let us know.

Cheers!
