Get Current Logged In User with REST Api

Is it possible to get the currently logged in user with the REST API? Below is me kinda guessing based on the limited information i could find on it.

function queryShotgun() {
    var headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json'
    };

    $.ajax({
        url: 'https://[SiteURL].shotgunstudio.com/api/v1/auth/access_token',
        method: 'post',

        headers: headers,
        data: {
            grant_type: 'client_credentials',
            client_id: 'queryToken',
            client_secret: '(CodeGoesHere'
        },
        success: function (data) {
            $('#accessOutput').html(data.access_token);

            var headers = {
                'Content-Type': 'application/json;odata=verbose',
                'Authorization': `Bearer ${data.access_token}`
            };
            $.ajax({
            	url: 'https://[SiteURL].shotgunstudio.com/api/web/currentuser',
                method: 'post',
                headers: headers,
                data: `${JSON.stringify(data)}`,
                success: function (data) {
                    console.log(JSON.stringify(data));
                    $('#queryOutput').val(JSON.stringify(data, null, 3));
                },
                error: function (data) {
                		console.log(data)
                    $('#queryOutput').val(JSON.stringify(data, null, 3));
                },
            })
        }
    })
}

window.onload = function(){
  queryShotgun();
};

Does anyone know if this is possible?

Hi @JokerMartini,

I would ask our expert if it is possible. I would suggest you to remove the login credential from the code to keep your shotgun safe.

Thanks

Loney

Hi @JokerMartini,

Unfortunately, this is not possible at this time.

doesn’t give me access to edit the post in order to remove them sadly :frowning:

I’ll make a quick edit for that, @JokerMartini. :slight_smile:

1 Like

And done!

1 Like