crater-invoice / crater

Open Source Invoicing Solution for Individuals & Businesses
https://craterapp.com
GNU Affero General Public License v3.0
7.62k stars 1.53k forks source link

Undefined array key \"tax\" and items not shown on invoice with admin API call #1276

Open kenjibailly opened 6 months ago

kenjibailly commented 6 months ago

I'm trying to create an invoice using the admin API with nodejs. But I'm getting a response body message: Undefined array key \"tax\" I've tried a number of things, like setting the tax to a string, setting it to the ID of the tax type I have set in crater, giving it a higher number than 0, but they all result in the same error message. However the invoice does get created in Crater, but the items aren't there. I'm guessing this might have to do because I'm getting an error message.

I have used the default body code that can be found on the API documentation. (https://api-docs.craterapp.com/#admin-invoices-POSTapi-v1-invoices) All I have changed is the item ID to the item ID of that item which is 3. I have checked this by doing an API call and getting the items:

data: [
    {
      id: 3,
      name: 'Apple Macbook',
      description: 'Light and powerful laptop',
      price: 10000,
      unit_id: 1,
      company_id: 1,
      creator_id: 1,
      currency_id: 3,
      created_at: '2023-12-08T10:22:33.000000Z',
      updated_at: '2023-12-08T10:22:33.000000Z',
      tax_per_item: 0,
      formatted_created_at: '08 Dec 2023',
      unit: [Object],
      company: [Object],
      currency: [Object]
    }
  ],
  let body = {
    "invoice_date": "2022-02-13",
    "due_date": "2022-02-16",
    "customer_id": 1,
    "invoice_number": "INV-000001",
    "exchange_rate": 1,
    "discount_type": "fixed",
    "discount": 50,
    "discount_val": 5000,
    "sub_total": 10000,
    "total": 5000,
    "tax": 0,
    "template_name": "invoice1",
    "items": [
        {
            "name": "Apple Macbook",
            "quantity": 1,
            "price": 10000,
            "description": "Light and powerful laptop",
            "item_id": 3,
            "sub_total": 10000,
            "total": 10000,
            "unit_name": "box",
            "discount": 0,
            "discount_type": "fixed",
            "discount_val": 0,
        }
    ],
  };

I'm not sure how to fix this. What am I doing wrong? Is this a bug?

rihards-simanovics commented 5 months ago

quick reminder the software is abandonware and will no longer receive updates: https://github.com/crater-invoice/crater/issues/1265