I am working on creating custom API pages for SalesHeader and SalesLine in Dynamics 365 Business Central. While I am able to successfully create a Sales Quote (the SalesHeader), the associated SalesLine is not being created as expected. I am using the following structure to link the SalesLine to the SalesHeader:
part(salesLines; "SalesLine")
{
SubPageLink = "Document No." = field("No.");
}
Here is my JSON for creating a Sales Quote with a SalesLine:
POST https://api.businesscentral.dynamics.com/v2.0/{Sanbox Name}/api/{ApiPublisher}/{ApiGroup}/v1.0/companies({CompanyID})/SalesHeader
{
"billtocustomerno": "10000",
"documenttype": "Quote",
"selltocustomerno": "10000",
"salesLine": [
{
"area": "",
"description": "Iphone",
"genBusPostingGroup": "DOMESTIC",
"genProdPostingGroup": "RETAIL",
"itemCategoryCode": "CHAIR",
"itemReferenceNo": "",
"itemReferenceTypeNo": "",
"itemReferenceUnitOfMeasure": "",
"locationCode": "BLUE",
"netWeight": 0,
"no": "1000",
"quantity": 5,
"type": "Item",
"unitOfMeasure": "Piece",
"useDuplicationList": false
}
]
}
The Sales Quote is created successfully, but the SalesLine is not created. There are no errors in the response, and everything looks fine, but the SalesLine data doesn't appear.
I then attempted to post the SalesLine separately to the SalesHeader like this:
POST https://api.businesscentral.dynamics.com/v2.0/{Sanbox Name}/api/{ApiPublisher}/{ApiGroup}/v1.0/companies({CompanyID})/SalesHeader({SalesQuoteID})/SalesLine
{
"area": "",
"description": "Iphone",
"documentNo": "1021",
"documentType": "Quote",
"genBusPostingGroup": "DOMESTIC",
"genProdPostingGroup": "RETAIL",
"itemCategoryCode": "CHAIR",
"itemReferenceNo": "",
"itemReferenceTypeNo": "",
"itemReferenceUnitOfMeasure": "",
"locationCode": "BLUE",
"netWeight": 0,
"no": "1000",
"quantity": 5,
"type": "Item",
"unitOfMeasure": "Piece",
"useDuplicationList": false
}
However, I received this error:
{
"error": {
"code": "Internal_RecordNotFound",
"message": "The Standard Text does not exist. Identification fields and values: Code='1000' CorrelationId: fb5171a4-1b6c-49c2-a3bb-9d62955d229c."
}
}
Next, I tried removing the no field from the SalesLine data. The SalesLine was created successfully, but the item data was not reflected.
I also tried using the PATCH method to update the SalesLine, but the update did not seem to take effect.