Reputation: 11
I have an api in nodejs to getter data I need an authorization with token, but I don't know how to do it?
$(document).ready(function() {
$.getJSON("https://skillz-api.herokuapp.com/users", function(data) {
$.each(data, function() {
$("ul").append("<li>" + this['name'] + "</li><li>Age: " + this['age'] + '</li><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-ok"></span>Valider</button> <
button type = "button" class = "btn btn-default btn-sm" > < span class = "glyphicon glyphicon-remove" > < /span>Non valider</button > ');
});
});
});
My error is GET https://skillz-api.herokuapp.com/users 401 (Unauthorized)
Thanks
Upvotes: 1
Views: 65
Reputation: 1090
First you must understand that an Authorization token must be passed by the GET Request's Headers, see: https://developer.mozilla.org/pt-BR/docs/Web/HTTP/Headers for more information.
You can build a jquery ajax request with headers, like this:
$.ajax("https://skillz-api.herokuapp.com/users", {
headers: { "Authorization": "Your token here" }
}).then( (response) => {
// do whatever you want here
});
Upvotes: 3