locked
How to set relationship for Account and Contact via REST API? RRS feed

  • Question

  • I'm working on integration software, which should create contacts in CRM. I can do it already, but I didn't get how to set relations for account?

    I send POST to ContactSet endpoint with this data:

    {
            "Telephone1": "222-333",
            "LastName": "Smith",
            "FirstName": "John",
            "EMailAddress1": "jonh@test.com",
            "AccountId": {
                "__metadata": {
                    "type": "Microsoft.Crm.Sdk.Data.Services.EntityReference"
                },
                "Id": "9dc28c45-e8cb-e411-80f5-c4346bad02e8"
            }
        }

    Contact is created, but in Account window I don't see this contact in contact's list

    Friday, March 20, 2015 10:43 AM

All replies

  • your query is missing the logicalname, also probably the syntax is not correct (but this depends if you are using a JS framework to help you with the REST queries)

    in my opinion the code will be:

    {
            "Telephone1": "222-333",
            "LastName": "Smith",
            "FirstName": "John",
            "EMailAddress1": "jonh@test.com",
            "AccountId": { Id: "9dc28c45-e8cb-e411-80f5-c4346bad02e8", LogicalName: "account", Name: "Account Name" }
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Friday, March 20, 2015 11:14 AM
  • I tried this data — nothing.

    After creation contact, I'm still getting this in response for just created contact:

    "AccountId": {
                "__metadata": {
                    "type": "Microsoft.Crm.Sdk.Data.Services.EntityReference"
                },
                "Id": null,
                "LogicalName": null,
                "Name": null
            },

    Any ideas how to fill it? Maybe CRM doesn't support setting relationships on the fly? I mean during create action.


    • Edited by slvrnight Friday, March 20, 2015 4:33 PM misstype
    Friday, March 20, 2015 4:31 PM