Can't make transition via REST API

aas November 14, 2019

Hello everybody! I can't make transition via REST because of 401 response code, but I authenticate with right credentials

def authString = "${user}:${password}".getBytes().encodeBase64().toString()

request.addHeader("authorization: Basic ${authString}", "ContentType: application/json")

The response is

Unauthorized (401)
    (function() {
        var contextPath = '';
        var eventBuffer = [];
        function printDeprecatedMsg() {
            if (console && console.warn) {
                console.warn('DEPRECATED JS - contextPath global variable has been deprecated since 7.4.0. Use `wrm/context-path` module instead.');
            }
        }
        function sendEvent(analytics, postfix) {
            analytics.send({
                name: 'js.globals.contextPath.' + postfix
            });
        }
        function sendDeprecatedEvent(postfix) {
            try {
                var analytics = require('jira/analytics');
                if (eventBuffer.length) {
                    eventBuffer.forEach(function(value) {
                        sendEvent(analytics, value);
                    });
                    eventBuffer = [];
                }
                if (postfix) {
                    sendEvent(analytics, postfix);
                }
            } catch(ex) {
                eventBuffer.push(postfix);
                setTimeout(sendDeprecatedEvent, 1000);
            }
        }
        Object.defineProperty(window, 'contextPath', {
            get: function() {
                printDeprecatedMsg();
                sendDeprecatedEvent('get');
                return contextPath;
            },
            set: function(value) {
                printDeprecatedMsg();
                sendDeprecatedEvent('set');
                contextPath = value;
            }
        });
    })();
if(window.WRM._dataArrived)window.WRM._dataArrived();Unauthorized (401)Возникла ошибка с кодом "401 - Unauthorized" при загрузке этой страницы.Basic Authentication Failure - Reason : AUTHENTICATED_FAILEDПерейти на домашнюю страницу Jira

2 answers

0 votes
aas November 14, 2019

Hi, this code request.addHeader("authorization: Basic ${authString}", "ContentType: application/json") works properly when I try to do smth via REST API in another instance of Jira. I always use it and it works without any problems

Andrew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 15, 2019
0 votes
Andrew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2019

Hi,

Could You please clarify code:

request.addHeader("authorization: Basic ${authString}", "ContentType: application/json")

Looks like You try add two headers. First - "authorization: Basic ${authString}", second - "ContentType: application/json". But I suppose it should like next:

request.addHeader("Header title", "header value")

E.g from my groovy:

connection.addRequestProperty("Authorization", "Basic ${authorization}")

B.R.

Suggest an answer

Log in or Sign up to answer