Forum Discussion

Troji's avatar
Troji
Guide
8 years ago

Bulk API call with C#: error 401 or 407

Dear Community

I've been looking for quite some time before coming to ask here.

I don't know how I can translate the following sample-curl call into appropriate C# code:

curl “https://api.lithium.com/lsi-data/v1/data/export/community/testcommunity.prod?fromDate=20140913&toDate=20140916 -H “client-id: safkdndkebbdkkkc” -u “eicncladjiickld:”

What I got so far:

        public string httpGetRequestCommunity (string url)
        {
            //set values
            ////////edit////////
            string token = "eicncladjiickld:";
            string clientID = "safkdndkebbdkkkc";

            //encode username and password in base64
            string authenticationEncoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(token));
            // Create a request for the URL.   
            WebRequest request = WebRequest.Create(url);
            // Set the credentials.  
            request.Headers.Add("client-id", clientID);
            request.Headers.Add("Authorization", "Basic " + authenticationEncoded);
// Get the response. WebResponse response = request.GetResponse(); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. responseFromServer = reader.ReadToEnd(); // Clean up the streams and the response. reader.Close(); response.Close(); return responseFromServer; }

Does anyone have sample code on how to connect with C# to the Bulk API? Or can someone help me? :)

 

That would be really great!

 

Regards,

Simon

No RepliesBe the first to reply