Question

I have scoured the SFDC REST API reference, and every example (as far as I can find) have examples of payload to create/update records using JSON, and although it is completely valid to use XML, there is no schema listed and no examples of how to do it.

I have tried a number of alternatives, including

<Opportunity><Name>An Opportunity</Name></Opportunity>

but whatever I send I get "Root element is missing". I am sure that there must be schema to follow update fields, but the documentation seems to be sadly lacking. I am certain I solved this a very long time ago, but i cannot recall or find the format of the xml to submit.

And no, I'm not keen on re-writing the application to work in JSON rather than xml. :)

Thanks in advance Craig

Was it helpful?

Solution

I don't know of a published schema, but the XML you posted should work fine, given the error, i expect your code is not sending an actual HTTP Body. Here's a working example using curl.

foo.xml contains <Opportunity><Name>Foo</Name></Opportunity>

then i run

curl -X PATCH -H "Authorization:Bearer $SID" -H "Content-Type:application/xml" https://na1.salesforce.com/services/data/v29.0/sobjects/opportunity/0063000000o2QgO --data-binary @foo.xml -v

Its important to set the right content-type on the request. Running this generated

> PATCH /services/data/v29.0/sobjects/opportunity/0063000000o2QgO HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
> Host: na1.salesforce.com
> Accept: */*
> Authorization:Bearer {A Sid would appear here}
> Content-Type:application/xml
> Content-Length: 43
> 
* upload completely sent off: 43 out of 43 bytes
< HTTP/1.1 204 No Content
< Date: Tue, 13 May 2014 16:15:58 GMT
< Sforce-Limit-Info: api-usage=5/5000
< 

a 204 is the expected result for a successful patch call. Checking in the browser, i can see that the record did get updated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top