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

197
Visualizações
Send Expo Push Notification to an Array of Token

I'm trying to send push notification to several devices with an array of token coming from an api. When I send to only one object, the push notification is sent correctly, but when I do it through an array of objects, it gives error 400 in the request.

//assembling the array of tokens coming from the api
let tokenArray = [];
this.dataObj.notification_tokens.map((item) => {
  tokenArray.push({
    to: item.push_token,
    sound: "default",
    title: this.dataObj.push_title,
    body: this.dataObj.push_message,
  });
});

//passing the array as a parameter of the Expo Push Notification request. I receive 400 error
 await fetch("https://exp.host/--/api/v2/push/send", {
  mode: "no-cors",
  method: "POST",
  headers: {
    Accept: "application/json",
    "Accept-encoding": "gzip, deflate",
    "Content-Type": "application/json",
  },
  body: JSON.stringify(tokenArray),
}).then((res) => {
  if (res) {
    this.dataObj.push_title = "";
    this.dataObj.push_message = "";
    this.goSuccess("Push Notification sending!");
  }
});

If I pass a single object as a parameter of the Expo request, the push notification is sent normally

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

0

I couldn't find a solution using the frontend, so I made an endpoint to send push through the backend. So the backend takes care of all the bulk shipping.

const dataObj = {
  sound: "default",
  title: this.dataObj.push_title,
  body: this.dataObj.push_message,
};
await this.$http
  .post(`/push/send-notification`, dataObj)
  .then((response) => {
    if (!response.data.success) {
      this.goError(response.data.message);
    } else {
      this.goSuccess(response.data.message);
      this.dataObj.push_title = "";
      this.dataObj.push_message = "";
    }
  })
  .catch(function (error) {
    console.log(error);
  });

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