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_option
does not reveal a match) - The Contact exists AND the Contact’s
CompanyId
field has a value.
… then a PUT will cause these results:
- If
company_name
is provided butid
is not, the info will be dropped. - If
id
is provided, then regardless of whethercompany_name
is also provided, the Contact’sCompanyId
field will be set to the supplied value and the Contact’sCompany
field 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
CompanyId
field does NOT have a value AND the Contact’sCompany
field has a value. - The Contact exists AND its
CompanyId
field does NOT have a value AND the Contact’sCompany
field is empty.
… then a PUT will cause these results:
- If only
company_name
is provided, it will be dropped. - If
id
is provided, then regardless of whethercompany_name
is also provided, the Contact’sCompany
field will be set but the Contact’sCompanyId
field 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
id
field is provided and corresponds to a valid Company record, then regardless of the supplied value forcompany_name
, set the Contact’sCompanyId
field to the supplied value and theCompany
field to the value extracted from the Company record corresponding toid
. - If only
company_name
is provided, then zero out the Contact’sCompanyId
field and set the Contact’sCompany
field 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).