1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00
invoiceninja/docs/api.rst

133 lines
4.7 KiB
ReStructuredText
Raw Normal View History

2021-07-04 00:08:39 +02:00
API (VERSION 4)
2021-07-25 12:11:41 +02:00
===============
2017-03-13 19:56:20 +01:00
2021-07-04 00:08:39 +02:00
**Please note this is for the V4 API, if you are looking for V5 API documentation please go here** https://app.swaggerhub.com/apis/invoiceninja/invoiceninja
2021-07-25 12:09:05 +02:00
Invoice Ninja provides a RESTful API,
2017-03-13 19:56:20 +01:00
2017-08-08 07:39:24 +02:00
To access the API you first need to create a token using the "API Tokens” page under "Advanced Settings”.
2017-03-13 19:56:20 +01:00
2017-03-21 16:30:33 +01:00
- **Zapier** [hosted or self-host]: https://zapier.com/zapbook/invoice-ninja/
2017-04-28 09:08:01 +02:00
- **Integromat**: https://www.integromat.com/en/integrations/invoiceninja
2017-03-13 20:20:37 +01:00
- **PHP SDK**: https://github.com/invoiceninja/sdk-php
2017-04-28 09:12:17 +02:00
- **Zend Framework**: https://github.com/alexz707/InvoiceNinjaModule
2017-03-13 19:56:20 +01:00
2017-12-31 10:08:46 +01:00
.. NOTE:: Replace ninja.test with https://app.invoiceninja.com to access a hosted account.
2017-03-13 19:56:20 +01:00
Reading Data
""""""""""""
Heres an example of reading the list of clients using cURL from the command line.
2017-03-17 15:39:20 +01:00
.. code-block:: shell
curl -X GET "ninja.test/api/v1/clients" -H "X-Ninja-Token: TOKEN"
2017-03-13 19:56:20 +01:00
2017-03-19 16:44:35 +01:00
For invoices, quotes, tasks and payments simply change the object type.
2017-03-13 19:56:20 +01:00
2017-03-17 15:39:20 +01:00
.. code-block:: shell
curl -X GET "ninja.test/api/v1/invoices" -H "X-Ninja-Token: TOKEN"
2017-03-13 19:56:20 +01:00
You can search clients by their email address or id number and invoices by their invoice number.
2017-03-19 17:03:17 +01:00
.. code-block:: shell
curl -X GET "ninja.test/api/v1/clients?email=<value>" -H "X-Ninja-Token: TOKEN"
curl -X GET "ninja.test/api/v1/clients?id_number=<value>" -H "X-Ninja-Token: TOKEN"
curl -X GET "ninja.test/api/v1/invoices?invoice_number=<value>" -H "X-Ninja-Token: TOKEN"
2017-03-19 17:03:17 +01:00
To load a single record specify the Id in the URL.
2017-03-13 19:56:20 +01:00
2017-03-17 15:39:20 +01:00
.. code-block:: shell
curl -X GET "ninja.test/api/v1/invoices/1" -H "X-Ninja-Token: TOKEN"
2017-03-13 19:56:20 +01:00
2017-03-19 16:44:35 +01:00
You can specify additional relationships to load using the ``include`` parameter.
.. code-block:: shell
curl -X GET "ninja.test/api/v1/clients/1?include=invoices.invitations" -H "X-Ninja-Token: TOKEN"
2017-03-19 16:44:35 +01:00
2017-03-13 19:56:20 +01:00
You can download a PDF using the following URL
2017-03-17 15:39:20 +01:00
.. code-block:: shell
curl -X GET "ninja.test/api/v1/download/1" -H "X-Ninja-Token: TOKEN"
2017-03-13 19:56:20 +01:00
2017-03-19 17:03:17 +01:00
Optional Settings
"""""""""""""""""
The following are optional query parameter settings:
- ``serializer``: Either array (the default) or `JSON <http://jsonapi.org/>`_.
- ``include``: A comma-separated list of nested relationships to include.
- ``client_id``: If set the results will be filtered by the client.
- ``page``: The page number of results to return when the results are paginated.
- ``per_page``: The number of results to return per page.
- ``updated_at``: Timestamp used as a filter to only show recently updated records.
2017-03-13 19:56:20 +01:00
Creating Data
"""""""""""""
2017-03-19 17:03:17 +01:00
.. TIP:: Add ``-H "X-Requested-With: XMLHttpRequest"`` to see validation errors in the response.
2017-03-13 19:56:20 +01:00
Heres an example of creating a client. Note that email address is a property of the clients contact not the client itself.
2017-03-17 15:39:20 +01:00
.. code-block:: shell
curl -X POST "ninja.test/api/v1/clients" -H "Content-Type:application/json" \
2017-04-24 17:39:39 +02:00
-d '{"name":"Client","contact":{"email":"test@example.com"}}' -H "X-Ninja-Token: TOKEN"
2017-03-13 19:56:20 +01:00
You can also update a client by specifying a value for id. Next, heres an example of creating an invoice.
2017-03-17 15:39:20 +01:00
.. code-block:: shell
curl -X POST "ninja.test/api/v1/invoices" -H "Content-Type:application/json" \
2017-05-16 11:37:39 +02:00
-d '{"client_id":"1", "invoice_items":[{"product_key": "ITEM", "notes":"Test", "cost":10, "qty":1}]}' \
2017-03-17 15:39:20 +01:00
-H "X-Ninja-Token: TOKEN"
2017-03-13 19:56:20 +01:00
2018-01-07 14:11:20 +01:00
If the email field is set well search for a matching client, if no matches are found a new client will be created.
If the product_key is set and matches an existing record the product fields will be auto-populated. You can use a comma-separated value to create an invoice with multiple products.
2017-03-13 19:56:20 +01:00
2017-04-24 17:44:08 +02:00
Options
^^^^^^^
The following options are available when creating an invoice.
- ``email_invoice``: Email the invoice to the client.
- ``email_type``: Set to reminder1, reminder2 or reminder3 to use the reminder template.
2017-04-24 17:44:08 +02:00
- ``auto_bill``: Attempt to auto-bill the invoice using stored payment methods or credits.
- ``paid``: Create a payment for the defined amount.
2017-04-24 17:39:39 +02:00
Updating Data
"""""""""""""
.. NOTE:: When updating a client it's important to include the contact ids.
.. code-block:: shell
curl -X PUT 'ninja.test/api/v1/clients/1" -H "Content-Type:application/json" \
2017-05-16 11:37:39 +02:00
-d '{"name":"test", "contacts":[{"id": 1, "first_name": "test"}]}' \
2017-04-24 17:39:39 +02:00
-H "X-Ninja-Token: TOKEN"
2017-05-22 11:16:27 +02:00
You can archive, delete or restore an entity by setting ``action`` in the request
2017-05-22 11:18:20 +02:00
.. code-block:: shell
curl -X PUT "ninja.test/api/v1/invoices/1?action=archive" \
2017-05-22 11:16:27 +02:00
-H "X-Ninja-Token: TOKEN"
2017-10-01 20:25:59 +02:00
.. TIP:: For invoices use `mark_sent` to manually mark the invoice as sent
2017-03-13 19:56:20 +01:00
Emailing Invoices
"""""""""""""""""
To email an invoice use the email_invoice command passing the id of the invoice.
2017-03-17 15:32:11 +01:00
.. code-block:: shell
curl -X POST "ninja.test/api/v1/email_invoice" -d '{"id":1}' \
2017-03-17 15:39:20 +01:00
-H "Content-Type:application/json" -H "X-Ninja-Token: TOKEN"