Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP 401 Error #30

Closed
infn8 opened this issue May 9, 2017 · 9 comments
Closed

HTTP 401 Error #30

infn8 opened this issue May 9, 2017 · 9 comments

Comments

@infn8
Copy link

infn8 commented May 9, 2017

Not sure if this is an error for this library or not but here goes:

When connecting i use this code

const rally = require('rally');

rc = rally({
	user: 'user@domain.ext',
	pass: 'xxxxxxxx',
	apiKey: token
});

Using the token Which i get by going here:

https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize

with my username and password. I then run this

rc.get({
	fetch: ['FormattedID', 'USXXXXX'], //fields to fetch
	scope: {
		workspace: '/workspace/YYYYYYYYYYYd' 
	},
}).then(function(result) {
		console.log(result);
}).catch(function(errors) {
	 console.log(errors);
});

Where YYYYYYYYYYYd is my real workspace ID and USXXXXX is a real User Story on that workspace. I get response that says:

Error 401 Full Authentication is required to access this resource 
HTTP ERROR 401
Problem Accessing /slm/webservice/v2.0null. Reason:
Full Authentication is required to access this resource
Powered by Jetty

Am I missing something?

@krmorse
Copy link
Contributor

krmorse commented May 23, 2017

A couple things. First- you should either use username/password OR an api key, but not both. You shouldn't need to worry about the CSRF token or the /security/authorize endpoint- that will be handled transparently by the toolkit once you are authenticated.

An api key may be obtained by going to https://rally1.rallydev.com/login

It seems like you're trying to find a story by FormattedID. In order to do that you'll need to use the query method. The error you're getting is because the get method expects a ref property of the object to read (/defect/12345 for example)

Something like this should work for you:

restApi.query({
    type: 'hierarchicalrequirement', //the type to query
    fetch: ['FormattedID'], //the fields to retrieve
    query: queryUtils.where('FormattedID', '=', 'US12345)
}).then().catch()...

@krmorse krmorse closed this as completed May 23, 2017
@vijendra-impetus
Copy link

I am trying to update the note section of a user story. Below is my code :

var rally = require('rally'),
queryUtils = rally.util.query;
refUtils = rally.util.ref;
restApi = rally({
user: username,
pass: password,
apiVersion: 'v2.0',
server: 'https://rally1.rallydev.com',
}, function (error, result) {
if (error) {
console.log('Failed to access Rally server:', error);
}
});

Above code is working as expected am able to update the note section of userstory or defect. But when try to use the same with "apiKey". I got error " Item with ID not found".

With username and password things working fine but not with apiKey. can you please help?

@krmorse
Copy link
Contributor

krmorse commented Jul 18, 2017

Can you post your full code? I think the code above is just a snippet.

@vijendra-impetus
Copy link

console.log('\nUpdating rally comments');

var args = process.argv.slice(2);
username = args[0].split(":")[0];
password = args[0].split(":")[1];
item = args[1];
comments = args[2];
updatedNotes = args[2];

if (item.substr(0,2) === 'DE') {
itemType = 'defect';
console.log('Defect: ' + args[1]);
console.log('Comments to be added: ' + comments + '\n');
} else if (item.substr(0,2) === 'US') {
itemType = 'hierarchicalrequirement';
console.log('User story: ' + args[1]);
console.log('Comments to be added: ' + comments + '\n');
} else {
try {
throw new Error('Please provide a correct defect or user story id to update.\nSample command: node app.js 'username:password' 'defectId' 'Comments to be updated'');
} catch (error) {
console.log('Failed while updating comments:', error.message);
return false;
}
}

var rally = require('rally'),
queryUtils = rally.util.query;
refUtils = rally.util.ref;
restApi = rally({
user: username, //required if no api key, defaults to process.env.RALLY_USERNAME
pass: password, //required if no api key, defaults to process.env.RALLY_PASSWORD
server: 'https://rally1.rallydev.com', //this is the default and may be omitted
}, function (error, result) {
if (error) {
console.log('Failed to access Rally server:', error);
}
});

function getNotes() {
return restApi.query({
type: itemType,
fetch: ['Notes'],
query: queryUtils.where('FormattedID', '=', item)
});
}

function updateNotes(result) {
console.log(result);
if (!result || !result.Results || result.Results.length === 0) {
throw new Error('Item with ID ' + item + ' not found');
}
notes = result.Results[0].Notes;
if (notes) {
updatedNotes = notes + '

' + comments + '
';
}
console.log(updatedNotes);
return restApi.update({
ref: refUtils.getRelative(result.Results[0]._ref),
data: {
Notes: updatedNotes //the data with which to update the specified object
}
});
}

function onSuccess(result) {
console.log('Successfully updated comments for ' + item);
}

function onError(errors) {
console.log('Failed while updating comments for ' + item, errors);
}

getNotes().
then(updateNotes).
then(onSuccess).
fail(onError)

Above is the complete code.

@vijendra-impetus
Copy link

Above code is working fine as i am giving username and password but when i try to comment username and password and give apiKey, then i got error.

@vijendra-impetus
Copy link

vijendra-impetus commented Jul 20, 2017

Hi @krmorse did you get the chance to look in to this?

thanks in advance for the help.

@krmorse
Copy link
Contributor

krmorse commented Jul 25, 2017

The code looks ok in general... Are you sure the api key is valid?

@vijendra-impetus
Copy link

@krmorse ,

Yes the API key is valid.

@Asha-arabhanvi
Copy link

Asha-arabhanvi commented Sep 14, 2020

Hi
@krmorse
I am trying to access data of rally using Rally npm package. and i am getting this authentication issue though i am giving correct credentials and api keys

Error:
Error 401 Full authentication is required to access this resource
HTTP ERROR 401
Problem accessing /slm/webservice/v2.0/defects. Reason:
Full authentication is required to access this resource
what is the solution , is there any proxy to be set?

Please help me in this
Thanks in Advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants