4

Every attempt I make to UPSERT via REST results in a 405 error which reads:

"errorCode": "METHOD_NOT_ALLOWED",
"message": "HTTP Method 'PATCH' not allowed. Allowed are GET,HEAD,POST"

I've tried to get help here without success: https://stackoverflow.com/questions/17268698/update-records-using-salesforce-rest-api-patch-method-not-working

I am testing this on hurl.it and I have tried these urls:

POST https://XXXX.salesforce.com/services/data/v32.0/sobjects/contact/Id?_HttpMethod=PATCH

PATCH https://XXXX.salesforce.com/services/data/v32.0/sobjects/contact/Id

I am trying to UPSERT based upon a Salesforce ID, not an external lookup.Is it possible to UPSERT based on the Salesforce ID?

Thanks

  • What object are you working with? – Adrian Larson Jun 24 '16 at 15:01
  • Contact (in the URL, hopefully in the right place). It's a shame the email field isn't an external id as I could use that otherwise :( – n34_panda Jun 24 '16 at 15:02
  • Ah, so it is. Well, I don't have any answers for you but I'm sure someone on here will know. – Adrian Larson Jun 24 '16 at 15:05
2

According to Insert or Update (Upsert) a Record Using an External ID, you should now use POST (as of v37.0). Make sure you're using the 37.0 endpoint (note to visitors from the future: any higher version will work as well, so long as your org supports that version).

Example from the page:

curl https://yourInstance.salesforce.com/services/data/v37.0/sobjects/Account/Id
-H "Authorization: Bearer token"
-H "Content-Type: application/json" -d @newrecord.json -X POST

newrecord.json

{ 
    "Name" : "California Wheat Corporation",
    "Type" : "New Customer"
}

This is new as of Summer '16/v37.0.

  • brief test via hurl.it (setting it to post, using the same endpoint - 37.0 and appending the Id field in the json returns the message: ""message": "The Id field should not be specified in the sobject data."?? Looks like it is just an insert, not an upsert? thanks for the reply. – n34_panda Jun 24 '16 at 15:53
  • 1
    @n34_panda I see what you mean now. I don't believe there's an equivalent; either you PATCH because you have an ID, or you POST because you don't. Since the REST API only allows single record transactions, I'm not sure this makes much of a difference? – sfdcfox Jun 24 '16 at 16:09
  • Ah, it would be only one record at a time but it doesn't help. My only other work around involves quite a bit more code so I better start on that I I can't figure this out today ;( – n34_panda Jun 24 '16 at 16:24
  • @n34_panda what platform are you using to make the http requests? It should just be a matter of switching out the http method based on whether or not you have an id. for me in node, all it took was: method : (request.body.Id ? 'PATCH' : 'POST'), – martin Nov 17 '16 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.