How to create an issue in Jira project via C# API? URL is probably wrong

Hi,
I’m just a little out of my comfort zone - hoping someone can nudge me towards a solution. I’ve read many posts on the topic, yet my code still doesn’t actually create a new issue.
I believe I’m unclear on how to form the URL I should use. I’m hoping someone can clarify this.
Here’s a typical example of a URL in the documentation:
"https://your-domain.atlassian.net/rest/api/3/issue/10000

When I use the following URL - I get an error code of 200, and no issue is made - 200 seems not to be a hard error:
https:// synergistech .atlassian.net/ jira/software/c/projects /GEN/rest/api/2/issue

What I don’t understand is how to form the URL to specify one specific project - where I want the issues to be created. Also there is often a trailing code (10000) in the “your-domain” URL. That’s unclear. If I want to make hundreds of issues (in a loop for example) how should I change that last decoration?
I’ve tried a number of variations - for example - removing the “jira/software/c/projects” part - but these do produce hard errors.
For authentication I’m using email:API token, which seems to work fine.
Can someone help me understand how to form the URL correctly?

My goal is to migrate an external database set into Jira.

Thanks,
Gene

Hello @GeneSewell
You haven’t said if you’re developing for Jira CLOUD or Jira SERVER / DATACENTER. Given that there is no such thing as a ‘C# API’, can it be assumed you’re using the Atlassian SDK or some other library to interact with the REST API of one of those Jira products?

Which documentation are you reading? First, that URL is a mis-mash of jumbled stuff that makes little sense. Next, the parameters or body content required to cause the Issue to be created are missing, so that’s not good. Lastly, you don’t say if you’re doing a PUT or a POST request, so there’s no way of knowing what connection type you’re attempting.

Have you done any sort of basic testing of your REST API request method using a test tool like Postman?

Thanks for the response! I’m still coming up to speed on all of this - but my company is using Jira Cloud - and wants to move records from an existing SQL database into Jira. I’m an experienced C# developer - with moderate web skills.
I did try using Postman, with high hopes, but kept stumbling because my calls lacked authentication. When I write C# code using httpClient.SendAsync calls, I’m able to use basic authentication email:Key - but I was unable to figure out how to include this with Postman. Again, this is my first attempt to write this sort of code. I also had hoped to use curl with Postman, but couldn’t get that to work either.
I was able to write C# code, but decided I just didn’t understand how to form/parse the URL properly. I did find this post helpful - but still wasn’t able to make successful calls: Jira URL REST Problem - #2 by ibuchanan
By documentation - I meant the atlassian jira/docs → https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/ - and yes, I knew that URL I posted was badly formed - that was just my starting point.
I’ll do more work with Postman - if I can figure out how to authenticate myself while making an api call.
thanks again for the response…
Gene

Welcome to the Atlassian developer community @GeneSewell,

As a prior C# developer, I wish there were more .NET examples around the community. Alas, you’ll find a lot more Java and JavaScript here than anything else. That aside, lets try to get your Postman sorted. Anticipating @sunnyape’s reason for asking about Postman, I find the use of a “raw HTTP client” to be helpful, regardless of programming language because it helps me to isolate at least 1 layer of problems (HTTP vs code concepts).

Personally, I use Insomnia and HTTPie instead of the more popular Postman and curl but that shouldn’t prevent us from finding common ground. The first thing to know is that Atlassian’s API Tokens use Basic Auth. So, despite there being a Postman section about API Tokens, just use Basic Auth and use your email for your username and API token for your password. That should populate the Authorization header with something that looks like Basic aWJ1...MUIz.

Then, you want to make sure that you POST to /rest/api/3/issue. For example, here’s my full request URL:

https://devpartisan.atlassian.net/rest/api/3/issue

And the JSON body can get quite picky. Here’s a minimum request, using a project ID and issue type ID that you’ll have to obtain outside this request. For example, by doing a bit of that URL hacking that I explained in my other post.

{
	"fields": {
		"project": {
			"id": "10768"
		},
		"issuetype": {
			"id": "10003"
		},
		"summary": "Summarize the issue"
	}
}

If you want to use the REST API to get some arbitrary IDs for each project and issue type, try these:

  • GET /rest/api/3/project/search?maxResults=1: look for $.values[*].id (to express the path in JSON path). For me, that satisfies the project ID with 10768. Use that value to get the available issue types…
  • GET /rest/api/3/issuetype/project?projectId=10772: look for $.[*].id. For me, one of the issue types is 10003.

Both requests will work without authentication; however, in your Jira instance, there might not be any public projects with issue types, which means you might get 0 results.

I hope that gets you a little further.

1 Like

Thanks again - you are very clear and helpful.
Sadly, I still can’t get to first base? I downloaded insomnia and httpie, and have tried all three (postman as well.) I set up basic auth - with my email as my username, and the api key as PW.
I’ve tried several calls - for example, rest/api/3/status or your /rest/api/3/project/search?maxResults=1

I’m always seeing 401 unauthorized as the response. Could it be that I have to ask the administrator to set me up in some special way?

I do appreciate the help - not sure why I’m at such a roadblock?
Gene

@GeneSewell,

It certainly could be “admin interference”. And with so many HTTP clients, I think you have ruled out error on your client. :wink: Have you tried sending no auth header at all? If you are getting the same 401 Unauthorized, then your admin may have set up an IP-based allowlist to help tighten security. For me, no authentication means “anonymous” access and I get 404 Not Found instead.

Whatever the problem (we have to solve it eventually, but it sure helps when we can prove success first), I think it would be safer to do all dev work against your own developer environment. You can create your own, free developer site using:

My one “pro tip” would be to not add users (or to turn off JSM) because there is a limit of 1 user agent (and the defaults will have any new users added become an agent, which will kick you off the free dev instance).

Then it won’t matter and you can create as much “junk” with API calls as you see fit. If you are still getting 401 Unauthorized on a brand new site, then the problem might be an HTTP proxy between you and Atlassian.

1 Like