web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Web API Bad Request creating Address record (customeraddress)

(0) ShareShare
ReportReport
Posted on by 40

Hi all,

I'm receiving a Status Code 400: Bad Request error when trying to create a new Address record using the Web API. I'm able to authenticate as expected and when I change my JSON to create an account record it works perfectly.

I've tried the following for my JSON:

JObject newAddress = new JObject
{
{"Name", "Address Test"},
{"addresstypecode", 1},
{"Line1", "Line 1"},
{ "ParentId_contact@odata.bind","/contacts(b1d5e428-e130-e811-812f-e0071b6e06c1)"},
{"ObjectTypeCode", 2}
};

Any suggestions helpful!

Thanks,
Vikesh

*This post is locked for comments

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at
    RE: Web API Bad Request creating Address record (customeraddress)

    At a first glance, shouldn't it be AddressTypeCode ?

    And to clarify, does the code that works create an account record, or an Address record for the account ?

  • Vikesh Profile Picture
    40 on at
    RE: Web API Bad Request creating Address record (customeraddress)

    Hi David,

    Thanks! I've changed the casing on AddressTypeCode,  but still getting the same error.

    It works when creating an Account record, I'm not able to create any Address records at all.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Web API Bad Request creating Address record (customeraddress)

    Hi Vikash,

    You need to create object with scema name of the fields PrimaryContactName .

    Please replace with PrimaryContactName .

    Hope ths helps.

  • Vikesh Profile Picture
    40 on at
    RE: Web API Bad Request creating Address record (customeraddress)

    Hi Goutam,

    Thanks for your response. I've added PrimaryContactName, not sure what data to map to this field? I tried the fullname of the contact I'm linking the Address too and an empty string, both gave the same 400 Bad Request error.

    JObject newAddress = new JObject

    {

      {"Name", "Address Test"},

      {"AddressTypeCode", 1},

      {"Line1", "Line 1"},

      { "ParentId_contact@odata.bind","/contacts(b1d5e428-e130-e811-812f-e0071b6e06c1)"},

      {"ObjectTypeCode", 2},

      {"PrimaryContactName", ""}

                   };

    Any other info/ideas?

    Vikesh

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Web API Bad Request creating Address record (customeraddress)

    Hi Vikash,

    Try to make simple your object to avoid the error first - Here is simple JSON just replace the id (highlighted in red) of contact lookup in Address entity.  Seems "ParentId_contact" is not correct one.

    var newAddress = JSON.stringify({
        "Name": "AddressTest",
        "Line1": "30 Avenue",
        "primarycontactid@odata.bind": "/contacts(b1d5e428-e130-e811-812f-e0071b6e06c1)" // Chnage your lookup id accordingly.
    });


    Hope this helps.

  • Vikesh Profile Picture
    40 on at
    RE: Web API Bad Request creating Address record (customeraddress)

    Hi Goutam,

    Thanks for your response, ParentId is the only available lookup field that points to the Contact entity. As far as I know this field is used to lookup to the Account, Contact and Lead entities in conjunction with the ObjectTypeCode field, which I've set to 2 for the Contact entity.

    I've also tried this with an account record (ObectTypeCode = 1) but still receive the bad request error:

                   {

                       {"Name", "Address Test"},

                       {"Line1", "Line 1"},

                       { "ParentId_account@odata.bind","/accounts(580448F4-8805-E811-8129-E0071B6E06C1)"},

                       {"ObjectTypeCode", 1}

                   };

    Any help appreciated.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Web API Bad Request creating Address record (customeraddress)

    Hi Vikash,

    Could you please create one Contact lookup in Address entity and try to use that lookup . Please use the format which I have shared in my earlier post.

  • Vikesh Profile Picture
    40 on at
    RE: Web API Bad Request creating Address record (customeraddress)

    Hi,

    Microsoft have blocked the ability to add any custom relationships to the Address entity in CRM. The existing ParentId lookup field is the only option which doesn't seem to work very well. Has anybody managed to get this working through the API? Seems like it should be a simple call to create additional addresses on contacts/accounts.

  • Verified answer
    Vikesh Profile Picture
    40 on at
    RE: Web API Bad Request creating Address record (customeraddress)

    I fixed it!

    parentid was the correct field after all.

    It turns out it was a combo of issues:

    Casing (I needed everything to be lowercase)

    Objecttypecode - This field needs to be entered as text "contact" or "account" we can't use the objecttypecode numeric values here (1 and 2) .

    Sample of working Web API call:

                       {"parentid_contact@odata.bind","/contacts(b1d5e428-e130-e811-812f-e0071b6e06c1)"},

                       {"objecttypecode", "contact"},

                       {"addresstypecode", 2}

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans