Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Salesforce by (11.9k points)

When I add an object using AddBody:

var request = new RestRequest( Method.POST);

request.RequestFormat = DataFormat.Xml;

request.AddHeader("X-SFDC-Session", loginresult.SessionID);

var ji = new jobInfo { operation = "insert", @object = "contact", contentType = "CSV" };

request.AddBody(ji, xmlns);

Salesforce rejects it with this error message:

Unsupported content-type: text/XML

... presumably, because behind the scenes RestSharp is interpreting request.RequestFormat = DataFormat.Xml; as "text/XML".

By fiddling around with the Salesforce API I have discovered that it wants "application/xml" instead of "text/xml".

Is there a supported way to make RestSharp send "application/xml" instead?

1 Answer

0 votes
by (32.1k points)
edited by

From the documentation here

RequestBody

If this parameter is set, its value will be sent as the body of the request. Only one RequestBody Parameter is accepted – the first one.

The name of the parameter will be used as the Content-Type header for the request.

So from this documentation:

var ji = new jobInfo { operation = "insert", @object = "contact", contentType = "CSV" };

var jiSerialized = /* Serialize ji to XML format */

request.AddParameter(new Parameter

{

    Name = "application/xml",

    Type = ParameterType.RequestBody,

    Value = jiSerialized 

})

Enroll in our Best Salesforce Course to get a professional certification! 

Browse Categories

...