According to https://developer.atlassian.com/static/rest/stash/2.6.3/stash-rest.html#idp2202432
I am trying to send put request /rest/api/1.0/users.
But there is always 405 error.
When I am trying to make request from Stash-Administration-REST API browser-Atlassian Stash REST plugin - /users - put it makes GET request.
Does the error in the rest? or I am wrong?
Simply I just want to retrieve currently authenticated user? Does any (undocumented?) default rest api exist? Or the better way is to make my own rest with the help of StashAuthenticationContext class?
PS Example of my request (via jQuery.ajax)
==1== $.ajax({ type: "POST", dataType: "json", url: "[local path]/stash/rest/api/1.0/users", success: function (data) { alert(data); } }); ==2== var dataInfo = '{"active": "true" }'; //or {} , or smth else, tried several variants $.ajax({ type: "POST", data: dataInfo, dataType: "json", url: "[local]/stash/rest/api/1.0/users", success: function (data) { alert(data); } });
Community moderators have prevented the ability to post new answers.
I have decided it by jQuery('#current-user').attr('data-username').
My goal was to retrive current authenticated user comments.
Dear Dana,
In your given code examples you are using POST instead of PUT, that's why you get HTTP 405 status ("Method not allowed").
Try to execute PUT with jquery.
--
Cheers, Ignat.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It didnt help. Now 415.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you print an example of your REST-entry-point
415 says that the media types doesn't match. You've put json on the one hand. What you've expacted on the other?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am expected JSOn with currently authenticated user's details.
I wanna to send empty json ({}), to not to change anything, but get response. Unfortunately, I didnt find more appreciable REST-reqest.
I tried several variants fron javascript-console inside browser
jQuery.ajax({ type: "PUT", dataType: "json", data: ({}), url: "[local]/stash/rest/api/1.0/users", success: function (data) { alert(data); } });
Its very strange that REST API browser doesnt work proper, too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did it happen from browser plugin? I'd avoid using it for calling REST endpoints. There is a known issue that it doesn't send correct content type header. https://ecosystem.atlassian.net/browse/DEVBOX-29.
When sending with jQuery try to ensure that header Content-Type is set.
Look here: http://forum.jquery.com/topic/jquery-headers-support-for-ajax
headers: { "Content-Type": "application/json", "Accept": "application/json" },
' dataType: "json" ' may be not enough
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you. But it still doesnt work.
jQuery.ajax({
beforeSend: function (xhrObj) { xhrObj.setRequestHeade("Content-Type", "application/json");
xhrObj.setRequestHeader("Accept", "application/json");
}, type: "PUT", dataType: "json", data: ({}), url: "http://kaetana-osx.local:7990/stash/rest/api/1.0/users", processData: false, success: function (data) { alert(data); } });
Does anybody tried to repeat this request?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dana,
Hope this will help:
jQuery.ajax({ type: "PUT", data: JSON.stringify({ "name" : "<name>", "displayName" : "<displayName>", "email" : "email@example.com" }), contentType:"application/json; charset=utf-8", url: "/rest/api/1.0/users", success: function (data) { log(data) } });
--
Cheers, Ignat.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you're trying to call this from Stash itself, that information should be mostly available on the page without a REST request at all.
This code isn't a public API, so it may stop working in a future release.
var user = require('model/page-state').getCurrentUser().toJSON(); console.log(user.name, user.displayName, user.slug);
What do you plan to do with the current user information?
Cheers,
Adam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've tried and I'm afraid it will not accept empty update.
In JIRA there is a new endpoint called myself, but I haven't found anything like that on stash...
Maybe as a workaround you could use something like that:
Call anything and get X-AUSERNAME from header response.
Then try to use it with GET /stash/rest/api/1.0/users/{userName}.
I'm not 100% sure if that's the same field that in header and it's ugly but it may be worth a try.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Change your AJAX-Request type to put
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I dont understand clear. I have tried to send request via js-script, and via REST API borwser. Both ones are awry.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you copy the header of your method?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Dana,
Are you able to execute PUT request from external REST client (e.g. a small python script)? I assume you may experience some issue with REST API browser.
--
Cheers, Ignat.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.