Setting Up a Custom Developer Console App to Connect Google Sheets to JSW Cloud API using OAuth 2.0 (3LO)
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Background:
While the easiest way to connect Google Sheets to Jira is with the Jira Cloud add-on for Google Sheets, for niche use cases where you want more control, it may be worth setting up a custom app in the developer console so that you can access the Jira API using OAuth 2.0 (3LO) authentication from within a Google App Script.
How-to:
- Start by navigating to the Developer Console
- Click Create → Oauth 2.0 integration
- Give the new app a name, read and agree to the developer terms then click Create
- Select Authorization from the menu → next to Oauth 2.0 (3LO) click Add
- Pause here and open a new browser tab
- Create a new Google Sheet and give it a recognizable name
In the menu pane, select Extensions → Apps Script and give the Apps Script a recognizable name
- In the left-side menu, click Libraries to add a new library
Use the Script ID below to load the Google's OAuth 2.0 Library:
Script ID: apps-script-oauth21B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF
- Leave the rest of the options as default and click Add
Now, click the gear icon in the left-side menu to navigate to the App project settings; locate your Script ID and take note of it for later.
Switch back to your Atlassian Developer Console
- If you navigated away from the Authorization screen, go to Console → My Apps → name_of_your_app → Authorization
Enter the following for the Callback URL (where SCRIPT_ID is replaced with the script ID you took note of in step 12 above):
Callback URLhttps://script.google.com/macros/d/SCRIPT_ID/usercallback
- Click Save Changes
- Next, navigate to the Permissions section using the left-side menu
- Next to where it says Jira API, click Add
- Wait a moment and the button should change to Configure, then click Configure → Edit Scopes
Click View user profiles (read:jira-user)
The read:jira-user permission is needed for the example in this article but for your own app you'll want to add whichever permission(s) your app will need.
- Click Save
Next, navigate to the Settings section and take note of your Authentication details (Client ID & Secret)
Switch back to your Google App Script
- Copy the Jira Example Script in Google's Repository and paste it into your own Google App Script console
In the script you just pasted, replace the ellipses (...) in the following variables with the values you saved from your atlassian developer console app in step 9 above
Variablesvar CLIENT_ID = '...'; var CLIENT_SECRET = '...';
Now select the run() function from the drop down and click the Run button in the app script editor.
- A modal box will pop up asking for Authorization. Click Review permissions
A new browser pop-up window will appear asking you to select an Atlassian account to sign into
- Select your account
Review the permissions then click Allow
You may get a message like the following in your Google App Script console:
- Copy the URL from the console and paste it into a new browser tab
- From the dropdown, select the Atlassian Site you are trying to connect to and click Accept
- Close the window, return to the App Script editor, and run the script again
If successful you should see JSON successfully returned by the API request