Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

user_created webhook for G-Suite users

Simeon Cheeseman
Contributor
June 5, 2019

So I've been using Adaptvists Scriptrunner for cloud and have added in a script listener that is supposed to be listening for the `user_created` event.

It seems this is working for the users created for our Service Desk but it doesn't seem to trigger for users created by the Google Suite integration.

Basically what I want to do is automatically create a task in a project to notify me that I need to go and figure out what groups the user needs to be added to.

Has anyone else had any issues with this `user_created` event?

1 answer

1 accepted

0 votes
Answer accepted
Simeon Cheeseman
Contributor
June 6, 2019

Never mind - turns out I'm just not patient enough...

For the curious, I'll attach my script for Google search completeness. (Feel free to use as necessary)

// Pre check - because `accountType` can't be checked in the condition
def userDetails = get("/rest/api/3/user?accountId=${user.accountId}").asObject(Map).body
logger.info("Account Type is ${userDetails.accountType}")
if (userDetails.accountType != "atlassian") return

// Definitions
def projectKey = 'KEY'
def issueTypeName = 'Atlassian Request'
def componentName = 'Atlassian'
def adminUrl = "https://admin.atlassian.com/s/<redacted>/users/${user.accountId}"
// In my case this should be fine even with GDPR as by default all this is "on"
// when being generated from Google Suite integration
def username = userDetails.displayName ?: userDetails.name ?: userDetails.emailAddress

// Related Values Search
def issueTypeId = get('/rest/api/3/issuetype').asObject(List).body.find { it['name'] == issueTypeName }['id']
def atlassianComponentId = get("/rest/api/3/project/${projectKey}/component")
.header('Content-Type', 'application/json')
.asObject(Map).body.values.find { it['name'] == componentName }['id']

// Build Description
def adminLink = [
type: "text",
text: "Admin Page For ${username}",
marks: [
[
type: "link",
attrs: [
href: adminUrl
] as Map
] as Map
] as List
] as Map

def description = [
version: 1,
type: "doc",
content: [
[
type: "paragraph",
content: [
[
type: "text",
text: "A new user has been added, please setup their correct access. "
] as Map
] as List
] as Map,
[
type: "paragraph",
content: [
adminLink
] as List
] as Map
] as List
] as Map

post('/rest/api/3/issue')
.header('Content-Type', 'application/json')
.queryString("overrideScreenSecurity", true)
.body(
[
fields: [
summary : "New User Added: ${username}",
description: description,
project : [
key: projectKey
],
issuetype : [
id: issueTypeId
],
components: [
[ id: atlassianComponentId ]
]
]
])
.asObject(Map).body

Suggest an answer

Log in or Sign up to answer