Skip to main content

Notifications

Small and medium business | Business Central, N...
Unanswered

Array in API POST

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all,

I am populating a line items related to a Job table using Custom API. My custom API is working fine with GET, PATCH, POST when I send single record. However, in my case I would like to send multiple lines. Is it possible to have array of items in JSON in BC Custom API? I am using version 16.x but soon will be upgrading to 19.1

Let me know if anyone come across same requirement in one of your project.

Table: Job (will be created by end user)

Table: Job Lines ( I would like to populate using API)

{
"value": [
{

"JobNo": "A00600",
"LineNo": 2000,
"CostType": "Material",
"Quantity": 10,

"Price" : 100

}
]
}

I tried array in POST but no luck, getting message back from API

"message": "An unexpected 'StartArray' node was found when reading from the JSON reader. A 'StartObject' node was expected.  CorrelationId:  6ec8513d-5334-471f-a3a1-fdb4b82d97ab."

[

 {

  Payload

 },

 {

  Payload

 }

]

Best Regards,

Farooq 

  • RE: Array in API POST

    Hello,

    You can insert multiple lines using json arrays. Here is an example from the standard api purchaseOrders where we insert one order with 2 lines and 2 dimensions (update ItemID to match your own items):

    POST MyPC:7048/.../purchaseOrders

    HEADER:

    Content-Type = application/json

    BODY

        {  

                        "vendorNumber": "20000",

                        "purchaseOrderLines":

                        [

                          {"itemId" : "7192b134-2a0f-ed11-b845-6045bd8e5eb4"},

                          {"itemId" : "7392b134-2a0f-ed11-b845-6045bd8e5eb4"}

                        ],

                                            "dimensionSetLines":

                        [

                            {

                          "code": "DEPARTMENT",

                           "valueCode": "SALES"

                            }

                         ]

        }

    or maybe its just the syntax of the array that is missing a ,{( or somethien else?

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans