Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

417
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!