skip to Main Content

This request works fine from postman, but i am trying to replicate it from axios but i cannot

enter image description here

This is what i did (Note that i am getting the same response status, but the language is not being updated on the instance itself)

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)
  });

This is the api endpoint used

enter image description here

2

Answers


  1. You have issue in your body even in your postman, you selected json so it should be a json, like:

    const API_URL = "https://add-jira8.infosysta.com/rest/api/2/mypreferences?key=jira.user.locale";
    const config = { headers: { 'Content-Type': 'application/json' } };
    const body = { lang: "en_US" };
    return axios.put(API_URL, body, config)
        .catch(error => {
            console.log(error)
        });
    Login or Signup to reply.
  2. Looking at the screenshot you provided the body is sent as "raw" but in your code you are trying to sent JSON. Not sure which one the server accepts but if it expects raw then you should change the content type:

    const config = { headers: {"Content-Type": "text/plain"} };
    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)
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search