You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dynamics 365 API v2:如何向现有销售订单添加销售行?

解决Dynamics 365 Business Central API添加销售订单行的“Invalid Request Body”错误

核心问题分析

  • 请求体格式错误:你提交的是数组格式,但标准API的salesOrderLines POST接口默认仅接受单个销售行对象(批量新增需使用专门的批量操作语法)。
  • 重复ID冲突:两个销售行使用了完全相同的id值,新增行无需手动指定id(系统会自动生成唯一标识),手动指定重复ID会触发校验失败。
  • 端点路径有误:关联现有销售订单添加行的正确端点是companies({companyId})/salesOrders({documentId})/salesOrderLines(注意是复数salesOrders,而非单数salesOrder)。

正确请求示例

单个销售行新增(适合拆分行项目提交)

端点

POST companies({companyId})/salesOrders({documentId})/salesOrderLines

请求体

{
  "lineType": "Item",
  "lineObjectNumber": "H10-110013",
  "quantity": 1
}

批量新增销售行(如需一次性提交多行)

若要批量添加多行,需使用OData批量操作,具体格式如下:

请求头

Content-Type: multipart/mixed; boundary=batch_unique_id

请求体

--batch_unique_id
Content-Type: application/http
Content-Transfer-Encoding: binary

POST companies({companyId})/salesOrders({documentId})/salesOrderLines HTTP/1.1
Content-Type: application/json

{"lineType": "Item", "lineObjectNumber": "H10-110013", "quantity": 1}

--batch_unique_id
Content-Type: application/http
Content-Transfer-Encoding: binary

POST companies({companyId})/salesOrders({documentId})/salesOrderLines HTTP/1.1
Content-Type: application/json

{"lineType": "Item", "lineObjectNumber": "H10-112117", "quantity": 1}

--batch_unique_id--

关键注意事项

  • 新增销售行时不要手动指定id字段,由系统自动生成唯一ID。
  • 拆分提交时,建议对每个销售行单独发送POST请求,既能避免批量操作的复杂度,又能规避大请求限制。
  • 确保请求头的Content-Type正确设置:单个请求为application/json,批量请求为multipart/mixed; boundary=xxx。

内容的提问来源于stack exchange,提问作者Ryan Fox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 16:50:25