The behavior of contact PUT in the REST API with regards to company info is strange.
If either of the following are true…
- The Contact does not exist (i.e. the
duplicate_optiondoes not reveal a match) - The Contact exists AND the Contact’s
CompanyIdfield has a value.
… then a PUT will cause these results:
- If
company_nameis provided butidis not, the info will be dropped. - If
idis provided, then regardless of whethercompany_nameis also provided, the Contact’sCompanyIdfield will be set to the supplied value and the Contact’sCompanyfield will be set to the value taken from the Company record corresponding toid.
If either of these situations are true…
- The Contact exists AND its
CompanyIdfield does NOT have a value AND the Contact’sCompanyfield has a value. - The Contact exists AND its
CompanyIdfield does NOT have a value AND the Contact’sCompanyfield is empty.
… then a PUT will cause these results:
- If only
company_nameis provided, it will be dropped. - If
idis provided, then regardless of whethercompany_nameis also provided, the Contact’sCompanyfield will be set but the Contact’sCompanyIdfield will not.
I would expect that if a valid company id is supplied then the Contact’s CompanyId would be set to the supplied value – so I consider the second set of behaviors to be a bug.
From my point of view, the most desirable behavior would actually be something different, yet consistent across all create/update scenarios:
- If the
idfield is provided and corresponds to a valid Company record, then regardless of the supplied value forcompany_name, set the Contact’sCompanyIdfield to the supplied value and theCompanyfield to the value extracted from the Company record corresponding toid. - If only
company_nameis provided, then zero out the Contact’sCompanyIdfield and set the Contact’sCompanyfield to the supplied value.
That would greatly simplify using PUT to create a create or update a contact. Right now, in order not to lose Company information, I have to perform two additional API calls to the legacy XML RPC API in order to find or create a Company record ID before I can PUT a Contact.
I argue that this requested behavior is RESTFUL because in no circumstances does it cause the side effect of creating a Company record – only the values of the Contact record are affected.
(Edit: use the correct names for the Contact record fields according to the Table Schema Docs).