You need to sign in to do that
Don't have an account?
Patch / payload question in Google Script (REST API)
I'm attempting to use a Google Apps spreadsheet to display SF data, collect user input, and update SF records. It obtains data just fine, and executes the code that should update the SF data without error, but nothing changes in SF. Here's the code block that tries to update data in SF. Google's UrlFetchApp.fetch function does not accept the 'PATCH' method, so I use X-HTTP-Method-Override in the header. Any insight into why this silently fails? All of the authorization, SF Object Id, etc. is correct and works in a previous code block in the same function (not shown).
My suspicion is that the X-HTTP-Method-Override doesn't work - it appears to behave as if the 'GET' method was specified, and if I add an explicit 'method : DELETE' to the options, it will delete the account record in SF even though X-HTTP-Method-Override still specifies 'PATCH".
var queryUrl = "https://na9.salesforce.com/services/data/v20.0/sobjects/Account/001E000000L8FDGIA3"; var payload = "{\"BillingState\":\"MO\"}"; var headers = { "Content-type" : "application/json", "Authorization" : "OAuth "+accessToken, "X-HTTP-Method-Override" : "PATCH" }; var options = { "headers" : headers, "payload" : payload }; var response = UrlFetchApp.fetch(queryUrl, options);
The way to override the http method is to add a URL paramater of _HttpMethod=PATCH, and not via a header.
All Answers
The way to override the http method is to add a URL paramater of _HttpMethod=PATCH, and not via a header.
Thanks - works perfectly! It turns out that you also need to specify 'method : "POST"' in the options, presumably since GET (the default) doesn't accept a payload.
By the way - I spent a LOT of time looking for the solution for this before I posted. Is this in some secret documentation accessible only to the secret inner circle, or have my search skills atrophied to the point of irrelevance? In either case, thanks again for solving this. Now I can use Google spreadsheets as data entry/edit forms. Happiness. For anyone else struggling with this, here's the working code snippet (authorization is handled elsewhere):
Its in the docs, see
http://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#StartTopic=Content/dome_sobject_create.htm
What an idiot I am! Since I was trying to update a record, I foolishly looked in the Update example:
http://www.salesforce.com/us/developer/docs/api_rest/Content/dome_update_fields.htm
I'm glad you know where the answers are. I spent WAY too long thinking it was a Google problem since the original issue was that Google doesn't allow PATCH as a method.
Hi there perhaps you can assist me, I am trying to do u much simplified version ofwhat you are doing,
Simply importing data from salesforce to a google spreadsheet live, no need for the reverse.
Any advice,? I have attemoted to do this using the =importhtml functioning google spreadsheet
Regards
This really should be a new topic....
I do it using two functions that I shamelessly appropriated from somewhere (Edit: here, actually). The first runs when the spreadsheett is opened, and it handles all of the security stuff:
The second function is invoked by the user and in this case reads some SalesForce data and populates the spreadsheet with it:
If you're like me, you'll spend a fair amount of time dealing with missing or incoherent error messages before you get it to work. I actually test my SOQL queries in a PHP script first - I think there's also a script explorer tool out there somewhere for that purpose.