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

540
Visualizações
How to Display Value Created from API Onto My Browser?

So I am working with this API and it auto calculates the delivery fee based on the address you input.

Here's the API docs I am using https://developer.doordash.com/en-US/api/drive#operation/DeliveryQuote

So when I add my values to my form and get my data, it logs the fee in my console like this

enter image description here

My issue is how do I get this value from the data field?

I tried to do

 const response = await client.createDelivery(
      {
        order_value: req.body.item1,
        fee: fee,
        tip: req.body.item1,
      },
      console.log(fee)
    );

    console.log(response);

    res.send(response);
  }
 )

But it says fee is not defined?

I also tried fee: "" and that doesn't work either.

I even put console.log(data.fee) and it says data is not defined

My last attempt I change it to console.log(response.fee) and it still showed undefined in the console?

How do I even get the fee value to console.log?

Note I am using express and for my tip value I have my input form named "item1" so I can access it by saying req.body.item1 to get that value

However, for the fee value its auto generated by the API, so I can't change it or update it manually myself.

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

0

this is what the return object looks like

{
  data {
    currency: 'USD',
    fee: 975,
    otherData: otherData,
  }
}

what you must do to fix your problem is first dive into the data object then retrieve fee from that object like data.fee

const response = await client.createDelivery(
  {
    order_value: req.body.item1,
    fee: data.fee, // changed from fee to data.fee
    tip: req.body.item1,
  },
  console.log(data.fee)
);

without retrieving it from the data object there would be no fee object to grab which is whats making it undefined...

about 4 years ago · Juan Pablo Isaza Relatório

0

Try using

console.log(response.data.fee)

And I am not sure what your client.createDelivery does. If it sends response, then you need to display it like

const response = await client.createDelivery(
  {
    order_value: req.body.item1,
    fee: fee,
    tip: req.body.item1,
  },
  console.log(fee)
).then((res) => res.json()).then((resData) => console.log(resData.data.fee));
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