0

i got the auth token using my api key den while trying to access user content i get this error

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

Here is my c# code

string url = "https://www.box.com/api/2.0/folders/0 \\ -H "Authorization: BoxAuth api_key=API_KEY&auth_token=AUTH_TOKEN"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 

1 Answer 1

1

The -H "Authorization: BoxAuth api_key=API_KEY&auth_token=AUTH_TOKEN" is an argument of the example cURL command, not part of the API URL. It indicates an HTTP Header. You'll need to add that header to your request object.

Try this:

string url = "https://www.box.com/api/2.0/folders/0"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Headers.Add("Authorization", "BoxAuth api_key=API_KEY&auth_token=AUTH_TOKEN"); 

Alternatively, you could try the Box C# SDK, which will take care of all that for you.

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

2 Comments

ok thnks for dat.I had one more doubt.In order to create a shared link i need one more parameter...-d '{"shared_link": {"access": "Open"}}' \.How should i add this to the request
I can't post the code in a comment, but this SO question should point you in the right direction.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.