2

I'm trying to do integration with Salesforce using their REST API and CF8. I got the OAuth bit working, getting data etc but now I'm trying to update some records in Contact table.

First I tought about doing it the "proper" way as their docs say -

Update a record using HTTP PATCH.

But CFHTTP doesn't support PATCH method.

So then I tried running a SOQL query:

UPDATE Contact SET MailingStreet = 'Blah Blah' WHERE Id = '003A000000Zp4ObIAJ' 

but here I'm getting

{"message":"unexpected token: UPDATE","errorCode":"MALFORMED_QUERY"}

Does anyone have an idea how to do it?

2 Answers 2

9

You can create your own PATCH method if your client supports it, but there is an easier way. From the Force.com REST API Developer's Guide:

If you use an HTTP library that doesn't allow overriding or setting an arbitrary HTTP method name, you can send a POST request and provide an override to the HTTP method via the query string parameter _HttpMethod. In the PATCH example, you can replace the PostMethod line with one that doesn't use override:

PostMethod m = new PostMethod(url + "?_HttpMethod=PATCH"); 
Sign up to request clarification or add additional context in comments.

Comments

2

In CF9 CFScript, using the method that Paddyslacker already suggested for adding _HttpMethod=PATCH to the URL:

private boolean function patchObject(required string sfid, required string type, required struct obj) { local.url = variables.salesforceInstance & '/services/data/v' & variables.apiVersion &'/sobjects/' & arguments.type & '/' & arguments.sfid &'?_HttpMethod=PATCH'; local.http = new Http(url=local.url,method='post'); //... convert obj to a json string, add to local.http ... local.httpSendResult = local.http.send().getPrefix(); } 

We have a CF9 CFC that we wrote that wraps most of the REST API that we will be open sourcing soon. I'll come back and link to it when we do.

2 Comments

Hi Dan, did you guys ever open source your CFC?
Not the full thing, but we do have a trimmed down version in a Gist: gist.github.com/danwatt/1827874

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.