In Postman I can POST request successfully with this raw data:
{
"relatedContact@odata.bind": "Contacts(3b36c706-6a6c-414f-8f5f-ed24fc9a5aa2)",
"stringName": "Shrek Rattle"
}
This will insert 3b36c706-6a6c-414f-8f5f-ed24fc9a5aa2
into the relatedContact
column and 'Shrek Rattle' in stringName column of the PreferenceManagement
table. Contact
and PreferenceManagement
tables have a one-to-many relationship via ContactId
from Contact
table and relatedContact
in the PreferenceManagement
table.
This is working fine when trying in Postman, and I'm able to see the posted records in PreferenceManagement
table in the database.
My problem is, HOW can I apply this same functionality in .NET 6 using C#?
From Swagger/UI, I tried sending that same post request but I always get a '400 Bad Request' result!
Note: when calling PostAsync for table that doesn't have foreign key values to be inserted, it's also working just fine. For example, if I just enter { "stringName": "Shrek Rattle" }
in Swagger/UI and click the Post
button, I'm not getting any issue in my code and the data is posted into the PreferenceManagement
table, but with a null relatedContact
value. But I need that relatedContact
value as it will relates the Contact
records to the Preference
records.
Any thoughts? Thanks in advance for any help, suggestions, and recommendations!
- I created the code in ASP.NET Core 6 using C#.
- We have Contact, and
PreferenceManagement
tables in Dynamics CRM. - In PreferenceManagementtable has the
stringName
andrelatedContact
columns that needs to be populated when making aPOST
request - I created a
PreferenceManagement
class with just two string properties (stringName, relatedContact
).
Supplied values in Swagger/UI:
{
"relatedContact": "3b36c706-6a6c-414f-8f5f-ed24fc9a5aa2",
"stringName": "Shrek Rattle"
}
I'm expecting that the values will be inserted in the respective columns of the PreferenceManagement
table. But I'm always getting 400 Bad Request exception.