Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unexpected status code received from API: 401,{\"code\":401,\"message\":\"Unauthorized\"

sonia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 15, 2023
request, err := http.NewRequest("POST", rootUrl, bytes.NewBuffer(requestBodyJSON))
if err != nil {
log.Errorf("failed to create HTTP request: %s", err.Error())
return nil, err
}

request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", "Bearer "+jwtToken)
client := http.Client{
Timeout: time.Second * 300,
}
response, err := client.Do(request)
if err != nil {
log.Errorf("Error while sending HTTP request: %s", err.Error())
return nil, err
}

defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
log.Errorf("Error while reading response body: %s", err.Error())
return nil, err
}

if response.StatusCode != http.StatusOK {
log.Errorf("jira.repo.jira_api: Unexpected status code received from API: %d,%s", response.StatusCode, body)
return nil, errors.New("error :Unexpected status code received from API")
}

1 answer

1 accepted

1 vote
Answer accepted
Brant Schroeder
Community Champion
January 26, 2024

@sonia Welcome to the Atlassian community

If you are getting a 401 error you are failing to authenticate.  Take a look at the documentation here on how to properly authenticate.  https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#version 

Brant Schroeder
Community Champion
April 3, 2024

@sonia please accept the answer to help others?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events