Creating an invoice in Invoice Ninja

Creating an invoice in Invoice Ninja

There is a connection to invoice ninja but the most important functionality - invoice creation - is missing. When do you expect to add invoice generation like it is at ZAPIER?


Hey @Dominik_Stefanski,

It would be great to see this feature natively integrated into ActivePieces. I personally use Invoice Ninja a lot as well and for now you could utilize Invoice Ninja’s API to achieve invoice creation.

Here’s a brief overview:

1. API Endpoint: /api/v1/invoices/create
2. HTTP Method: GET
3. Required Headers:

  • X-Api-Token: Your API token for authentication.
  • X-Requested-With: This should be set to XMLHttpRequest.

The response to this endpoint gives you a blank invoice object which you can then populate and send back to Invoice Ninja for creating an actual invoice.

Here’s a direct link to the detailed documentation: Invoice Ninja API Documentation. It has all the detailed parameters and potential responses that you might need.

If you’re familiar with setting up HTTP requests in ActivePieces, this should be quite straightforward. If you need any help or guidance setting it up, don’t hesitate to ask😊

@Dennis Wow!
Thanks for the answer. I have never used the build API. I don’t have such skills. How to start exploring the topic?

EDIT:
ChatGPT helped me with the code :slight_smile:
Is it correct? What type of Trigger i should put?

const axios = require(‘axios’);

// Konfiguracja API
const API_ENDPOINT = ‘…’;
const API_TOKEN = ‘…’;

// Ustawienie nagłówków
const headers = {
‘X-Api-Token’: API_TOKEN,
‘X-Requested-With’: ‘XMLHttpRequest’
};

// Funkcja do tworzenia pustej faktury
async function createEmptyInvoice() {
try {
const response = await axios.get(API_ENDPOINT, { headers: headers });
const invoice = response.data;
console.log(‘Pusta faktura:’, invoice);
return invoice;
} catch (error) {
console.error(‘Błąd podczas tworzenia pustej faktury:’, error);
}
}

// Wywołanie funkcji
createEmptyInvoice();

Hey,

Based on the screenshots you provided, it appears you might be wanting to trigger the invoice creation after a new payment in Stripe. Is that correct?

If so, here’s how you can set it up in ActivePieces:

Trigger: New Payment in Stripe (or any other relevant trigger if my assumption isn’t right)

Next, add an API step with an HTTP request, configured as follows:

Action: Send HTTP request
Method: POST
URL: https://YOUR-IN-DOMAIN.com/api/v1/invoices

Headers:
X-Api-Token - YOUR API KEY
X-Requested-With - XMLHttpRequest
Content-Type - application/json

Body (this is a very basic example, adjust the parameters based on your needs):

{
  "client_id": "CLIENT-ID",
  "line_items": [
    {
      "product_key": "ProductNameHere",
      "cost": 10,
      "quantity": 1,
      "tax_name1": "VAT",
      "tax_rate1": 21
    }
  ]
}

After setting up the above, test it out to ensure everything is working smoothly. If you encounter any issues or have further questions, don’t hesitate to ask!

Hey!
Many thanks! I tried your combination and got sample data as below.
Correctly found my test payment! :slight_smile:
It says failed but I think it is ok?
I wonder how to enter the date. I want it to issue a document with the day on which the payment is made. I can’t find this in the documentation you sent me. There is a fixed date and I need the current date always.

Hi Dominik,

Are you still in the process of generating the invoice? The date parameters for invoices are as follows:

  "date": "1994-07-30",
  "last_sent_date": "1994-07-30",
  "next_send_date": "1994-07-30",
  "partial_due_date": "1994-07-30",
  "due_date": "1994-07-30",

To mark the paid date I’d recommend first generating the invoice, and in a next step marking the invoice as paid with a date extracted from Stripe step (really easy to do with a HTTP request).

Lastly, did the test invoice appear correctly and link to the appropriate client on your IN dashboard? It shouldn’t produce any errors.

Hi @Dominik_Stefanski,

A couple of points to note:

  1. Token Security:

    • You might want to remove this API key from your post and generate a new one in Invoice Ninja (if that’s your actual key) for security reasons.
  2. Client ID:

    • I see you put "client_id": "Dominik Stefanski". The client_id should be a unique code associated with the client, not their name.
  3. Client Creation:

    • Is the client “Dominik Stefanski” already present in your Invoice Ninja dashboard? If he’s a new client, you’ll need to create him first. Here’s how you can add a new client using another HTTP step:

      Method: POST
      URL: https://in.example.com/api/v1/clients
      Headers:
      X-API-TOKEN - Your API Token
      X-Requested-With - XMLHttpRequest

      Body:

      {
        "city": "",
        "name": "",
        "address1": "",
        "contacts": [
          {
            "email": "",
            "phone": "",
            "last_name": "",
            "first_name": ""
          }
        ],
        "postal_code": "",
        "private_notes": "",
        "shipping_city": "",
        "shipping_address1": "",
        "shipping_postal_code": ""
      }
      

      This is just a basic structure. Adjust the parameters based on your needs. Check the documention here for all paramters.

Once the client is created, you should be provided with a unique client_id which you can then use to create the invoice.

Hope this helps! If you need any more assistance, don’t hesitate to ask.

Thank U very much for help!
Its working! But there is few informations that are missing even that i type it in the body section.

  1. “terms”: “Sposób płatności: Stripe, Metoda płatności: {{trigger[‘payment_method_details’][‘type’]}}”
  2. “public_notes”: “Dziękujemy za zamówienie i polecamy się na przyszłość :)”,
  3. “line_items”: “Audyt/Świadectwo charakterystyki energetycznej”
  4. Amount is 500 but it should be 5. Don’t know why there is “,” missing it should be 5,00

Input

{
  "url": "https://xxxxx.invoicing.co/api/v1/invoices",
  "body": {
    "client_id": "xxxx,
    "line_items": [
      {
        "cost": 500,
        "date": "1994-07-30",
        "terms": "Sposób płatności: Stripe, Metoda płatności: blik",
        "footer": "Właścicielem portalu certyfikat-cieplny.pl jest Rns Group Sp z o.o. z siedzibą w Warszawie, NIP: 5272753791",
        "due_date": "1994-07-30",
        "quantity": 1,
        "tax_name1": "VAT",
        "tax_rate1": 23,
        "line_items": "Audyt/Świadectwo charakterystyki energetycznej",
        "product_key": "SCHE",
        "public_notes": "Dziękujemy za zamówienie i polecamy się na przyszłość :)"
      }
    ]
  },
  "method": "POST",
  "headers": {
    "X-Api-Token": "P35p9WEokuUSBge9M4ogsa7MAilJQ3edXgKHT9gU6sWlfEpcbukkCYPP5AKBd6W6",
    "Content-Type": "application/json",
    "X-Requested-With": "XMLHttpRequest"
  },
  "failsafe": true,
  "queryParams": {}
}

Output

{
  "status": 200,
  "headers": {
    "date": "Tue, 24 Oct 2023 10:45:10 GMT",
    "content-type": "application/json",
    "transfer-encoding": "chunked",
    "connection": "close",
    "x-api-version": "5.0.16",
    "x-app-version": "5.7.33",
    "cache-control": "no-cache, private",
    "x-ratelimit-limit": "300",
    "x-ratelimit-remaining": "298",
    "access-control-allow-origin": "*",
    "access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
    "access-control-allow-headers": "X-React,X-API-PASSWORD-BASE64,X-API-COMPANY-KEY,X-API-SECRET,X-API-TOKEN,X-API-PASSWORD,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Disposition,Range,X-CSRF-TOKEN,X-XSRF-TOKEN,X-LIVEWIRE",
    "access-control-expose-headers": "X-APP-VERSION,X-MINIMUM-CLIENT-VERSION,Content-Disposition",
    "x-minimum-client-version": "5.0.16",
    "cf-cache-status": "DYNAMIC",
    "report-to": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=aJcJz1e0ZXIWzYMKW6rA6B2MlIJrow7NQwP4fr2kj0br%2FkCJJkkTGhkKQA0wf9UN0z1wuJxoEgPlvJKlK2XuN%2Fg6iLPh78Z8VhTF0IS7qz3pVvrGOVmBz2RB9nCg8y%2Bg%2Fa9R5VoefZKF6rXGIVvrm8U%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
    "nel": "{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}",
    "set-cookie": "__cflb=02DiuEfyB3LaZ68PDyiaiNRbKQb1mWFBusq2M1LN8FFjA; SameSite=Lax; path=/; expires=Wed, 25-Oct-23 09:45:10 GMT; HttpOnly",
    "server": "cloudflare",
    "cf-ray": "81b1a0f40f839a35-FRA"
  },
  "body": {
    "data": {
      "id": "negLQz43aw",
      "user_id": "y5eVmJnMdE",
      "project_id": "",
      "assigned_user_id": "",
      "amount": 500,
      "balance": 0,
      "client_id": "nelYGwY6aK",
      "vendor_id": "",
      "status_id": "1",
      "design_id": "Wpmbk5ezJn",
      "recurring_id": "",
      "created_at": 1698144310,
      "updated_at": 1698144310,
      "archived_at": 0,
      "is_deleted": false,
      "number": "53/CC/10/2023",
      "discount": 0,
      "po_number": "",
      "date": "2023-10-24",
      "last_sent_date": "",
      "next_send_date": "",
      "due_date": "",
      "terms": "",
      "public_notes": "",
      "private_notes": "",
      "uses_inclusive_taxes": true,
      "tax_name1": "",
      "tax_rate1": 0,
      "tax_name2": "",
      "tax_rate2": 0,
      "tax_name3": "",
      "tax_rate3": 0,
      "total_taxes": 93.5,
      "is_amount_discount": true,
      "footer": "Właścicielem portalu certyfikat-cieplny.pl jest Rns Group Sp z o.o. z siedzibą w Warszawie, NIP: 5272753791",
      "partial": 0,
      "partial_due_date": "",
      "custom_value1": "",
      "custom_value2": "",
      "custom_value3": "",
      "custom_value4": "",
      "has_tasks": false,
      "has_expenses": false,
      "custom_surcharge1": 0,
      "custom_surcharge2": 0,
      "custom_surcharge3": 0,
      "custom_surcharge4": 0,
      "exchange_rate": 1,
      "custom_surcharge_tax1": false,
      "custom_surcharge_tax2": false,
      "custom_surcharge_tax3": false,
      "custom_surcharge_tax4": false,
      "line_items": [
        {
          "cost": 500,
          "date": "1994-07-30",
          "terms": "Sposób płatności: Stripe, Metoda płatności: blik",
          "footer": "Właścicielem portalu certyfikat-cieplny.pl jest Rns Group Sp z o.o. z siedzibą w Warszawie, NIP: 5272753791",
          "due_date": "1994-07-30",
          "quantity": 1,
          "tax_name1": "VAT",
          "tax_rate1": 23,
          "line_items": "Audyt/Świadectwo charakterystyki energetycznej",
          "product_key": "SCHE",
          "public_notes": "Dziękujemy za zamówienie i polecamy się na przyszłość :)",
          "type_id": "1",
          "tax_id": "1",
          "product_cost": 0,
          "notes": "",
          "discount": 0,
          "is_amount_discount": true,
          "tax_name2": "",
          "tax_rate2": 0,
          "tax_name3": "",
          "tax_rate3": 0,
          "sort_id": "0",
          "line_total": 500,
          "gross_line_total": 500,
          "tax_amount": 93.5,
          "custom_value1": "",
          "custom_value2": "",
          "custom_value3": "",
          "custom_value4": "",
          "task_id": "",
          "expense_id": ""
        }
      ],
      "entity_type": "invoice",
      "reminder1_sent": "",
      "reminder2_sent": "",
      "reminder3_sent": "",
      "reminder_last_sent": "",
      "paid_to_date": 0,
      "subscription_id": "",
      "auto_bill_enabled": false,
      "tax_info": {},
      "invitations": [
        {
          "id": "xxxx",
          "client_contact_id": "7e58q5nZd2",
          "key": "xxxx",
          "link": "https://xxxx.invoicing.co/client/invoice/xxxx",
          "sent_date": "",
          "viewed_date": "",
          "opened_date": "",
          "updated_at": 1698144310,
          "archived_at": 0,
          "created_at": 1698144310,
          "email_status": "",
          "email_error": ""
        }
      ],
      "documents": []
    }
  }
}

WRONG

CORRECT

What im missing? :sweat_smile:

Hi Dominik_Stefanski,

I’ve taken a look at your issue and here’s what I found and suggest:

  1. Missing Info: You might be placing some properties inside the "line_items" array that don’t actually belong there. Instead, they should be directly under the invoice object.

  2. Amount Format: The format seems to use a period ‘.’ as a decimal separator. If you’re trying to represent 5,00, it should be 5.00.

  3. Description: I’ve added the “Audyt/Świadectwo charakterystyki energetycznej” note to the line item as you mentioned.

Here’s a corrected structure:

{
  "url": "https://xxxxx.invoicing.co/api/v1/invoices",
  "body": {
    "client_id": "xxxx",
    "date": "1994-07-30",
    "due_date": "1994-07-30",
    "terms": "Sposób płatności: Stripe, Metoda płatności: blik",
    "public_notes": "Dziękujemy za zamówienie i polecamy się na przyszłość :)",
    "footer": "Właścicielem portalu certyfikat-cieplny.pl jest Rns Group Sp z o.o. z siedzibą w Warszawie, NIP: 5272753791",
    "line_items": [
      {
        "cost": 5.00,
        "date": "1994-07-30",
        "quantity": 1,
        "tax_name1": "VAT",
        "tax_rate1": 23,
        "product_key": "SCHE",
        "notes": "Audyt/Świadectwo charakterystyki energetycznej"
      }
    ]
  },
  "method": "POST",
  "headers": {
    "X-Api-Token": "P35p9WEokuUSBge9M4ogsa7MAilJQ3edXgKHT9gU6sWlfEpcbukkCYPP5AKBd6W6",
    "Content-Type": "application/json",
    "X-Requested-With": "XMLHttpRequest"
  },
  "failsafe": true,
  "queryParams": {}
}

Oh! I see!

  1. Missing Info: You might be placing some properties inside the "line_items" array that don’t actually belong there. Instead, they should be directly under the invoice object.

I tried different placement of the data but didn’t come across this! Thank you!

  1. Amount Format: The format seems to use a period ‘.’ as a decimal separator. If you’re trying to represent 5,00, it should be 5.00.

But the trigger is from the stripe

Is it possible to add “,” or “.” between price? before making invoice? amount is 500 but it is 5. Its deleting the comma, so final price is also with “00”. I have the same issue when i collecting the data from stripe to my google sheets doc

Ah, understood. The easiest way to solve this would probably be to add a step beforehand and convert the comma to a period:

Working perfectly! :smile:

Now the invoice is in draft form. How can I make its status do paid and send an automatic email with the invoice?

I tried to use this one

{
“id”: “{{step_2[‘request’][‘body’][‘client_id’]}}”,
“date”: “1994-07-30”,
“transaction_reference”: “{{trigger[‘id’]}}”,
“is_manual”: true,
“is_deleted”: true,
“amount”: “{{step_3}}”,
“refunded”: 0,
“updated_at”: “{{step_1[‘body’][‘data’][‘contacts’][0][‘updated_at’]}}}}”,
“archived_at”: “{{step_1[‘body’][‘data’][‘archived_at’]}}}}”,
“company_gateway_id”: “3”,
“paymentables”: {
“id”: “{{step_2[‘request’][‘body’][‘client_id’]}}”,
“refunded”: 0,
“amount”: “{{step_3}}”,
“updated_at”: “{{step_1[‘body’][‘data’][‘contacts’][0][‘updated_at’]}}}}”,
“created_at”: “{{step_1[‘body’][‘data’][‘created_at’]}}}}”
}
}

but it doesn’t work :sweat_smile:

Hey Dominik,

I’m glad to hear things are working out for you!

  1. Marking the Invoice as Paid:

    {
      "amount": "5", //not sure if this is needed, you can try without first
      "invoices": [
        {
          "amount": "5",
          "invoice_id": "your-invoice-id-here"
        }
      ],
      "client_id": "your-client-id-here" //same about this
    }
    
    
  2. Sending the Invoice via Email: To send the invoice via email, you’ll want to use the /api/v1/emails endpoint. Here’s how you can format your API call:

{
 "subject": "Your Invoice from Us",
 "body": "Hello, please find attached the invoice for our recent services. Let us know if you have any questions.",
 "entity": "invoice",
 "entity_id": "your-invoice-id-here",
 "template": "your-email-template-name-here"
}

For the headers in both calls, don’t forget to include:

X-Api-Token: API
X-Requested-With: XMLHttpRequest

I haven’t used the email part before, so I’m not sure if this will work.

Hello!

I am refreshing the topic. I had some more work and zapier was covering invoicing so it was not my priority. I continue to have a problem with the payment status. I have diagnosed that I do not have access to the numerous data that are generated after issuing an invoice. The code you suggested might work only I don’t have access to the “invoice_id”. Where can I find or how do I extract the data?

{
  "status": 200,
  "headers": {
    "date": "Mon, 20 Nov 2023 11:01:20 GMT",
    "content-type": "application/json",
    "transfer-encoding": "chunked",
    "connection": "close",
    "x-api-version": "5.0.16",
    "x-app-version": "5.7.47",
    "cache-control": "no-cache, private",
    "x-ratelimit-limit": "300",
    "x-ratelimit-remaining": "298",
    "access-control-allow-origin": "*",
    "access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
    "access-control-allow-headers": "X-React,X-API-PASSWORD-BASE64,X-API-COMPANY-KEY,X-API-SECRET,X-API-TOKEN,X-API-PASSWORD,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Disposition,Range,X-CSRF-TOKEN,X-XSRF-TOKEN,X-LIVEWIRE",
    "access-control-expose-headers": "X-APP-VERSION,X-MINIMUM-CLIENT-VERSION,Content-Disposition",
    "x-minimum-client-version": "5.0.16",
    "cf-cache-status": "DYNAMIC",
    "report-to": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=5UVUCtDisam9oOlRH9XTx84aWk%x%2Bn0bvUF87zvDK1F2%2FFhmDzyv2mRNPJBbVLEN%2F9tm%2BG22Xkf%2FcrOP2qs3SIhupQA%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
    "nel": "{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}",
    "set-cookie": "__cflb=02DiuEfyB3LaZ68PDyjQJzqRsUgt5JqJMV4EB9RcQ3D48; SameSite=Lax; path=/; expires=Tue, 21-Nov-23 10:01:20 GMT; HttpOnly",
    "server": "cloudflare",
    "cf-ray": "829031bf992c3651-FRA"
  },
  "body": {
    "data": {
      "id": "YerRVM34eO",
      "user_id": "y5eVmJnMdE",
      "project_id": "",
      "assigned_user_id": "",
      "amount": 5,
      "balance": 0,
      "client_id": "mbkRqERJaz",
      "vendor_id": "",
      "status_id": "1",
      "design_id": "Wpmbk5ezJn",
      "recurring_id": "",
      "created_at": 1700478080,
      "updated_at": 1700478080,
      "archived_at": 0,
      "is_deleted": false,
      "number": "18/CC/11/2023",
      "discount": 0,
      "po_number": "",
      "date": "2023-11-20",
      "last_sent_date": "",
      "next_send_date": "",
      "due_date": "",
      "terms": "Sposób płatności: Stripe, Metoda płatności: blik",
      "public_notes": "Dziękujemy za zamówienie i polecamy się na przyszłość :)",
      "private_notes": "",
      "uses_inclusive_taxes": true,
      "tax_name1": "",
      "tax_rate1": 0,
      "tax_name2": "",
      "tax_rate2": 0,
      "tax_name3": "",
      "tax_rate3": 0,
      "total_taxes": 0.93,
      "is_amount_discount": true,
      "footer": "Właścicielem portalu xxxx Warszawie, NIP: xxxx",
      "partial": 0,
      "partial_due_date": "",
      "custom_value1": "",
      "custom_value2": "",
      "custom_value3": "",
      "custom_value4": "",
      "has_tasks": false,
      "has_expenses": false,
      "custom_surcharge1": 0,
      "custom_surcharge2": 0,
      "custom_surcharge3": 0,
      "custom_surcharge4": 0,
      "exchange_rate": 1,
      "custom_surcharge_tax1": false,
      "custom_surcharge_tax2": false,
      "custom_surcharge_tax3": false,
      "custom_surcharge_tax4": false,
      "line_items": [
        {
          "cost": 5,
          "date": "1994-07-30",
          "notes": "Audyt/Świadectwo charakterystyki energetycznej",
          "due_date": "1994-07-30",
          "quantity": 1,
          "tax_name1": "VAT",
          "tax_rate1": 23,
          "product_key": "SCHE",
          "type_id": "1",
          "tax_id": "1",
          "product_cost": 0,
          "discount": 0,
          "is_amount_discount": true,
          "tax_name2": "",
          "tax_rate2": 0,
          "tax_name3": "",
          "tax_rate3": 0,
          "sort_id": "0",
          "line_total": 5,
          "gross_line_total": 5,
          "tax_amount": 0.93,
          "custom_value1": "",
          "custom_value2": "",
          "custom_value3": "",
          "custom_value4": "",
          "task_id": "",
          "expense_id": ""
        }
      ],
      "entity_type": "invoice",
      "reminder1_sent": "",
      "reminder2_sent": "",
      "reminder3_sent": "",
      "reminder_last_sent": "",
      "paid_to_date": 0,
      "subscription_id": "",
      "auto_bill_enabled": false,
      "tax_info": {},
      "invitations": [
        {
          "id": "QeZVMqm2ep",
          "client_contact_id": "5eVPpQAobE",
          "key": "xxxx",
          "link": "https:/xxxx.invoicing.co/client/invoice/xxx",
          "sent_date": "",
          "viewed_date": "",
          "opened_date": "",
          "updated_at": 1700478080,
          "archived_at": 0,
          "created_at": 1700478080,
          "email_status": "",
          "email_error": "",
          "message_id": ""
        }
      ],
      "documents": []
    }
  }
}