Accessing invoices by id


#1

Hi

I’m trying to access invoices by invoice number.

There’s a sparsely documented reference to this:

Get a single invoice:
GET https://api.freeagent.com/v2/invoices/:id

Frustratingly ‘id’ is not defined in this context, and only seems to be mentioned in the updating / deleting section where even there the definition is really unhelpful:

id	ID of the invoice item to update	Integer

So what is the id exactly? I was assuming it was the invoice number I have attributed in Freeagent but it’s really not clear. If it’s not that, what is it?

I currently get the response:

Resource not found

Help!

Thanks
Bruce


#2

The id is the number you see at the end of the URL when you are viewing an invoice on FreeAgent’s website. It is not the invoice reference number.

As far as I know there’s no way to get a single invoice directly by reference number. You have to get a list from the invoices endpoint and iterate over it looking for the one you want.

Yours,
Andrew


#3

Hi @weblaunch,

Thanks for your question. Our API follows the REST convention of allowing you to pass an item’s unique ID into the request URL to show a single resource from a collection. This ID can be retrieved from the url attribute of the item, e.g. when listing all invoices:

{
    "invoices": [
        {
            "url": "https://api.sandbox.freeagent.com/v2/invoices/97336",
            "contact": "https://api.sandbox.freeagent.com/v2/contacts/83986",
            "dated_on": "2019-12-12",
            "due_on": "2019-12-17",
            "reference": "004",
            "contact_name": "Test Contact",
            ...
        },
        {
            "url": "https://api.sandbox.freeagent.com/v2/invoices/97337",
            "contact": "https://api.sandbox.freeagent.com/v2/contacts/83986",
            "dated_on": "2019-12-12",
            "due_on": "2019-12-17",
            "reference": "005",
            "contact_name": "Test Contact",
            ...
        }
    ]
}

you can get the individual item’s ID from the url (in the example above 97336 and 97337). Subsequently making a GET request to https://api.sandbox.freeagent.com/v2/invoices/97336 will allow you to view the details of that invoice only.

I hope this helps!

Best wishes,

Ewa


#4

Thanks for the replies, guys.

Wow. I saw a post from 2013 asking for this feature. I can’t comprehend why it hasn’t been implemented. This seems such a heavy-handed, resource-sucking way to achieve what must be a common task, I would have thought!

Also, would be good to get the documentation updated just to make this clear :slight_smile:


#5

And 5 hours later I’m still trying to retrieve one invoice by its reference by loading in ALL the invoices, using the pagination etc etc

"Why Freeagent - WHY?!?! " he cried into the abyss.