400 bad request PUT update

I’m writing a quick and dirty script to batch update some jira fields directly in the browser console… i’m able to retrieve the individual issues and push them to my issues array… but for whatever reason the updateIssues fn I wrote is returning 400 error… If i go to the link directly, it works!

I was able to use the same script for another jira project we have on the same instance but It’s not working on this particular project. Is there something I’m missing? Are old jira issues archived in a weird way that would prevent them from being returned in the api? Why is the API returning 400 errors if i can access the url directly?

let issues = []
const getIssues = async (partner, project) => {
 await fetch(
      `https://${host}.atlassian.net/rest/api/2/search?jql=project="${project}"%20AND%20partner="${partner}"`
    )
      .then((response) => {
        if (response.ok) {
          return response.json()
        } else {
          return Promise.reject(`No Issues found with search criteria project=${project} and partner=${partner}`)
        }
      }).then (data => { 
return data.issues.forEach(issue => issues.push(issue.key)) 
})
      .catch((error) => console.error(error))
      console.log(issues)
}
const updateIssues = async updatePartner => { 
    issues
    .forEach(async issue => { 
        await fetch( `https://${host}.atlassian.net/rest/api/2/issue/${issue}`, { 
          method: "PUT",
          headers: {
              "Content-Type": "application/json"
          },
          body: JSON.stringify(updatePartner)
          }
    )
    .then((response) => {
        if (response.ok) {
            issues.shift()
            return console.log(`Partner Updated!`)
        } else {
            return Promise.reject(`No Issue found`)
        }
        })
    .catch((error) => console.error(error))
    })
}
getIssues("partner value", "project name") // anonymized for dev community

updateIssues({
    fields: {
        customfield_10307: { value: "new partner value" }
    }
}) // customfield_10307 == Partner Name

Could it be that there’s an issue with the project permissions or setup for this project? Usually a 400 error is in response to one of the following:

  • the request body is missing.
  • the user does not have the necessary permission to edit one or more fields.
  • the request includes one or more fields that are not found or are not associated with the issue’s edit screen.
  • the request includes an invalid transition.

I see you’re making a change to a particular field - so I’d double check the project configuration.

Cheers,
Melissa