Home Forums Support How to update clients and invoices data through the API

This topic contains 5 replies, has 3 voices, and was last updated by  Hillel Coren 2 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4408

    joaquin.iranzo
    Participant

    We need to interact with the InvoiceNinja using the exposed API (https://www.invoiceninja.com/api-documentation/).
    It is indicated that we could update the client data specifying a value for ‘id’. Nevertheless, we haven’t been able to achieve it, we always receive a response error, for example:

    *When we have tried the “PUT” method with https://app.invoiceninja.com/api/v1/clients; the response is:
    Something went wrong…
    Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException

    *If we have tried the “PUT” method with https://app.invoiceninja.com/api/v1/clients/2 (client id=2 exists); the response is:
    “Something went wrong… ErrorException”.

    Note: We have tried with different bodies:
    {“id”:”2″,”name”:”ClientTestXXXX”,”contact”:{“email”:”[email protected]”}}
    or
    {“name”:”ClientTestXXXX”,”contact”:{“email”:”[email protected]”}}

    On the other side, we also need to update the invoices data (in draft status). However, in the documentation, it is not commented anything about this functionality (we have tried to use PUSH + invoice id, but it is not working).

    We wonder if you could provide an example of how to update the client data and confirm us if we could update the invoices through the API REST.

    #4409

    Hillel Coren
    Keymaster

    This is the correct URL: https://app.invoiceninja.com/api/v1/clients/2

    Try changing contact to contacts and make it an array.

    You should be able to update the invoice through the API, we use it for our iPhone app.

    #4669

    joaquin.iranzo
    Participant

    Thank you for your answer, and sorry for the late response. Now, all the calls are working correctly, even for updating invoices. I would like to post here the curl calls for everybody.

    $ curl -X PUT https://app.invoiceninja.com/api/v1/clients/23 -H “Content-Type:application/json” -d ‘{“id”: 23,”name”: “ClientName”,”contacts”: [{“id”: 19,”first_name”: “example”,”last_name”: “last name”,”email”: “[email protected]”}]}’ -H “X-Ninja-Token: YqN8zeC0JKRNHW6HCsfplAeib2akgLng” -H “X-Requested-With: XMLHttpRequest”

    $ curl -X PUT https://app.invoiceninja.com/api/v1/invoices/12 -H “Content-Type:application/json” -d ‘{“id”: 12,”client_id”: 23,”invoice_items”: [{“id”: 21,”product_key”: “lamp”,”notes”: “lamp notes”,”cost”: 22,”qty”: 5},{“id”: 22,”product_key”: “other”,”notes”: “other notes”, “cost”: 44,”qty”: 10}] }’ -H “X-Ninja-Token: token_Id” -H “X-Requested-With: XMLHttpRequest”

    By the way, I have only one more question regarding the clients, I have tried to obtain only the registry for one client but the system give an error “Something went wrong… ReflectionException” ). The call is this one:
    $ curl -X GET https://app.invoiceninja.com/api/v1/clients/23 -H “X-Ninja-Token: token_id” -H “X-Requested-With: XMLHttpRequest”

    Nevertheless, for the invoice data is working correctly:
    $ curl -X GET https://app.invoiceninja.com/api/v1/invoices/12 -H “X-Ninja-Token: YqN8zeC0JKRNHW6HCsfplAeib2akgLng” -H “X-Requested-With: XMLHttpRequest”

    I can create another ticket in the support system, if you consider that it should be covered in another thread. Thank you in advance.

    #4670

    Hillel Coren
    Keymaster

    If you send an email to [email protected] with the email address of your account I’ll check our error logs for more details.

    #20416

    braddcadd
    Participant

    I am having some trouble with my curl. I would like to number all of my clients (id_number=A001, A002, etc) similar to the database id (1,2,etc). Any advice?

    
    curl -X PUT https://app.invoiceninja.com/api/v1/clients/1 -H “Content-Type:application/json” -d ‘{“id_number”: "A001"}’ -H “X-Ninja-Token: a-long-token”
    

    {“error”:{“message”:”Invalid token”}}curl: (3) [globbing] unmatched close brace/bracket in column 5
    curl: (3) Failed to convert plffhfkl667pizbq2bcvpuujkzfnjrby” to ACE; string contains a disallowed character

    • This reply was modified 2 months, 1 week ago by  braddcadd.
    #20419

    Hillel Coren
    Keymaster

    I see two possible issues:

    – You may be using the wrong type of quotes: ” vs " (unless that’s just from the forum)

    – Updating an invoice requires passing all current invoice values

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Posted in: