OData PATCH request shouldn't fail when a referenced record is not found

347 views Asked by At

I am quite new to OData services and am working on an integration between an ERP and CRM application. When using Postman, I run into the following problem...

  • I have 2 data entities to sync: Contacts and Accounts.

  • Whenever I pass an account, I need to bind the Primary Contact No. to the account. My Request to do this (stripped of unnecessary data:

  • Using PATCH requests to upsert the accounts, I find that, whenever a Contact does not exist, I receive the following error and the request is not executed:

REQUEST:

PATCH:https://{baseurl}/accounts(externalaccountnumber='12345')
{
   "name": "changed name here",
   "[email protected]": "https://{baseurl}/contacts(externalcontactnumber='CT54321')"
}


RESPONSE:

{
    "error": {
        "code": "0x80060891",
        "message": "A record with the specified key values does not exist in contact entity"
    }
}

This response is true, because the data in the ERP is not always 100% correct... (SiSo / GiGo / RiRo / all of the above)

Is it possible to apply the rest of the PATCH (in this example the name field) even though the @odata.bind action can't be processed correctly?

I haven't been able to find any similar questions, and was not yet able to come up with a proper solution.

Looking forward to your brilliant minds!

1

There are 1 answers

0
Daryl On

You could do what you describe with a plugin in the prevalidation stage on the server or a custom API, but I don't recommend it. What you really want to do is get all your erp contacts first, create them in CRM, then create the accounts, where the contacts are already in CRM because you already created them. You could use and create an alternate key on the contract