Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

"Specify a valid project ID or key" exception while creating an issue from Google Script

Zet October 19, 2023
I'm trying to create an issue in my Jira (Cloud) project with URL Fetch in Google Script.
The main code is:

    issue = {
        "fields": {
          "issuetype": "Task",
          "summary": "Summary",
          "reporter": {"displayName": "John"},
          "priority": "Medium",
          "project": {"key": projectKey}
        }
      };
    UrlFetchApp.fetch(jiraUrl, {
      method: "POST",
      headers: {
        'Content-Type': "application/json",
        "Authorization": "Basic " + Utilities.base64Encode(userName + ':' + apiToken)
      },
      payload: JSON.stringify(issue)
    });

When I run it, I get a 400 exception: Truncated server response: {"errorMessages":[],"errors":{"project":"Specify a valid project ID or key"}}
However, I'm pretty sure that I put the correct key (shows in the issue datas I got from my Jira project in the same URL Fetch way) of my project into the line ("project": {"key": projectKey})
And I also tried using "project": {"id": projectId}, but still the same exception.
I have found similar questions and reports about this exception on the Internet. But it seems no effective solution mentioned ever.

1 answer

0 votes
Marios Marneros
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2023

Hi @Zet , welcome to the Atlassian Community!
I have ran into a similar issue before. Does the user or system trying to create the issue have the correct permissions? You might need to update the Browse Project permission as well as the Create issue Permission. If the user/system that is using the credentials in the request cannot "see" the project, the error you get is that the project id/name is invalid. Please let me know if this solves it! Have a nice day!

Zet October 23, 2023

Thanks for reply. How to check if I have the Create issue Permission? May I check it in google script with code?

Zet October 23, 2023

I (the user) can create issues in Browser in the project. Isn't it enough?

Marios Marneros
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2023

You can update project permissions through project settings by updating the permission scheme. Permission Documentation 

If your user has create issue and browse project permissions you need to use those credentials to make the request (API token) or give permission to the user you are currently using. Let me know if this helps

Zet October 24, 2023

uhhh... actually I'm not a manager of the project so I can't access the project settings. But I can browse and create issue in the project with the GUI on the project web page.

And I do created an API token for my Jira account (and I tried revoking and recreated a new one).

And I can even get issue datas in my Google Script code with that token, juse can't create issue in it.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events