Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

419
Vistas
Change global variable to response data inside axios call
var payUrl;
var orderId;

async function getInvoice() {
    var data = JSON.stringify({
        "price_amount": 10,
        "price_currency": "gbp",
      });
      
      var config = {
        method: 'post',
        url: 'https://api.nowpayments.io/v1/invoice',
        headers: { 
          'x-api-key': 'api-key', 
          'Content-Type': 'application/json'
        },
        data : data
      };
      
      axios(config)
      .then(function (response) {
        orderId = response.data.id;
        payUrl = response.data.invoice_url;
      });
}

getInvoice();

console.log(payUrl);

This code returns undefined. I need the code to set the global variable to the response data needed so i can access it in other functions.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda