Hey folks, I’m trying to add a small text file to an existing JIRA ticket using PowerShell. I’m using the Invoke-RestMethod command with a POST request, but I’m running into some issues.
When I run this, I get a 404 error. Any ideas what I might be doing wrong? I’ve double-checked the JIRA ID and API URL, but I’m still stuck. Thanks for any help!
I’ve encountered similar issues when working with JIRA’s REST API in PowerShell. From my experience, the problem might be with how you’re handling the multipart/form-data content type. Invoke-RestMethod doesn’t natively support this format well.
Here’s what worked for me:
Use the -Form parameter instead of -InFile.
Create a custom boundary string.
Construct the body manually using byte arrays.
Here’s a modified version of your function that should work:
I’ve worked extensively with JIRA’s API, and I can offer some insights. The issue you’re facing is likely related to authentication or the API endpoint structure. First, ensure your auth token is correctly formatted and up-to-date. JIRA’s API is sensitive to token expiration.
Secondly, double-check the API endpoint. Some JIRA instances use a slightly different structure. Try modifying your URL to:
“$apiUrl/rest/api/2/issue/$ticketId/attachments”
Additionally, make sure your account has the necessary permissions to add attachments to the specific ticket.
If these don’t resolve the issue, you might want to look into using a dedicated JIRA PowerShell module like PSJira. It handles many of these intricacies automatically, making API interactions much smoother.