It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create a Jira project from Powershell with REST API

I am trying to create a new project in Jira from Powershell using REST API.

I have the following code, but it is giving me http error 400. I can't figure out where the problem is, most likely in the json part, but how to pinpoint the exact error?

$npuri = "$baseurl/rest/api/2/project"
$npjson = "{    `"key`": `"MNew`",
    `"name`": `"M Software Sample`",
    `"projectTypeKey`": `"business`",
    `"projectTemplateKey`": `"com.atlassian.jira-core-project-templates:jira-core-project-management`"
,    `"description`": `"Example Project description`"
    `"lead`": `"userid`",
    `"assigneeType`": `"PROJECT_LEAD`",
    `"avatarId`": 10262,
    `"permissionScheme`": 10342,
    `"notificationScheme`": 10000,
    `"categoryId`": 10120
    }"
$response=Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json" -Uri $npuri -Body $npjson -Method POST

A basic query using same base URL and authentication works.

1 answer

I don't know where the problem is, but here are some ideas to narrow down the problem:

  • use a different client (for isntance a browser plugin) to "play" with your rest-service
  • wrap your json body in single-quotes, then you dont need to escape your double quotes
  • use a simpler use-case (something like create issue) to start with before creating a project, as to test your body syntax

Hi,

Thanks for your suggestions. Using postman, I was able to clear up the JSON syntax, mostly by removing all unnecessary fields.

I also changed the way the JSON body was constructed:

$hash = @{    key"KEY";
    name"TG Software Sample";
    projectTypeKey"software";
    projectTemplateKey="com.pyxis.greenhopper.jira:gh-scrum-template";
    description"Example Project description";
    lead"userid";
    assigneeType"PROJECT_LEAD"
    }

$json = $hash | ConvertTo-Json

 After that, a project was created successfully on Jira.

 

Regards,

 

Thijs

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you