You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Axios发送Jira用户偏好设置更新请求?

问题:Axios调用Jira语言偏好API无实际效果(Postman可正常运行)
  • 该请求在Postman中可正常触发语言更新,但用Axios复现后,虽能获取相同响应状态码,用户的语言设置并未实际变更。

现有实现代码

const config = { headers: {'Content-Type': 'application/json'} };
const lang ="en_US";
return axios.put("https://add-jira8.infosysta.com/rest/api/2/mypreferences?key=jira.user.locale", lang,config).catch(ex => {
  console.log(ex)
  ErrorLoging.log("AxiosRequests.js >>>>>> updateUserLanguage >>>>>>> ERROR: " + ex)
});

问题原因

Axios的PUT请求参数传递不符合Jira API要求:

  • Jira的mypreferences PUT接口需要JSON格式的请求体,且需用value字段包裹语言值
  • 直接传递字符串lang作为请求体,即便设置了Content-Type为application/json,实际发送的是纯文本而非合法JSON结构,这和Postman中正确的参数格式不一致

修复方案

方案一:传递符合API规范的JSON对象(推荐)

const config = { headers: {'Content-Type': 'application/json'} };
const lang = "en_US";
return axios.put(
  "https://add-jira8.infosysta.com/rest/api/2/mypreferences?key=jira.user.locale",
  { value: lang },
  config
).catch(ex => {
  console.log(ex);
  ErrorLoging.log("AxiosRequests.js >>>>>> updateUserLanguage >>>>>>> ERROR: " + ex);
});

方案二:传递合法JSON字符串

若需直接传递字符串,需先转为JSON格式:

const config = { headers: {'Content-Type': 'application/json'} };
const lang = "en_US";
return axios.put(
  "https://add-jira8.infosysta.com/rest/api/2/mypreferences?key=jira.user.locale",
  JSON.stringify(lang),
  config
).catch(ex => {
  console.log(ex);
  ErrorLoging.log("AxiosRequests.js >>>>>> updateUserLanguage >>>>>>> ERROR: " + ex);
});

内容的提问来源于stack exchange,提问作者Sora

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 23:54:50