ScriptRunner Cloud - Automate setting up "Manager" property from Azure AD

Mark Sayo November 22, 2023

Hi,

I need help with the following situation.

After the user created an issue in Jira, In the create PostFunction I need to create a script (ScriptRunner) that brings the logged-in user information "Manager Hierarchy Details" that is registered in Azure AD and copies them in custom fields, for example, "Manager 1", "Manager 2", "Manager 3".

We tested if this is possible via REST API in Postman and we succeeded in getting the logged-in user "Manager Hierarchy Details". To do this we need to generate a token to access the Microsoft Graph API.

I believe this is possible in ScriptRunner and appreciate the assistance in what is lacking in my script below

 


import groovy.json.JsonOutput
 
final externalUrl = "https://graph.microsoft.com/v1.0/"
 
def getResponse = get(externalUrl, 'me')
 
if (getResponse) {
  def responseGetMap = getResponse as Map
  responseGetMap.each {}
}
 
def get (def hostUrl, def endpointAndQuery) {
def token = "<input token>"
  get("$hostUrl$endpointAndQuery")
   .header('Accept', 'application/JSON')
   //.header
  .header('Authorization', "Bearer $token")
   .asObject(Map)
}

1 answer

0 votes
Kristian Walker (Adaptavist)
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 22, 2023

Hi Mark,

I can confirm that it is possible to call external APIs with ScriptRunner for Jira Cloud if the external API provides a rest API.

We have an example in our documentation page here which shows how to interact with the external slack API, and this can be used as a guide to see what syntax to use to call external APIs from ScriptRunner for Jira Cloud.

Also, on this documentation page, we have many examples of how to set different custom field types that may be useful to your requirements.

Also, to let you know, we provide the Script Variables feature, which allows you to store tokens encrypted and reference them in scripts so you do not have to hard code these as plain text in the scripts.

If you need assistance with using the third-party API, we would advise contacting the vendor who makes these APIs to ask them to assist with the API payload structure that the API requires.

I hope this information helps.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events