Question

I am trying to retrieve an order from the Eventbrite API. I have a valid OAuth token and order number. I have verified this by using postman which successfully returns the correct JSON.

However when I make the call using the following c# code, I get a 401 Unauthorised:

var client = new HttpClient();
var req = new HttpRequestMessage(HttpMethod.Get, "https://www.eventbriteapi.com/v3/orders/{orderNo}");
req.Headers.Add("Authorization", "Bearer {authToken}");
var response = await client.SendAsync(req);

I've tried replacing the header with:

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("{authToken}");

I have also tried:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.eventbriteapi.com/v3/orders/{orderNo}");
request.Headers.Add("Authorization", "Bearer {authToken}");
request.Accept = "application/json";
using(WebResponse response = request.GetResponse())
            {
    using(Stream dataStream = response.GetResponseStream())
                {
        using(StreamReader reader = new StreamReader(dataStream))
                    {
                        string responseFromServer = reader.ReadToEnd();
        }

    }
}

All of these get a 401 response. I know the authtoken and the eventid are correct, so there must be something wrong with my code.

Am I doing something wrong with the authroisation token?

Était-ce utile?

La solution

Have you tried ?token={authToken} option on the EventBrite API?

This would at least confirm if it's a problem with the way the header is being sent across.

http://developer.eventbrite.com/docs/auth/

Autres conseils

You omitted the trailing '/' in the URL, which caused a subsequent redirect from "eventbriteapi.com/v3/orders/{orderNo}" to "eventbriteapi.com/v3/orders/{orderNo}/". The authorization header was dropped in the redirect.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top