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

177
Visualizações
Convert USPS Manager class C# code to JavaScript

I have some working USPS Manager C# code but need to execute it from Google Apps Script in JavaScript.

How would I convert the below to JavaScript format?

USPSManager m = new USPSManager("YOUR_USER_ID", true);
Address a = new Address();
a.Address2 = "6406 Ivy Lane";
a.City = "Greenbelt";
a.State = "MD";
Address addressWithZip = m.GetZipcode(a);
string zip = addressWithZip.Zip;

Thanks in advance for any tips.

Using the code outlined below in GAS I receive the below error: enter image description here

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

0

Here it is "translated" into JavaScript. Thing is, if USPS doesn't have a USPSManager class written in JavaScript, then this isn't going to work - or you'll have to write one yourself.

const m = new USPSManager("YOUR_USER_ID", true);
const a = new Address();
a.Address2 = "6406 Ivy Lane";
a.City = "Greenbelt";
a.State = "MD";
const addressWithZip = m.GetZipcode(a);
const zip = addressWithZip.Zip;
about 4 years ago · Juan Pablo Isaza Relatório

0

If you are writing code in JavaScript, using a C# library will not work. You need to use a JavaScript library.

A quick search on NPM found this usps-webtools package.

Here is how you would use it in code:

// Old CommonJS Modules syntax:
const USPS = require('usps-webtools');
// or, if your platform supports the newer ECMAScript Module syntax:
import USPS from 'usps-webtools';

const usps = new USPS({
    server: 'http://production.shippingapis.com/ShippingAPI.dll',
    userId: 'YOUR_USER_ID',
});

const address = {
  street2: '6406 Ivy Lane',
  city: 'Greenbelt',
  state: 'MD'
};

usps.zipCodeLookup(address, (error, address) => {
    if (error) {
        // handle error here
        return;
    }
    const zip = address.zip;
    // use that result here
});
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