Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create annotation to a contact entity in Microsoft Dynamics CRM by API

Tags:

This question is related to Microsoft Dynamics CRM 2015, that I'm calling through API.

I create contact entity:

POST [organization URI]/api/data/contacts
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "emailaddress1": "[email protected]",
}

It works, I see new record, after I log into the panel. And I can call it through the API:

[organization URI]/api/data/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)
{
  "@odata.context":"[organization URI]/api/data/$metadata#contacts/$entity",
  "@odata.etag":"W/\"460199\"",
  ...
  "contactid":"f76e4e7c-ea61-e511-80fd-3863bb342b00",
  "emailaddress1":"[email protected]",
  ....
}

Next thing I want to do, is to add annotation record associated with that contact. Following the guide I call:

POST [organization URI]/api/data/annotations
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "notetext": "TEST",
    '[email protected]': 'contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)'
}

But it returns 400 error:

An undeclared property 'contact' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.

When I call:

POST [organization URI]/api/data/annotations
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "notetext": "TEST",
}

New entity is created, but without a relation to contact.

How to properly compose this POST request? What am I missing here? I suspect, that [email protected] should be presented somehow different, I've tried [email protected], [email protected], [email protected] - but no effects.

Any ideas?

like image 817
maicher Avatar asked Sep 24 '15 12:09

maicher


People also ask

How do I create a custom activity entity?

Navigate to Settings- Customizations- Customize the System to open the default solution. In the default solution, click on Entities, then Click New. Within your new entity, give it a name and description. Then, to activate as an activity, check the box for 'Define as an activity entity'.


2 Answers

Instead of using [email protected], you have to use [email protected]. This results are in:

"[email protected]": "/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)"

To get the list of properties, look under the single-valued navigation properties in the documentation.

like image 58
Justin Avatar answered Oct 11 '22 23:10

Justin


I've found this working, but in two requests:

POST [organization URI]/api/data/annotations
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "notetext": "TEST"
}

POST [organization URI]/api/data/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)/Contact_Annotation/$ref
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "@odata.id": "[organization URI]/annotations(annotation_id_from_first_request)"
}

Edit:

annotation_id_from_first_request value is taken form first request's response.

like image 22
maicher Avatar answered Oct 11 '22 21:10

maicher