If I am querying using the following, then Function CallSFDCAPI works.


I am required get the response in XML format. But how can i get the response in XML format if I am querying using the following?


I get the error when trying to GET the picklist values.

System.Net.WebException: 'The remote server returned an error: (406) Not Acceptable.'

 Public Function CallSFDCAPI(ByVal Query As String, FileName As String) As String

    Dim objSFDCToken As New SFDCToken.GetSFDCToken()
    Dim SFDCToken As String = objSFDCToken.SFDCToken()

    Dim SFDCQuery As String = String.Format(Query)

    Dim TempFolder As String = ConfigurationManager.AppSettings("TempFolder").ToString()

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
    Dim httpWebRequest As HttpWebRequest
    Dim httpWebResponse As HttpWebResponse
    httpWebRequest = WebRequest.Create(SFDCQuery)
    httpWebRequest.Method = "GET"
    httpWebRequest.ContentType = "application/json"
    httpWebRequest.Accept = "application/xml"
    httpWebRequest.Headers.Add("Authorization", "Bearer " + SFDCToken)
    httpWebResponse = httpWebRequest.GetResponse()

    Dim uniqueFileName As String = DateTime.Now.ToString().Replace(":", "_")
    uniqueFileName = FileName + "_" + uniqueFileName.Replace("/", "_")

    Dim responseStream As Stream = httpWebResponse.GetResponseStream()
    Dim sr As StreamReader = New StreamReader(responseStream, Encoding.Default)
    Dim sw = New StreamWriter(TempFolder + uniqueFileName + ".xml", False, Encoding.Default)
   End Function

Any workaround to force a XML return?


/services/data/<api version>/query/... is a REST resource for SOQL Query. This resource supports both JSON and XML as payload representations.

/services/data/<api version>/ui-api/object-info/... is a User Interface API REST resource for object metadata. UI API REST resources only support JSON as the response format...because their intent is to have the response be consumed by a front-end client. Very few modern front-ends would want XML, thus it's not an option.

If you need XML, you're going to have to grab the JSON in the response and then generate XML yourself

  • I guess that is the only choice i have, thanks! – Tan Stanley Aug 16 '19 at 1:16

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.