Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-68724

Trigger Directory Syncs using the REST API

XMLWordPrintable

    • 20
    • 1
    • We collect Jira feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      It is common to have an LDAP directory that does not support incremental syncs and is moderately sized. These directories don't have the option to lower the sync interval to pick up group membership changes for known users, so admins currently have to trigger syncs from the UI if the sync interval is not an acceptable time to wait for the change to reach Jira. If the REST API had a means of triggering a sync remotely, it would give admins an easy (and scriptable) way to pick up changes to a directory.

      Workaround

      The Bash script below runs a directory sync of all enabled directories, be sure to update your credentials.
      The script and its contents are not supported by Atlassian and are only provided on a best-effort basis. Use at your own risk.

      #!/bin/bash
      
      set -x
      
      # we need the base URL of the app (ie: https://jira.domain.com)
      BASEURL=$1
      [ -z "$BASEURL" ] && echo "usage: $0 BASEURL" && exit 1
      
      # build the URL needed to grab the xtoken
      URL="$BASEURL/plugins/servlet/embedded-crowd/directories/list"
      
      # store the cookie as a temp file that is deleted as we finish
      COOKIE=/tmp/GetRest.$$
      RESP=/tmp/GetToken.$$
      
      # login and save the cookie
      curl -k -c $COOKIE -s -X POST \
       --data 'os_username=your_admin_username'  --data 'os_password=your_admin_password' --data "formname=loginform" --data "login='Log In'" \
       "$BASEURL/dologin.action" -o /dev/null
      
      # get the list of sync opertaions by getting the URL with the cookie
      curl -k -b $COOKIE -s -X GET "$URL" > $RESP
      
      # here is an example of the sync operation
      # href="/plugins/servlet/embedded-crowd/directories/sync?directoryId=10501&atl_token=d5265f974829752eaa45a94011452b1b05f3f730">
      
      # look for all of the available sync operations and call each one-by-one
      for i in `grep /sync $RESP | grep atl_token= | grep -v "{id}" | sed 's/^.*href="//; s/".$//'` ; do
              curl -k -b $COOKIE -s -X GET "$BASEURL$i"
      done
      
      # delete the temp files
      rm -f $COOKIE $TOKEN
      

            Unassigned Unassigned
            smitra2@atlassian.com Suddha
            Votes:
            52 Vote for this issue
            Watchers:
            41 Start watching this issue

              Created:
              Updated: