Hi there,
I am starting to delve into the API for JSM but looking on the developer website there doesn't seem to be any examples set out in Powershell, this hurts due to me pretty much only knowing scripting in Powershell.
Does anyone know of any sites that give some examples for how to best leverage API calls (of all types) using Powershell?
Thanks all.
You might like to have a look at https://atlassianps.org/docs/JiraPS/ which is a community site that explores options around Jira and PowerShell.
Hi Steven,
I'm working on creating requests via API through Powershell as well. I'm slowly getting it to work, while I' m convinced that it can be done more easily.
It would be nice if there was already a ready made Powershell module, but that is not the case. The proposed JiraPS is basically suitable for creating ISSUES, but not REQUESTS. It is made for normal Jira projects, but not for JSM projects.
There is a separate API for JSM projects, which is designed for this.
You can find the documentation here: https://developer.atlassian.com/cloud/jira/service-desk/rest/intro/
Now that you also asked for some examples, I'll post my code here.
Use case: Creation of a request, during the automatic user creation, from the HR database system.
The Request Type is "Neues Konto anlegen" (Translated it should be something like "Create New Account")
# Create encoded CREDS
$user = 'YOUR MAIL ADDRESS'
$pass = 'YOUR API TOKEN'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
#Create Auth Headers for Invoke-RestMethod
#in my case encoded Creds is loaded from Keepass with Module PoShKeePass and already Base64encoded
# Please dont use plain text credentials in scripts, due to security reasons. if you have a Read-Host method to get the pass thats ok.
$Headers = @{
Authorization = "Basic $encodedCred"
Accept = "application/json"
}
$Body = @"
{
"requestParticipants": [],
"serviceDeskId": "4",
"requestTypeId": "51",
"requestFieldValues": {
"summary": "Request JSD help via REST",
"description": "I need a new *mouse* for my Mac",
"components" : [{"name": "Active Directory"}]
}
}
"@
My Problem is, the above Body. I would like to work with PS Objects and use ConvertTo-JSON once, but this is not working properly.
So i have something like a mix with creating the damn Body.
Current problems:
Invoke-RestMEthod -Method Post -Uri "https://YOUR-BASE-DOMAIN/rest/servicedeskapi/request" -Headers $Headers -Body $Body -ContentType 'application/json'
I hope I could help you a little with this.
if you want, we can also exchange ideas via private channels like MS teams
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Steven,
i am currently taking a deeper look into the JiraPS Module to find some generic code for the different Attribute Types.
I think there is the root cause, that simply build the Objects wrong, so the resulting JSON is wrong, too.
Additonally have a look here: https://community.atlassian.com/t5/Jira-Service-Management/Is-anybody-working-on-a-Powershell-Module-for-Jira-Service/qaq-p/2052980#U2053806
Another Post of me, which is looking for a JSM Powershell Module.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.