1

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

services/data/v41.0/query?q=Select+Id+FROM+Vendor__c" 

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?

/services/data/v41.0/ui-api/object-info/Service_A__c/picklist-values/xxxx/Provider__c

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)
    sw.Write(sr.ReadToEnd())
    sw.Close()
    sr.Close()
    responseStream.Close()
   End Function

Any workaround to force a XML return?

1 Answer 1

0

/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

1
  • I guess that is the only choice i have, thanks! Aug 16, 2019 at 1:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .