web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

API v2.0 - Purchase Invoice Line - taxCode ignored

(3) ShareShare
ReportReport
Posted on by 6

) Context:

I am working with Business Central API v2 (Business Central 20.0 (Platform 20.0.37114.38150) to create and update purchaseInvoiceLines. However, I am experiencing issues with setting or modifying the taxCode field.

What I Have Tried:

  1. Creating a Purchase Invoice Line with taxCode
    • I make a POST request to:
      POST /purchaseInvoices({invoiceId})/purchaseInvoiceLines
      
      with the following payload:
      {
        "documentId": "37308e23-7fa6-ef11-a2e7-005056bed6cb",
        "accountId": "6539b815-4490-ef11-a2e6-005056bed6cb",
        "lineType": "Account",
        "lineObjectNumber": "73100",
        "description": "Igangværende arbejde",
        "unitCost": 200,
        "quantity": 1,
        "amountExcludingTax": 200,
        "taxCode": "FRITAGET"
      }
      
    • Result: The invoice line is created, but the taxCode field remains empty.

       
  2. Updating an Existing Line with taxCode
    • After creating a line, I try updating the taxCode via:
      PATCH /purchaseInvoices({invoiceId})/purchaseInvoiceLines({lineId})
      
      with:
      { "taxCode": "FRITAGET" }
      
    • Result: No error is returned, but the taxCode is not updated.

       
  3. Verifying taxCode and taxGroupId
    • I confirmed via:
      GET /companies({companyId})/taxGroups
      
      that "FRITAGET" is a valid tax group.

       
  4. Additional Tests
    • I verified that I can update other fields like quantity on the same line.
    • Manually setting the tax code in the BC UI works fine

Questions:

  1. Why does Business Central API ignore taxCode on purchaseInvoiceLines?
  2. Is taxCode read-only after creation? If so, how should it be assigned?
  3. Is there a workaround (e.g., using taxGroupId or another field) to ensure the correct tax code is applied?
  4. Are there specific conditions (e.g., posting groups, tax setups) that could prevent taxCode from being set via API but allow it in the UI?
  5. Is this behavior expected, or is it a limitation/bug in the BC API v2?
 
I would assume this was 100% basic functionality of any working ERP.
 
Thanks - any insights or official documentation references would be greatly appreciated.
  
I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,247 Super User 2025 Season 2 on at
    Please the below condition on that field, based on General Ledger Setup the value is copied to VAT Prod. Posting Group or Tax Group Code.
     
     
    field(taxCode; Rec."Tax Code")
                    {
                        Caption = 'Tax Code';
                        trigger OnValidate()
                        var
                            GeneralLedgerSetup: Record "General Ledger Setup";
                        begin
                            if GeneralLedgerSetup.UseVat() then begin
                                Rec.Validate("VAT Prod. Posting Group", CopyStr(Rec."Tax Code", 1, 20));
                                RegisterFieldSet(Rec.FieldNo("VAT Prod. Posting Group"));
                            end else begin
                                Rec.Validate("Tax Group Code", CopyStr(Rec."Tax Code", 1, 20));
                                RegisterFieldSet(Rec.FieldNo("Tax Group Code"));
                            end;
                        end;
                    }
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,647 Super User 2025 Season 2 on at
    The taxCode field isn't directly stored but mapped to either VAT Prod. Posting Group or Tax Group Code, based on the Use VAT setting in General Ledger Setup. The API likely ignores taxCode because it's validated and reassigned internally. Try updating VAT Prod. Posting Group (if VAT is enabled) or Tax Group Code (if VAT is disabled) instead of taxCode in your API request.
  • Suggested answer
    YUN ZHU Profile Picture
    95,748 Super User 2025 Season 2 on at
    Hi, you can try the following function.
     
    Thanks.
    ZHU
  • CU19021242-1 Profile Picture
    12 on at
    Hi,
     
    I have a very similar problem with the "taxCode" field when creating a purchase invoice through API V2.  What I'm finding is :
     
    1. If I populate "taxCode" with a 'VAT Prod. Posting Group' code which doesn't exist, I rightly get an "Internal_TableRelation" error because the value doesn't exist.
     
    2. If I populate "taxCode" with a 'VAT Prod. Posting Group' code which does exist, I get "The VAT Posting Setup does not exist.  Identification fields and values: VAT Bus. Posting Group='DOMESTIC',VAT Prod. Posting Group='' ".  So it thinks I have passed it a blank value for this field.
     
    Did you get anywhere with figuring out what the problem is?
     
    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,066

#2
YUN ZHU Profile Picture

YUN ZHU 658 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 595

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans