1

I'm working on Salesforce and wanting to get cases fields in it. found the command

curl https://yoursite.desk.com/api/v2/cases \
-u email:password \
-H 'Accept: application/json'

And I tried it in command prompt as

curl https://xxx.desk.com/api/v2/cases \-u [email protected]:xxxxxxxxx \ -H 'Accept: application/json'

I have tried the below code in C#

        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://xxxx.desk.com/api/v2/cases");
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Accept = "text/xml";
        httpWebRequest.Method = "GET";
        httpWebRequest.Credentials = new NetworkCredential("username", "password");
        var response = httpWebRequest.GetResponse();

But it is returning an error

The remote server returned an error: (401) Unauthorized.

2 Answers 2

1

CURL is just a client for WebRequests

the default C# option is WebRequest Class you can also use Restsharp

Sign up to request clarification or add additional context in comments.

1 Comment

I cannot do your work for you. Those are the tools. There are examples and tutorials. If u are stuck with a new question ask.
1
        var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://xxxx.desk.com/api/v2/cases");
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Accept = "text/xml";
        httpWebRequest.Method = "GET";
        httpWebRequest.Credentials = new NetworkCredential("username", "password");
        httpWebRequest.Headers.Add("Authorization", "Basic reallylongstring");
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        string text;
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {            
                string fddf =  streamReader.ReadToEnd();

        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.