Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
GET method gives success but PUT method gives 401 despite same credentials

The problem Overview

  • When getting products using a GET method everything works
  • when trying to update a product using PUT method I get 401 unauthorized
  • I use same credentials for both methods
  • The bearer token is global scope, I should be authorized to do anything to a given product

The code

GET

// javascript
const axiosOptions = {
  headers: {
    "Authorization": `Bearer ${token}`
  }
}

const onAllClick = async () => {
  const result = await axios.get(`https://api.printify.com/v1/shops/${shopId}/products.json?limit=30`, axiosOptions );
  const products = result.data.data; 
  console.log(products);
}

PUT

javascript
const axiosTagUpdateOptions = {
  headers: {
    "Authorization": `Bearer ${token}`
  },
  data: {
    title:"New product title"
  }
}


const onEditTagsClick = async (productID, tags) => {
  await axios.put(`https://api.printify.com/v1/shops/${shopId}/products/60e0a5c198be4c1296798c27.json`, axiosTagUpdateOptions)
  .catch(err => console.log(err));
}

Problem

The get function works perfectly fine. But whenever I try to modify a product using the put method, like the documentation says, I get a 401 unauthorized error. But I'm using the same token for both the get and the put method. The token is set to global scope (for testing purposes) so I should be able to edit and delete products at will.

I read through the API documentation and it looks like I got everything right. I have the bearer token as the header and in the body I included the value I want to modify. Obviously the request is going through, I just don't know why it keeps saying I'm unauthorized to edit the product. I would have liked to edit the product from the printify UI, but the UI won't let me add tags (which is really annoying)... So I'm forced to update via a put method.

I couldn't find any reason for why I am getting this error, can anyone help me?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For put request you must pass data as a parameter and not in axiosOptions.

const onEditTagsClick = async (productID, tags) => {
  await axios.put(`https://api.printify.com/v1/shops/${shopId}/products/60e0a5c198be4c1296798c27.json`, data, axiosTagUpdateOptions)
  .catch(err => console.log(err));
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda