How to Attach a File to a Jira Issue

  • 23 June 2021
  • 0 replies
  • 142 views
How to Attach a File to a Jira Issue
Userlevel 4

Jira is a popular App for planning, tracking and managing agile and software development projects.

One of the key components in Jira are Issues where details about that particular task or issue are tracked.

In Zapier today - we can create and update Issues - but we don’t have the ability to attach Files to issues through Zapier’s current Actions.

I always love a good workaround - and especially workarounds with webhooks. :slight_smile:

As usual - the 2 keys for making a webhook workaround work in Zapier are:

  1. Does the App provide API Key or Basic Authentication access to their API (as opposed to OAuth only)

  2. Do they have an Endpoint for doing what we want to do.

In the case of Jira and Attaching a File to an Issue - the answer is Yes to both.

Step 1: Getting our Jira API Key

Jira has instructions for creating an API Key at this link.

The quick summary is

  1. Go here: https://id.atlassian.com/manage-profile/security/api-tokens

  2. Click the Create API Key button on the Top

  3. Label your API Key and click Create

  4. Copy your API Key and store it in a secure location or password vault.

Step 2: The Endpoint for Files

While you won’t necessarily need to reference this for building your Zap - it might be helpful if you want to fully understand the API Call we’re making to Jira.

We can see the Jira’s API Documentation for Adding Files to Issues at this link.

The URL we’ll want to use in the call is:

https://your-domain.atlassian.net/rest/api/3/issue/TEST-123/attachments

Where “your-domain” is the domain used in your Jira Instance (just look at the URL when you’re logged into Jira).

And “TEST-123” is the Issue Key which we’ll get to in a bit.

Step 3: Our Zap Trigger

There are no set triggers and actions that we’d need to use in this Zap.

The only 2 things we’ll need to make this action work are a File Object (or a public download link to a File Object) and the Issue Key.

For the purposes of this post - I’m going to use a Google Drive New File in Folder Trigger - which returns the File Object.


Step 4: The Issue Key

Your trigger or a previous action may already be providing the Issue Key for the Issue that you want to update - and if so you wouldn’t need a Find Issue action in the Zap.

However - if we need to lookup the Issue Key - we can add a Find Issue Action to the Zap.

 

Which will return the Key for our Issue.


Step 5: Our Webhook

Now we’re ready to configure our Webhook action.

We’re going to use a Webhooks > POST request action for this Zap.

 

For the URL - we’re going to start with the URL Jira provided in their documentation.

https://your-domain.atlassian.net/rest/api/3/issue/TEST-123/attachments

Again - you’ll replace YOUR-DOMAIN with the domain for your Jira instance - and we’ll map in our Key from the previous step in the Zap that has that data.

The Payload Type we want to choose here is “form”.

The File is the File Object from my Google Drive trigger.

For Basic Auth - you’ll type in the email address you use to access Jira followed by a Pipe Delimiter | and then your API Key.

The 2 Headers we need to add for this request are:

  • Content-type multipart/form-data
  • X-Atlassian-Token no-check

 

That’s it. It’s time to Continue and Test.

And...Success!

The file has been attached to the Jira Issue. :)


Will it Work for Links and Not File Objects?

Yes - as long as the link is a publicly accessible link to the file object itself.

I tried it here with a link to my test palm tree image.

 

And again - the file was attached to the issue as well.

 

Will it Work for Multiple Files?

Not exactly.

Searching Google - I found other Jira users wanting to attach multiple files with one API call.

But this doesn’t appear to be possible today via Jira’s API.

We have to make a separate call for each file we want to attach.

If we will always have the same number of files in our Zap to attach - we can simply add additional POST Webhook actions for each file.

If the number of files will vary - we could add a Looping by Zapier action and then place our POST Webhook action after the Loop.

Summary

While attaching files to Jira Issues isn’t currently possible in Zapier’s existing Create and Update Issue actions - it is possible to attach files to a Jira Issue using a Webhooks by Zapier POST request.

To make this work we need 3 things.

  • JIRA API Key

  • File Object (or public link to a File Object)

  • The Jira Issue Key

From there a straightforward Webhooks POST request should attach the file to the Issue in Jira.

If you do give this a try - I’d love to hear your experience in the comments below!


0 replies

Be the first to reply!

Reply