Case Owner gets rewritten while updating Case via REST API - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Dmytro ShevchenkoDmytro Shevchenko 

Case Owner gets rewritten while updating Case via REST API

We are using REST API to manage our SF Cases.
For some reason, when we change a Case's "Status" field via the API, the "Case Owner" field's value also changes to the "Default Case Owner", although the "Case Owner" field doesn't participate in the request at all. Moreover, the Case Owner changes to the default owner even if I explicitly specify a new OwnerId (referring to some particular user). Which looks quite weird to me.
Marco (werewolf) CasalainaMarco (werewolf) Casalaina
Did you turn on some debug logs at Setup | Administration Setup | Monitoring | Debug Logs?  Try updating a case via that API and then looking at the debug log.  My guess is that assignment rules are running due to your API transaction and are reassigning the case.

If my suspicion is true then you'll just have to turn off running assignment rules when updating these cases.  Unfortunately I do not know how to do so via the REST API and I can't find any documentation for it (it's quite simple for the regular API, just a header to set on the SOAP calls).
Laurent LabergeLaurent Laberge
Here's how to do it:

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_autoassign.htm
Eduardo Offermann PalmaEduardo Offermann Palma
Hi!, I have used the header that Laurent mention but it does not work for me. Does anybody could resolve this?

More technicals details:

   I am using "simple-salesforce (https://github.com/heroku/simple-salesforce)" library and I had to modify this line (https://github.com/heroku/simple-salesforce/blob/master/simple_salesforce/api.py#L122) for sending the additional header "Sforce-Auto-Assign" like that:

self.headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + self.session_id,
'X-PrettyPrint': '1',
'Sforce-Auto-Assign': 'FALSE'
}

 
Michael LaceyMichael Lacey
So I know this is old but I had same issue yesterday and was able to solve it as follows in case this pops up in somoene elses google search

you dont set the header in api.py like the example above

If you look at the create function of SFType class things become a little more obvious:
 
​def create(self, data, headers=None):
"""Creates a new SObject using a POST to `.../{object_name}/`.
Returns a dict decoded from the JSON payload returned by Salesforce.
Arguments:
* data -- a dict of the data to create the SObject from. It will be
JSON-encoded before being transmitted.
* headers -- a dict with additional request headers.
"""

So by default no headers are set by the function

So solution is to pass the headers in as part of the create call so something like this should work for you:
 
sf = simple_salesforce.Salesforce(password=password, username=user)
headers = {'Sforce-Auto-Assign': 'False'}
sf.Case.create(some-dict, headers)