Intellipaat Back

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

I am trying to connect to the bulk API so I can do mass uploads of data from my application. I have read through the PDF documentation which emphasizes using CURL to make the POST requests. In keeping with the instructions, I have created a text file in XML format which is used for logging into the server.

Login.txt contents below:

<?xml version="1.0" encoding="utf-8" ?>

<env:Envelope xmlns:xsd=""




     <n1:login xmlns:n1="">

            <n1:username>my username</n1:username>

         <n1:password>my password</n1:password>




Here is what I'm trying to do in my code to make the login request:

XmlDocument XMLResponse = null;
HttpWebRequest httpRequest;
HttpWebResponse httpResponse = null;
Stream requestStream = null;
Stream responseStream = null;
XmlTextReader xmlReader;
httpRequest = HttpWebRequest)WebRequest.Create("");
            byte[] bytes = File.ReadAllBytes(filename);
            httpRequest.Method = "POST";
            httpRequest.ContentLength = bytes.Length;
            httpRequest.ContentType = "text/xml; charset=UTF-8";
            httpRequest.Headers.Add("SOAPAction: login");
            requestStream = httpRequest.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            if (httpResponse.StatusCode == HttpStatusCode.OK)
                responseStream = httpResponse.GetResponseStream();
                xmlReader = new XmlTextReader(responseStream);
                XmlDocument xmldoc = new XmlDocument();
                XMLResponse = xmldoc;

When this code executes I always get a 500 error. Does anyone have any experience in doing what I am attempting to do? Could you please provide me with some suggestions?

Thank you in advance.

1 Answer

0 votes
by (32.1k points)
edited by
To solve your login problem, just download and import the partner WSDL and use the generated web service client.

Or else, you'll have to update your code to read the response when it gets a 500 status code, the response body will give you more clues to the problem.

I'd assume in this case you're getting an identity confirmation error, and you'll want to provide your API security token in addition to your password in the login request.

Related questions

0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Browse Categories