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

使用Web API向CRM自定义实体插入含Lookup字段记录时遇Bad Request错误

Fixing Bad Request Error When Setting Lookup Fields via Dynamics CRM Web API

Let's break down the issue and fix that bad request error you're seeing. The core problem here is how you're formatting the lookup field bindings in your JSON payload.

What Was Wrong with Your Original Payload

You tried using new_contactid_contact@odata.bind and new_moveid_new_move@odata.bind, but that's not the correct format for Web API lookup bindings. The Web API expects you to use the navigation property name (not a modified version with entity names) followed by @odata.bind.

Correct JSON Payload

From the OData metadata you shared, the navigation properties for your lookups are new_contactid and new_moveid (check the <NavigationProperty> elements). Here's the corrected payload:

{ 
  "new_transactionnumber":"114", 
  "new_transactionamount":650, 
  "new_transactiondate":"2018-01-29T15:01:00.000Z", 
  "new_contactid@odata.bind":"/contacts(afb9e006-6be5-e711-80ed-bef806786223)", 
  "new_moveid@odata.bind":"/new_moves(896f2dcd-b2fa-e711-80ef-bef806786223)" 
}

Why This Works

Looking at your OData metadata:

  • The <NavigationProperty Name="new_contactid" Type="mscrm.contact"...> explicitly defines that new_contactid is the navigation property linking to the contact entity. The @odata.bind suffix tells the Web API to establish this relationship using the specified contact record GUID.
  • The _new_contactid_value property you see is a read-only computed field (marked with <Annotation Term="Org.OData.Core.V1.Computed" Bool="true" />), so you can't use it to set the lookup value—you must use the navigation property binding instead.

Additional Checks to Ensure Success

  • Verify that the GUIDs for the contact and new_move records are valid and exist in your CRM instance.
  • Make sure your POST request is targeting the correct endpoint (e.g., /api/data/v9.2/new_transactions—adjust the API version and entity set name as needed).
  • Ensure your request headers include Content-Type: application/json and a valid authorization token.

内容的提问来源于stack exchange,提问作者I Love Stackoverflow

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:52:51