Not able to call jira api using service account to create bug/issue

I am not able to create Bug/Issue. I am using a go jira sdk (GitHub - andygrunwald/go-jira: Go client library for Atlassian Jira) to create bug/issue.

Strange thing is when i use my personal account id which has format “df45g5541d8834b550c18e4g”, issue/bug is being successfully created but when i a service account which has id format as “s34fg5:bfd5ddh-bnerbr76556-bmgbegege667g-nmefge7987” it does not create the issue/bug. Although payload is same in both the cases.

error i get : “errorString {s: “request failed. Please analyze the request body for more details. Status code: 400”}”

is there any difference in both type of account id’s?

Welcome to the Atlassian developer community @pkushwaha,

While there are a couple formats of account ids, they are intended to be opaque. There’s nothing about the difference that would inherently prevent API calls. More likely there is some kind of configuration/permissions issue at play.

To help you more, I agree with the error message; it would really help to see the additional details in the request body. Could you log that out and post here for more analysis?

@ibuchanan Thanks for the prompt reply.

this is the actual payload:

“{"fields":{"assignee":{"Password":"","accountId":"713030:a6a3dfa0-a7ac-56d4-f56b-f33377b9ee57"},"description":"Hello There is a new creative created","issuetype":{"name":"Bug"},"project":{"key":"VXAD"},"reporter":{"Password":"","accountId":"713030:a6a3dfa0-a7ac-56d4-f56b-f33377b9ee57"},"summary":"Jira Test"}}\n”

same payload working fine with personal account credential. only accountId will be replaced with personal account Id in above payload.

@pkushwaha,

I can’t reproduce the problem. And my Atlassian Account ID has the same pattern as your service account 557057:3d0e64ae-35d3-490d-b6d9-d81c981476d0. That leads me to believe the problem is that your service account does not have sufficient permissions in the project to be assigned (or reporter). For example, if I try to use your service account id (which I think you have obfuscated so it’s both invalid and harmless to use), then I get the following response:

{
	"errorMessages": [],
	"errors": {
		"reporter": "Specify a valid value for reporter",
		"assignee": "Specify a valid value for assignee"
	}
}

@ibuchanan Yes, i obfuscated the accountId purposely. Also I am able to create issues/task/bug from jira dashboard using same credential as i am using in calling api, So i believe it has sufficient permissions to create issues.

Can you suggest some permissions which you think might require so i can check with infra team?

@pkushwaha,

I’m afraid the documentation on permissions is not specific enough:

If it’s not permissions, I don’t know what is the problem. I cannot reproduce any errors based on the id format. Do you have any other information to share? Maybe the result body has more error information?

@ibuchanan Received this error. However when i change the credential with my personal account, it successfully creating issues. I have seen this error message when i do not pass or does not correctly pass payload fields too.


e

calling version 2 api- https://company.atlassian.net/rest/api/2/issue

hey @ibuchanan i checked with it, only difference between personal and this jira account is that gmail associated with this new jira account does not have oauth enable but personal gmail account has oauth enabled and is integrated with okta!

does it make any difference?

@pkushwaha,

I still can’t reproduce the problem. For me, if I use a wrong accountId or a wrong API token in the Authorization header, then I consistently get 401 Unauthorized responses, not 400 Bad request. So, I don’t think the problem is about authorization.

Let’s see if we can isolate where the account difference might be causing a problem. There are 3 places where we can set the accountId, let’s try changing them in this order:

  1. Start with your working example. You are authorizing with your account, and setting both assignee and reporter to your account. We expect this to work (because it has many times).
  2. Make the request again, changing only the assignee to the service account.
  3. Make the request again, changing both user fields: assignee and reporter are set to the service account.
  4. Make the request using all 3. Authenticate with the service account, and set both user fields.
  5. Keeping the service account authorization, try setting assignee to your user account.
  6. Keeping the service account authorization, try setting both assignee and reporter to your user account.

Let us know the HTTP statuses for each variation. I think that will tell us more about how to solve the problem.

i did tried different ways you mentioned @ibuchanan

result:

  1. working
  2. error
  3. error
  4. error
  5. error
  6. error

http status for each error :
Status:
“400 Bad Request”

@pkushwaha,

I’m pretty sure this is a permissions configuration problem, not an authorization problem or anything specific to the API. For Company-Managed Projects, there are issue permissions specifically for “Assignable User” and “Modify Reporter”. And for Team-Managed Projects, the permissions aren’t so fine-grained, but users (potentially through groups) must be granted access to the project. If your service account does not have sufficient permissions, then it cannot be assigned to an issue or report issues at all. If my permissions hypothesis is correct, you will not be able to set the service account as assignee in the UI either.

@ibuchanan I initially thought so but when i created a task from ui from service account i am able to create it and assign it too.

I am attaching the code i’m trying to run to create task/bug.

package main

import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"log"

	"net/http"
)

type User struct {
	AccountID string `json:"id" structs:"id"`
}

type IssueType struct {
	Name string `json:"name" structs:"name"`
}

type Project struct {
	Key string `json:"key" structs:"key"`
}

type Field struct {
	Assignee    User      `json:"assignee" structs:"assignee"`
	Reporter    User      `json:"reporter" structs:"reporter"`
	Description string    `json:"description" structs:"description"`
	Type        IssueType `json:"issuetype" structs:"issuetype"`
	Project     Project   `json:"project" structs:"project"`
	Summary     string    `json:"summary" structs:"summary"`
}

type Issue struct {
	Field Field `json:"fields" structs:"fields"`
}

func main() {

	iss := Issue{
		Field: Field{
			Assignee: User{
				AccountID: "45c6c5541d5564b550c18g5t",
			},
			Reporter: User{
				AccountID: "712020:3Ar4e3dfa0-a7ac-48d4-r44b-f33388b9ed34",
			},
			Description: "Hello There is a new creative created",
			Type: IssueType{
				Name: "Bug",
			},
			Project: Project{
				Key: "VXAD",
			},
			Summary: "Jira Test",
		},
	}

	payloadBuf := new(bytes.Buffer)
	err := json.NewEncoder(payloadBuf).Encode(&iss)
	if err != nil {
		panic("error")
	}

	r, err := http.NewRequest("POST", "https://fubotv.atlassian.net/rest/api/2/issue", payloadBuf)
	if err != nil {
		panic(err)
	}

	r.Header.Add("Content-Type", "application/json")
	r.Header.Add("Accept", "application/json")
	r.Header.Add("Authorization", "Basic "+basicAuth("pv@fubo.tv", "ATATT3xFfGF04e0yd2yPkGucBQrSfsyCJ-fNTjI8RC50Vwed4t6sPCUXkcmqJbr2rnvt2en3Ly7abl4a0U01k0APL6hqJv_5hlSUViVutn8jqv1eevQMqgZLwy9vIqE6xkFwbrvCOqz4mlE8QZQ8BZ34Kjms4CxWtDyAqJlSIHSSTotnmiNylI=E4D5CC51"))
	log.Println(r)

	client := &http.Client{}
	res, err := client.Do(r)
	if err != nil {
		panic(err)
	}

	defer res.Body.Close()

}

func basicAuth(username, password string) string {
	auth := username + ":" + password
	return base64.StdEncoding.EncodeToString([]byte(auth))
}

Note: api-token values are obfuscated

@pkushwaha,

I still cannot reproduce in my instance with my own users. And the prior errors on 2 (assignee) and 3 (reporter) indicate configuration. I don’t know what further help I can offer.