Project

General

Profile

Need clarification on how to update or post data to redmine

Added by Thirumala Chary about 3 years ago

Hi Team,

We are trying to update and post the data to Redmine. We are getting 401(Authorization Required) error.
Please find below credentials which we are using.
UserName="ramsytesting",Password="ramsytesting"

We are using below type of code with to update and post data.

var httpClient = new HttpClient();
var username = "<API Username>";
var response = new HttpResponseMessage();
var password = "<API Password>";
var postData = "Data which we want to post to Redmine"

String authInfo = AuthProvider.BasicAuthProvider.UserName + ":" + AuthProvider.BasicAuthProvider.Password;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authInfo);
var jsonContent = jsoninput;
var httpContent = new StringContent(jsonContent);
response = await client.PutAsync("http://ramsytesting.m.redmine.org/issues/40.json", httpContent).ConfigureAwait(false);

Kindly help us in this.


Replies (2)

RE: Need clarification on how to update or post data to redmine - Added by Lorenzo Meneghetti about 3 years ago

Thirumala Chary wrote:

Hi Team,

We are trying to update and post the data to Redmine. We are getting 401(Authorization Required) error.

you are non able to login into redmine, check the documentation

We are using below type of code with to update and post data.

try first getting resource from browser, then with curl or postman to understand user accounting and authorization is correct

String authInfo = AuthProvider.BasicAuthProvider.UserName + ":" + AuthProvider.BasicAuthProvider.Password;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authInfo);

never seen before need to encode in Base64...
prefer to use http header X-Redmine-API-Key as explained here

var jsonContent = jsoninput;
var httpContent = new StringContent(jsonContent);
response = await client.PutAsync("http://ramsytesting.m.redmine.org/issues/40.json", httpContent).ConfigureAwait(false);

..but where do you tell to API request to use GET or other http methods?

Lorenzo

    (1-2/2)