How to sync Jira and Confluence directories with API call ?

Rachid El Mansouri May 3, 2023

Hi experts, 

I am trying to synchronize Jira and Confluence directories with an API call.

I wrote a powershell script but it is not working 

 

$TLS12Protocol = [System.Net.SecurityProtocolType] 'Ssl3 , Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $TLS12Protocol

$username = "toto"
$password = "xxxxx"
$baseurl = "https://myURL"

# Configuration de l'en-tête de la requête
$headers = @{
"Content-Type" = "application/json"
#"Authorization" = "Basic"
}

############### JIRA Synchro ##################
# Configuration de l'URL de l'API REST pour créer un projet
$jiraUrl = $baseurl + "/jira/plugins/servlet/embedded-crowd/directories/sync"
$directoryId = 10700

# Configuration des données du projet pour l'envoi à l'API REST
$syncBody = @{
"directoryId" = $directoryId
} | ConvertTo-Json


# Envoi de la requête à l'API REST pour créer le projet
$responseJira = Invoke-RestMethod -Uri $jiraUrl -Method Post -Headers $headers -Body $syncBody -Credential (New-Object System.Management.Automation.PSCredential ($username, (ConvertTo-SecureString $password -AsPlainText -Force)))

 I have an error 401 unauthorized 

 

Do you have an idea ?

2 answers

0 votes
Rachid El Mansouri June 9, 2023

Any idea ?

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 7, 2023

Hi @Rash ,

you can use JIRA as user management and syn users and groups in Confluence using a bultin feature (https://confluence.atlassian.com/doc/synchronizing-data-from-external-directories-229838498.html). Why don't you use this approach?

Fabio

Rachid El Mansouri May 9, 2023

Hi @Fabio Racobaldo _Herzum_ 

Thanks for your answer;

I can't use this approch because we use Crowd as user management. I want to sync Jira and Confluence after creation of new groups in Crowd.

I know that sync can be scheduled every x minutes but i want to automate it.

My initial need is to automate creation of new project (Group creation in Crowd, Jira directory sync, Jira project creation, Configuration of permissions in Jira project, Confluence space creation, Configuration of permissions in Confluence space...)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events