Create Task - API Example

Hello,

I recently migrated from InvoicePlane to InvoiceNinja v5, and I would like to clarify a question about the API.

I’m running a test trying to create a task with curl with the following code:

#!/bin/bash

curl --request POST
–url https://host.domain.com/api/v1/tasks
–header ‘X-Api-Token: UZsdfdsfdfdfsIan32N3IB2qYJKe’
–header ‘X-Requested-With: XMLHttpRequest’
–data ‘{ “client_id”: “23”, “user_id”: “1” }’

The task is created successfully, but with the client_id and user_id fields blank.

I tried here on the forum and in the API documentation to look for information on how to create a task for a specific client, but without success.

Could someone with more experience please help me?

Thank you

Hi.

Welcome!

You need to pass the hashed id’s in the API request (ie QBeXRNzgby). The web app also uses the API, I suggest using the network tab in the browser console to see sample API requests.

Hello,

Thank you for your reply!

I was able to get the user code through the developer tools in the browser, I tried different ways like sending the data through a .json file, but the result was the same.

I tried with these commands:

curl --request GET
–url https://host.domain.com/api/v1/tasks/W4QbYy0bzq/edit
–header ‘X-Api-Token: UZeoChUB8sdfsHZUrKO5gZaqIan32N3IB2qYJKe’
–header ‘X-Requested-With: XMLHttpRequest’
–data ‘{ “client_id”: “7N1aMAaWmp” }’

I used the API documentation as an example, do you have any other ideas on how I can debug this issue?

Thank you!

The command above is incorrect, you can’t use a GET request to edit the record.

Hello,

Thank you for your reply.

Without GET I get the following error:

{“message”:“Method not supported for this route”}

But I managed to solve the problem as follows:

First I created a task, and after getting the task ID, I was able to edit the data with the following command:

curl --header ‘X-Api-Token: UZeoChUB8aan32N3IB2qYJKe’ --header ‘X-Requested-With: XMLHttpRequest’ --request PUT --url https://hosting.domain.com/api/v1/tasks/W4QbYy0bzq?client_id=“7N1aMAaWmp”&description=yyy

I would like to create a task directly without having to edit, but this was the best way I found.

Anyway, I appreciate your help!

PUT can be used to edit, to create you want to send a POST request to /tasks

Hello,

Thank you for your help, this the final conclusion:

description=“Message…”
url=“https://hosting.domain.com/api/v1/tasks
x_api_token=“UZeoChUB8KO5gZaqIan32N3IB2qYJKe”
client_d $1

task_id=curl --silent --request POST \ --url $url \ --header "X-Api-Token: $x_api_token" \ --header 'X-Requested-With: XMLHttpRequest' |jq -r '.data.id'

curl --silent --header “X-Api-Token: $x_api_token”
–header ‘X-Requested-With: XMLHttpRequest’
–request PUT --url “$url/$task_id?client_id=$1&description=$description”

@minimediale

Have you checked the API documentation?

https://api-docs.invoicing.co/#tag/tasks/POST/api/v1/tasks
curl -X PUT 'http://ninja.test:8000/api/v1/tasks/JxboV2jagw' \
-H "X-API-TOKEN:company-token-test" \
-H "Content-Type:application/json" \
-d '{"client-id":"xxxx"}' \
-H "X-Requested-With: XMLHttpRequest" \
-H "X-API-SECRET:password";

yes,

I checked the documentation, but unfortunately it didn’t work that way. However, the way I described above worked.

Thank you