0

I am using OkHttp to make a POST request to the Bitbucket API to create a new issue. Their documentation says that a private repo or a private issue tracker require authentication to create new issues with this API. Both my repo and my issue tracker are public so there shouldn't be any issues with that. However when I make the call to create a new issue I get a 401 unauthorized response. Here is the code I am using to make the call:

FormEncodingBuilder builder = new FormEncodingBuilder();
String t = "{" +
           "\"status\": \"new\"," +
           "\"priority\": \"trivial\"," +
           "\"title\": \"This is a title\"," +
           "\"content\": \"This is the content\"," +
           "\"is_spam\": false\n" +
           "}";
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), t);
String url = "https://bitbucket.org/api/1.0/repositories/userName/repoName/issues"
Request request = new Request.Builder().url(url)
                                       .post(requestBody)
                                       .build();
Response response = new OkHttpClient().newCall(request).execute();

The Question: Can anyone tell me why I am getting an unauthorized response back?

UPDATE
Per Jim Redmond I have changed my request to authenticate first. I am now making a POST to https://bitbucket.org/site/oauth2/authorize?client_id=myConsumerKey&response_type=token and I get response 200 OK but I do not see a token in the headers... Any idea why I'm not getting a token in response?

Jason Crosby
  • 3,533
  • 4
  • 28
  • 49

1 Answers1

0

As the documentation also says, authentication is required for this method. It doesn't matter if your repo or issue tracker are public; there still needs to be a "reported_by" user.

Jim Redmond
  • 4,139
  • 1
  • 14
  • 18