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

158
Visualizações
Easypost Node.js Example Difficulties?

I'm currently trying to implement the Easypost API however the example from the docs is console logging null on my front-end (localhost:3000)... does anyone know what I'm doing wrong? Thanks... First time using using firebase as well as easypost & react

functions/index.js:

const functions = require("firebase-functions");
const EasyPost = require("@easypost/api");

const api = new EasyPost(TEST_API_KEYS);

exports.buyShipping = functions.https.onCall((data, res) => {
  const shipment = new api.Shipment({
    from_address: {
      street1: "417 MONTGOMERY ST",
      street2: "FLOOR 5",
      city: "SAN FRANCISCO",
      state: "CA",
      zip: "94104",
      country: "US",
      company: "EasyPost",
      phone: "415-123-4567",
    },
    to_address: {
      name: "Dr. Steve Brule",
      street1: "179 N Harbor Dr",
      city: "Redondo Beach",
      state: "CA",
      zip: "90277",
      country: "US",
      phone: "4155559999",
    },
    parcel: {
      length: 8,
      width: 5,
      height: 5,
      weight: 5,
    },
  });

  shipment.save().then((s) => {
    s.buy(shipment.lowestRate()).then((result) => {
      return result;
    });
  });

  });
});

frontend:

import { initializeApp } from "firebase/app";
import { getFunctions, httpsCallable } from 'firebase/functions';

///

const app = initializeApp(firebaseConfig);
const functions = getFunctions(app);
const buyShipping = httpsCallable(functions, 'buyShipping')

const buy = async () => {              
       await buyShipping().then((result) => {
          /** @type {any} */
          console.log(result)
    })} 

///

<button onClick={buy}>Purchase</button>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It looks like you are console logging on your backend which won't do anything useful. You'll instead want to return the result of your buyShipping call from the backend so that your frontend can then display it on the page or console log it or whatever you are intending to do with it. Additionally, your two function calls don't share the same name so you aren't actually calling your backend most likely (based on the example provided). buyShipping is the name of the function on the backend but you are calling sendPackage on the frontend.

You'll want all your logic living on your backend Node server and do nothing with it there except return. Then all your "representation" logic (displaying, logging, etc) will happen on the frontend by calling those functions from the backend.

about 4 years ago · Juan Pablo Isaza Relatório

0

I found the problem; I can't have a return within the shipment.save function in my firebase backend... this worked:

exports.buyShipping = functions.https.onCall((data, res) => {
  const shipment = new api.Shipment({
    from_address: {
      street1: "417 MONTGOMERY ST",
      street2: "FLOOR 5",
      city: "SAN FRANCISCO",
      state: "CA",
      zip: "94104",
      country: "US",
      company: "EasyPost",
      phone: "415-123-4567",
    },
    to_address: {
      name: "Dr. Steve Brule",
      street1: "179 N Harbor Dr",
      city: "Redondo Beach",
      state: "CA",
      zip: "90277",
      country: "US",
      phone: "4155559999",
    },
    parcel: {
      length: 8,
      width: 5,
      height: 5,
      weight: 5,
    },
  });

  const arrayData = shipment.save().then((s) => {
    return s;
  });
  return arrayData;
});
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