How to insert multiple rows in a Business Central API with a single call?

kuhikuhi Member Posts: 18
edited 2024-05-09 in NAV Tips & Tricks
I'm trying to insert a json with multiple records into Business Central via Web Services
page 60000 "Sales Order Inserts MIM API"
{
    PageType = API;
    SourceTable = "Sales Order Inserts MIM";
    Caption = 'Sales Order Inserts MIM API';
    EntitySetName = 'SalesOrderInserts';
    EntityName = 'SalesOrderInsert';
    APIPublisher = 'Kuhicop';
    APIGroup = 'Kuhicop';
    DelayedInsert = true; 
    APIVersion = 'v1.0';   

    layout
    {
        area(content)
        {
            repeater(Group)
            {
                field("BatchID"; Rec."Batch ID")
                {
                    ApplicationArea = All;
                }
            }
        }
    }
}

If I make a GET request, I see this response:
{
    "@odata.context": "https://api.businesscentral.dynamics.com/v2.0/{{TENANT_ID}}/{{ENVIRONMENT}}/api/Kuhicop/Kuhicop/v1.0/$metadata#companies({{COMPANY_ID}})/SalesOrderInserts",
    "value": [
        {
            "@odata.etag": "W/\"JzIwOzE1ODc4NzU5MDIzMDQyNDQyNTI1MTswMDsn\"",
            "BatchID": "BATCH001"
        },
        {
            "@odata.etag": "W/\"JzE5OzI3MTk3MjU4MTE5MDAwNDI1NTAxOzAwOyc=\"",
            "BatchID": "BATCH002"
        },
        {
            "@odata.etag": "W/\"JzE5OzgwMDc0MzY2NzQ0NjcxOTQxOTExOzAwOyc=\"",
            "BatchID": "BATCH003"
        }
    ]
}

Trying to insert from Postman against this URL: https://api.businesscentral.dynamics.com/v2.0/{{TENANT_ID}}/{{ENVIRONMENT}}/api/Kuhicop/Kuhicop/v1.0/companies({{COMPANY_ID}})/SalesOrderInserts

And based in the GET response, I will send a json With this data:
{
    "value": [
        {
            "BatchID": "BATCH004"
        },
        {
            "BatchID": "BATCH005"
        }        
    ]
}

But I get this error:
{
    "error": {
        "code": "BadRequest",
        "message": "The property 'value' does not exist on type 'Microsoft.NAV.salesOrderInsert'. Make sure to only use property names that are defined by the type.  CorrelationId:  a10912cb-7f47-4f38-b0a0-43f5dd595e3a."
    }
}

How to insert multiple rows in a Business Central custom API?
Sign In or Register to comment.