### all method example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/insurance-service.md Example of listing insurances with a tracking_code filter. ```js const { insurances } = await client.Insurance.all({ tracking_code: 'EZ1000000001' }); ``` -------------------------------- ### makeApiCall GET example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/easypost-client.md Example of a GET request using makeApiCall. The method lowercases the HTTP method and passes query parameters for GET requests. ```js const result = await client.makeApiCall('get', '/addresses', { page_size: 10 }); ``` -------------------------------- ### List all carrier accounts example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/carrier-account-service.md Example of retrieving all carrier accounts. ```JavaScript const accounts = await client.CarrierAccount.all(); ``` -------------------------------- ### Fund wallet example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/billing-service.md Example call to fund the wallet with $50.00 using the secondary payment method. ```js await client.Billing.fundWallet('50.00', 'secondary'); ``` -------------------------------- ### Example: all Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/event-service.md Example usage of all. Retrieves events with page_size 50 and logs each event's description and result id. ```js const { events } = await client.Event.all({ page_size: 50 }); for (const event of events) { console.log(event.description, event.result?.id); } ``` -------------------------------- ### Development commands for EasyPost Node.js library Source: https://github.com/easypost/easypost-node/blob/master/README.md Development commands for the EasyPost Node.js library. Use `just install` to install dependencies, `just test` with the required API keys to run tests, and `just docs` to generate documentation. The `just lint-fix` command fixes linting issues, and `just update-examples-submodule` updates the examples submodule. ```bash # Install dependencies just install # Install style guides (Unix only) just install-styleguide # Update dependencies just update # Build the project just build # Lint the project just lint just lint-fix # Run tests (these will be transpiled on the fly) EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... just test EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... just coverage # Run security analysis just scan # Generate library documentation just docs # Update submodules just update-examples-submodule ``` -------------------------------- ### Get Next Page Example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/refund-service.md Example of fetching the next page of refunds, catching the `EndOfPaginationError` when no more pages exist. ```js try { const next = await client.Refund.getNextPage(page1); } catch (error) { // EndOfPaginationError } ``` -------------------------------- ### Rate.retrieve usage example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/parcel-customs-rate-services.md JavaScript example showing how to retrieve a rate and log its carrier, service, and rate. ```javascript const rate = await client.Rate.retrieve('rate_123'); console.log(rate.carrier, rate.service, rate.rate); ``` -------------------------------- ### CustomsItem.create usage example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/parcel-customs-rate-services.md JavaScript example showing how to create a customs item with the required fields. ```javascript const item = await client.CustomsItem.create({ description: 'Coffee', quantity: 1, weight: 10, value: 25.5, origin_country: 'US', }); ``` -------------------------------- ### create method example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/insurance-service.md Example of creating an insurance policy. Either address can be an Address instance or an ID string. ```js const insurance = await client.Insurance.create({ to_address: 'adr_123', from_address: 'adr_456', carrier: 'USPS', tracking_code: 'EZ1000000001', amount: '100.00', }); console.log(insurance.status); // 'new' | 'pending' | 'purchased' | ... ``` -------------------------------- ### Get next page example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/claim-service.md Example of getting the next page of claims. Catches EndOfPaginationError when no more pages exist. ```js try { const next = await client.Claim.getNextPage(page1); } catch (error) { // EndOfPaginationError } ``` -------------------------------- ### Retrieve claim example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/claim-service.md Example of retrieving a claim by ID and logging its status and status_detail. ```js const claim = await client.Claim.retrieve('clm_123'); console.log(claim.status, claim.status_detail); ``` -------------------------------- ### Example: retrieve Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/event-service.md Example usage of retrieve. Fetches an event and logs its status, pending URLs, and completed URLs. ```js const event = await client.Event.retrieve('evt_123'); console.log(event.status, event.pending_urls, event.completed_urls); ``` -------------------------------- ### retrieve method example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/insurance-service.md Example of retrieving an insurance by ID and logging its status and tracker. ```js const insurance = await client.Insurance.retrieve('ins_123'); console.log(insurance.status, insurance.tracker); ``` -------------------------------- ### Retrieve a pickup and get lowest rate Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/pickup-service.md Example of retrieving a pickup with `client.Pickup.retrieve` and then using the `lowestRate()` helper on the returned Pickup model. ```js const pickup = await client.Pickup.retrieve('pickup_123'); const cheapest = pickup.lowestRate(); // lowestRate() helper on the Pickup model ``` -------------------------------- ### Create customer portal account link example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/beta-services.md Example of creating a customer portal account link by calling the createAccountLink method on the client's CustomerPortal service. The session_type is set to 'account_onboarding' and the refresh and return URLs are provided. ```js const link = await client.CustomerPortal.createAccountLink({ session_type: 'account_onboarding', refresh_url: 'https://example.com/refresh', return_url: 'https://example.com/return', }); ``` -------------------------------- ### refund method example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/insurance-service.md Example of refunding an insurance by ID. ```js const refunded = await client.Insurance.refund('ins_123'); ``` -------------------------------- ### Retrieve an Order and get lowest rate Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/order-service.md Example of retrieving an Order and using the `lowestRate()` helper to get the cheapest rate. Logs the rate and carrier of the cheapest option. ```js const order = await client.Order.retrieve('order_123'); const cheapestRate = order.lowestRate(); // lowestRate() helper on the Order model console.log(cheapestRate.rate, cheapestRate.carrier); ``` -------------------------------- ### copyClient example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/easypost-client.md Example of copying a client with an overridden API key. Useful for creating a client scoped to a referral user's key. ```js const referralClient = EasyPostClient.copyClient(client, { apiKey: 'REFERRAL_PRODUCTION_KEY' }); ``` -------------------------------- ### Install @easypost/api with npm Source: https://github.com/easypost/easypost-node/blob/master/README.md Install the EasyPost Node client library from npm. Use this in a backend Node service, not in a browser. ```bash npm install --save @easypost/api ``` -------------------------------- ### Create claim example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/claim-service.md Example of creating a claim with typical parameters including tracking code, type, amount, contact email, recipient name, and payment method. ```js const claim = await client.Claim.create({ tracking_code: 'EZ1000000001', type: 'damage', amount: '50.00', contact_email: 'you@example.com', recipient_name: 'Steve Brule', payment_method: 'original_payment_method', }); ``` -------------------------------- ### Get rates for an Order Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/order-service.md Example of retrieving rates for an Order and logging the rates array. The response is destructured to get the `rates` property. ```js const { rates } = await client.Order.getRates('order_123'); console.log(rates); ``` -------------------------------- ### Get next page with client.Pickup.getNextPage Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/pickup-service.md Example of using `client.Pickup.getNextPage` to fetch the next page. Catch the `EndOfPaginationError` when no more pages exist. ```js try { const next = await client.Pickup.getNextPage(page1); } catch (error) { // EndOfPaginationError } ``` -------------------------------- ### Create embeddable session example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/beta-services.md Example of creating an embeddable session by calling the createSession method on the client's Embeddable service. The origin_host parameter is set to the example URL. ```js const session = await client.Embeddable.createSession({ origin_host: 'https://example.com' }); ``` -------------------------------- ### Example: retrievePayload Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/event-service.md Example usage of retrievePayload. Fetches a specific payload and logs its raw response body. ```js const payload = await client.Event.retrievePayload('evt_123', 'payload_456'); console.log(payload.response_body); // raw response captured from the webhook target ``` -------------------------------- ### Example: retrieveAllPayloads Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/event-service.md Example usage of retrieveAllPayloads. Fetches all payloads for event 'evt_123' and logs their response bodies. ```js const payloads = await client.Event.retrieveAllPayloads('evt_123'); console.log(payloads.map((p) => p.response_body)); ``` -------------------------------- ### List Refunds Example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/refund-service.md Example of retrieving all refunds. Returns an object with a `refunds` array and a `has_more` boolean. ```js const { refunds } = await client.Refund.all(); ``` -------------------------------- ### Retrieve Refund Example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/refund-service.md Example of retrieving a refund by ID and logging its status and confirmation number. ```js const refund = await client.Refund.retrieve('rfnd_123'); console.log(refund.status, refund.confirmation_number); ``` -------------------------------- ### Create carrier account example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/carrier-account-service.md Example of creating a UPS carrier account with credentials. Uses the type 'UpsAccount' and includes description and credentials. ```JavaScript const account = await client.CarrierAccount.create({ type: 'UpsAccount', description: 'UPS production', credentials: { account_number: '123456', password: 'pw' }, }); ``` -------------------------------- ### getNextPage method example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/insurance-service.md Example of fetching the next page, catching EndOfPaginationError. ```js try { const next = await client.Insurance.getNextPage(page1); } catch (error) { // EndOfPaginationError } ``` -------------------------------- ### Create Refunds Example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/refund-service.md Example of creating refunds for multiple tracking codes with a carrier. Returns a list of `Refund` objects. ```js const refunds = await client.Refund.create({ carrier: 'USPS', tracking_codes: ['EZ1000000001', 'EZ1000000002'], }); ``` -------------------------------- ### List claims example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/claim-service.md Example of listing claims with a page size of 25. Returns an object with claims and has_more properties. ```js const { claims } = await client.Claim.all({ page_size: 25 }); ``` -------------------------------- ### CustomsItem.retrieve usage example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/parcel-customs-rate-services.md JavaScript example showing how to retrieve a customs item by its ID. ```javascript const item = await client.CustomsItem.retrieve('cstitem_123'); ``` -------------------------------- ### List EndShippers Example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/end-shipper-service.md Example of listing all EndShippers and iterating over the results to log each name and zip code. ```js const { end_shippers } = await client.EndShipper.all(); end_shippers.forEach((es) => console.log(es.name, es.zip)); ``` -------------------------------- ### Observability hooks example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/easypost-client.md Example of using request and response hooks for observability. Hooks cannot mutate requests; they are for logging only. The example creates a client, adds hooks, performs a shipment creation, then removes a request hook and clears response hooks. ```js const client = new EasyPostClient(process.env.EASYPOST_API_KEY); client.addRequestHook((req) => console.log('Outgoing:', req)); client.addResponseHook((res) => console.log('Response:', res)); await client.Shipment.create({ parcel: { weight: 5 } }); client.removeRequestHook(log); client.clearResponseHooks(); ``` -------------------------------- ### recommendShipDate usage example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/beta-services.md JavaScript example calling client.SmartRate.recommendShipDate with from_postal_code, to_postal_code, and delivery_date. Returns the converted response. ```javascript const result = await client.SmartRate.recommendShipDate({ from_postal_code: '94104', to_postal_code: '90277', delivery_date: '2025-01-10', }); ``` -------------------------------- ### Create EndShipper Example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/end-shipper-service.md Example of creating an EndShipper with address fields. The address fields are sent under an 'address' key as per the endpoint's legacy contract. ```js const endShipper = await client.EndShipper.create({ name: 'Shipster', street1: '388 Townsend St', city: 'San Francisco', state: 'CA', zip: '94107', country: 'US', email: 'shipster@example.com', }); ``` -------------------------------- ### Retrieve carrier account example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/carrier-account-service.md Example of retrieving a carrier account by ID and logging its type and billing_type. ```JavaScript const account = await client.CarrierAccount.retrieve('ca_123'); console.log(account.type, account.billing_type); ``` -------------------------------- ### Retrieve payment methods example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/billing-service.md Example of retrieving payment methods and handling the InvalidObjectError when no payment methods exist. ```js try { const methods = await client.Billing.retrievePaymentMethods(); console.log(methods.primary_payment_method); } catch (error) { // InvalidObjectError when no payment methods exist } ``` -------------------------------- ### Create Refunds Error Handling Example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/refund-service.md Example of error handling when creating refunds. Logs the error's status code and message. ```js try { await client.Refund.create({ carrier: 'USPS', tracking_codes: ['INVALID'] }); } catch (error) { console.error(error.statusCode, error.message); } ``` -------------------------------- ### Create a pickup with client.Pickup.create Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/pickup-service.md Example of creating a pickup with the `client.Pickup.create` method. Provide the address, shipment, reference, time window, instructions, and whether it is an account address. ```js const pickup = await client.Pickup.create({ address: 'adr_123', shipment: 'shp_123', reference: 'my-pickup', min_datetime: '2025-01-02T09:00:00Z', max_datetime: '2025-01-02T17:00:00Z', instructions: 'Ring the doorbell', is_account_address: false, }); ``` -------------------------------- ### List pickups with client.Pickup.all Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/pickup-service.md Example of listing pickups with `client.Pickup.all`. Pass query parameters like `page_size` to control the result set. ```js const { pickups } = await client.Pickup.all({ page_size: 10 }); ``` -------------------------------- ### Example: getLowestSmartRate with valid accuracy Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/utils.md Example usage of getLowestSmartRate. Fetches smart rates for a shipment ID and then finds the cheapest rate with a delivery time within 3 days at the 90th percentile accuracy. ```js const smartrates = await client.Shipment.getSmartRates('shp_123'); const cheapest = client.Utils.getLowestSmartRate(smartrates, 3, 'percentile_90'); ``` -------------------------------- ### Get next page of ScanForms with error handling Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/scan-form-service.md Example of getting the next page of ScanForms. Catches EndOfPaginationError when no more pages exist. ```js try { const next = await client.ScanForm.getNextPage(page1); } catch (error) { // EndOfPaginationError } ``` -------------------------------- ### Create CustomsInfo Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/parcel-customs-rate-services.md JavaScript example using client.CustomsInfo.create with contents type, certification, and customs items. ```javascript const customsInfo = await client.CustomsInfo.create({ contents_type: 'merchandise', customs_certify: true, customs_signer: 'Steve', non_delivery_option: 'return', restriction_type: 'none', customs_items: [{ description: 'T-shirt', quantity: 2, weight: 6, value: 20 }], }); ``` -------------------------------- ### Buy a pickup with client.Pickup.buy Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/pickup-service.md Example of buying a pickup with the `client.Pickup.buy` method. Pass the pickup ID, carrier, and service name. ```js const bought = await client.Pickup.buy('pickup_123', 'UPS', 'Same-Day Pickup'); ``` -------------------------------- ### Call BetaReferralCustomer.createCreditCardClientSecret Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/beta-services.md Example call to create a credit card client secret. ```js const secret = await client.BetaReferralCustomer.createCreditCardClientSecret(); ``` -------------------------------- ### GET refunds Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves a list of refunds with optional filters. ```APIDOC ## GET refunds ### Description Retrieves a list of refunds with optional filters. ### Method GET ### Endpoint refunds ### Parameters #### Query Parameters - **filters** (object) - Optional - Query parameters to filter the list. ### Response #### Success Response (200) - **refunds** (array of Refund) - List of refunds. - **has_more** (boolean) - Indicates if there are more results. #### Response Example { "refunds": [ { "id": "rfnd_...", "shipment_id": "shp_...", "status": "submitted" } ], "has_more": false } ``` -------------------------------- ### GET refunds/{id} Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves a specific refund by its ID. ```APIDOC ## GET refunds/{id} ### Description Retrieves a specific refund by its ID. ### Method GET ### Endpoint refunds/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the refund to retrieve. ### Response #### Success Response (200) - **Refund** (object) - The requested refund. #### Response Example { "id": "rfnd_...", "shipment_id": "shp_...", "status": "submitted" } ``` -------------------------------- ### GET insurances Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves a list of insurances with optional filters. ```APIDOC ## GET insurances ### Description Retrieves a list of insurances with optional filters. ### Method GET ### Endpoint `insurances` ### Parameters #### Query Parameters - **filters** (object) - Optional - Filter criteria for the list. ### Response #### Success Response (200) - **insurances** (array of Insurance) - List of insurance objects. - **has_more** (boolean) - Indicates if there are more results. #### Response Example ```json { "insurances": [ { "id": "ins_..." } ], "has_more": false } ``` ``` -------------------------------- ### Retrieve EndShipper Example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/end-shipper-service.md Example of retrieving an EndShipper by its ID. ```js const endShipper = await client.EndShipper.retrieve('es_123'); ``` -------------------------------- ### Call BetaReferralCustomer.refundByAmount Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/beta-services.md Example call to refund by amount, passing 5000 cents. ```js const refund = await client.BetaReferralCustomer.refundByAmount(5000); ``` -------------------------------- ### GET referral_customers Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves a list of referral customers with optional filters. ```APIDOC ## GET referral_customers ### Description Retrieves a list of referral customers with optional filters. ### Method GET ### Endpoint referral_customers ### Parameters #### Query Parameters - **filters** (object) - Optional - Query parameters to filter the list. ### Response #### Success Response (200) - **referral_customers** (array of User) - List of referral customers. - **has_more** (boolean) - Indicates if there are more results. #### Response Example { "referral_customers": [ { "id": "user_...", "email": "..." } ], "has_more": false } ``` -------------------------------- ### Create an Order with client.Order.create Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/order-service.md Example of creating an Order by passing address IDs and shipment IDs. The `to_address` and `from_address` can be Address objects or ID strings, and `shipments` can be Shipment models or ID strings. ```js const order = await client.Order.create({ to_address: 'adr_123', from_address: 'adr_456', shipments: ['shp_111', 'shp_222'], }); ``` -------------------------------- ### Delete carrier account example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/carrier-account-service.md Example of deleting a carrier account by ID. ```JavaScript await client.CarrierAccount.delete('ca_123'); ``` -------------------------------- ### Create a webhook with client.Webhook.create Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/webhook-service.md Example of creating a webhook with a URL and a webhook secret. ```js const webhook = await client.Webhook.create({ url: 'https://example.com/hooks/easypost', webhook_secret: 'shh-secret', }); ``` -------------------------------- ### GET orders/{id}/rates Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves rates for a specific order. ```APIDOC ## GET orders/{id}/rates ### Description Retrieves rates for a specific order. ### Method GET ### Endpoint `orders/{id}/rates` ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the order. ### Response #### Success Response (200) - **rates** (array of Rate) - List of rate objects. #### Response Example ```json { "rates": [ { "id": "rate_..." } ] } ``` ``` -------------------------------- ### List all webhooks with client.Webhook.all Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/webhook-service.md Example of retrieving all webhooks. The response includes an optional `has_more` flag. ```js const { webhooks } = await client.Webhook.all(); ``` -------------------------------- ### GET shipments Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves a list of shipments, optionally filtered by query parameters. ```APIDOC ## GET shipments ### Description Retrieves a list of shipments, optionally filtered by query parameters. ### Method GET ### Endpoint shipments ### Parameters #### Query Parameters - **filters** (object) - Optional - Filtering criteria for the shipments list. ### Response #### Success Response (200) - **shipments** (array) - List of Shipment objects. - **has_more** (boolean) - Indicates if there are more results. #### Response Example { "shipments": [ { "id": "shp_123" } ], "has_more": false } ``` -------------------------------- ### GET shipments/{id}/label Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves the label for a shipment in a specified file format. ```APIDOC ## GET shipments/{id}/label ### Description Retrieves the label for a shipment in a specified file format. ### Method GET ### Endpoint shipments/{id}/label ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the shipment. #### Query Parameters - **file_format** (string) - Required - The desired label file format (e.g., PDF, PNG). ### Response #### Success Response (200) - **Shipment** (object) - The shipment with label information. #### Response Example { "id": "shp_123", "label_url": "https://..." } ``` -------------------------------- ### GET shipments/{id}/smartrate/delivery_date Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves smart rates with delivery date estimates for a shipment. ```APIDOC ## GET shipments/{id}/smartrate/delivery_date ### Description Retrieves smart rates with delivery date estimates for a shipment. ### Method GET ### Endpoint shipments/{id}/smartrate/delivery_date ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the shipment. #### Query Parameters - **planned_ship_date** (string) - Required - The planned ship date. ### Response #### Success Response (200) - **rates** (array) - Array of rates with delivery date estimates. #### Response Example { "rates": [ { "id": "rate_123", "delivery_date": "2023-01-01" } ] } ``` -------------------------------- ### GET reports/{type} Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves a list of reports of the specified type with optional filters. ```APIDOC ## GET reports/{type} ### Description Retrieves a list of reports of the specified type with optional filters. ### Method GET ### Endpoint reports/{type} ### Parameters #### Path Parameters - **type** (string) - Required - The type of report to retrieve. #### Query Parameters - **filters** (object) - Optional - Query parameters to filter the list, excluding `type`. ### Response #### Success Response (200) - **reports** (array of Report) - List of reports. - **has_more** (boolean) - Indicates if there are more results. #### Response Example { "reports": [ { "id": "rept_...", "type": "shipment", "status": "available" } ], "has_more": false } ``` -------------------------------- ### GET partners/stripe_public_key Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves the Stripe public key used for credit card tokenization. ```APIDOC ## GET partners/stripe_public_key ### Description Retrieves the Stripe public key used for credit card tokenization. ### Method GET ### Endpoint partners/stripe_public_key ### Parameters None ### Response #### Success Response (200) - **public_key** (string) - The Stripe public key. #### Response Example { "public_key": "pk_..." } ``` -------------------------------- ### Cancel claim example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/claim-service.md Example of canceling a claim by ID. Returns the canceled Claim. ```js const canceled = await client.Claim.cancel('clm_123'); ``` -------------------------------- ### Create a tracker with tracking_code and carrier Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/tracker-service.md Example of creating a tracker with a tracking code and carrier. Returns the created Tracker object. ```js const tracker = await client.Tracker.create({ tracking_code: 'EZ1000000001', carrier: 'USPS', }); ``` -------------------------------- ### GET shipments/{id}/smartrate/precision_shipping Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves smart rates with precision shipping estimates for a shipment. ```APIDOC ## GET shipments/{id}/smartrate/precision_shipping ### Description Retrieves smart rates with precision shipping estimates for a shipment. ### Method GET ### Endpoint shipments/{id}/smartrate/precision_shipping ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the shipment. #### Query Parameters - **desired_delivery_date** (string) - Required - The desired delivery date. ### Response #### Success Response (200) - **rates** (array) - Array of rates with precision shipping estimates. #### Response Example { "rates": [ { "id": "rate_123", "precision_shipping": "2023-01-01" } ] } ``` -------------------------------- ### GET scan_forms Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/endpoints.md Retrieves a list of scan forms, optionally filtered by query parameters. ```APIDOC ## GET scan_forms ### Description Retrieves a list of scan forms, optionally filtered by query parameters. ### Method GET ### Endpoint scan_forms ### Parameters #### Query Parameters - **filters** (object) - Optional - Filtering criteria for the scan forms list. ### Response #### Success Response (200) - **scan_forms** (array) - List of ScanForm objects. - **has_more** (boolean) - Indicates if there are more results. #### Response Example { "scan_forms": [ { "id": "sf_123" } ], "has_more": false } ``` -------------------------------- ### Delete payment method example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/billing-service.md Example call to delete the primary payment method. ```js await client.Billing.deletePaymentMethod('primary'); ``` -------------------------------- ### Create an API key Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/api-key-service.md Example usage of the create method to create an API key in production mode. ```js const apiKey = await client.ApiKey.create('production'); ``` -------------------------------- ### Retrieve all API keys Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/api-key-service.md Example usage of the all method to fetch and log the parent user object with keys and children. ```js const keys = await client.ApiKey.all(); console.log(keys.id, keys.keys, keys.children); ``` -------------------------------- ### CarrierMetadata.retrieve usage example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/parcel-customs-rate-services.md JavaScript example showing how to retrieve carrier metadata for USPS service levels. ```javascript const metadata = await client.CarrierMetadata.retrieve(['usps'], ['service_levels']); console.log(metadata); ``` -------------------------------- ### Enable an API key Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/api-key-service.md Example usage of the enable method to enable an API key and log its active status. ```js const apiKey = await client.ApiKey.enable('ak_123'); console.log(apiKey.active); // true ``` -------------------------------- ### Constructor Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/easypost-client.md Creates a new EasyPost client instance with the provided API key and options. The constructor validates the API key and initializes the HTTP client, middleware, and services. ```APIDOC ## Constructor ### Description Creates a new EasyPost client instance with the provided API key and options. ### Method constructor ### Parameters - **key** (string) - Optional - The API key used for Authorization (Basic auth) on every request. Required unless `options.useProxy` is truthy. - **options** (ClientOptions) - Optional - Additional client options including `timeout`, `baseUrl`, `httpClient`, `httpMiddleware`, `requestMiddleware`, and `useProxy`. ### Request Example ```js const client = new EasyPostClient(process.env.EASYPOST_API_KEY, { timeout: 120000, baseUrl: 'https://api.easypost.com/v2/', useProxy: false, httpClient: fetch, httpMiddleware: (httpFn) => (input, init) => httpFn(input, init), }); ``` ### Response No return value. The client instance is created with attached services. ### Error Handling - Throws `MissingParameterError` if no API key is provided and `useProxy` is not truthy. - Throws `Error` if the resolved `httpClient` is not a function. ``` -------------------------------- ### Construct EasyPostClient with options Source: https://github.com/easypost/easypost-node/blob/master/README.md Construct an EasyPostClient with custom options: timeout (ms), baseUrl, useProxy, httpMiddleware, httpClient, and requestMiddleware. The example sets a 120000 ms timeout, a custom base URL, disables proxy, and uses identity functions for middleware. ```javascript const client = new EasyPostClient(process.env.EASYPOST_API_KEY, { timeout: 120000, baseUrl: 'https://api.easypost.com/v2/', useProxy: false, httpMiddleware: (f) => f, httpClient: fetch, requestMiddleware: (r) => r, }); ``` -------------------------------- ### Create and buy an Order using lowestRate Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/order-service.md Example of creating an Order with shipment objects and then buying it using the lowest rate. The `buy` method requires a carrier and service that match a rate returned for the order. ```js const order = await client.Order.create({ shipments: [shipment1, shipment2] }); const bought = await client.Order.buy(order.id, order.lowestRate().carrier, order.lowestRate().service); ``` -------------------------------- ### Update carrier account example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/carrier-account-service.md Example of updating a carrier account's description using its ID. ```JavaScript const updated = await client.CarrierAccount.update('ca_123', { description: 'New description' }); ``` -------------------------------- ### GET webhooks/{id} Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/webhook-service.md Retrieves a single Webhook object by sending a GET request to the `webhooks/{id}` endpoint. ```APIDOC ## GET webhooks/{id} ### Description Retrieves a single Webhook object by sending a GET request to the `webhooks/{id}` endpoint. ### Method GET ### Endpoint `webhooks/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the Webhook to retrieve. ### Response #### Success Response (200) Returns the requested `Webhook` object. #### Response Example ```json { "id": "hook_123", "url": "https://example.com/hooks/easypost", "webhook_secret": "shh-secret", "disabled_at": null, "custom_headers": null } ``` ### Error Handling Rejects with an `ApiError`-family error on failure. ``` -------------------------------- ### Call BetaReferralCustomer.createBankAccountClientSecret Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/beta-services.md Example call to create a bank account client secret with a return URL. ```js const session = await client.BetaReferralCustomer.createBankAccountClientSecret('https://example.com/callback'); ``` -------------------------------- ### retrieveStatelessRates usage example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/beta-services.md JavaScript example calling client.BetaRate.retrieveStatelessRates with from_address, to_address, and parcel. Reads rates from response.rates. ```javascript const response = await client.BetaRate.retrieveStatelessRates({ from_address: { zip: '94104' }, to_address: { zip: '90277' }, parcel: { weight: 5 }, }); const rates = response.rates; ``` -------------------------------- ### all JavaScript usage Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/referral-customer-service.md Example call to retrieve all referral customers, destructuring the referral_customers array from the response. ```javascript const { referral_customers } = await client.ReferralCustomer.all(); ``` -------------------------------- ### estimateDeliveryDate usage example Source: https://github.com/easypost/easypost-node/blob/master/_autodocs/api-reference/beta-services.md JavaScript example calling client.SmartRate.estimateDeliveryDate with from_postal_code, to_postal_code, and ship_date. Returns the converted response. ```javascript const result = await client.SmartRate.estimateDeliveryDate({ from_postal_code: '94104', to_postal_code: '90277', ship_date: '2025-01-01', }); ```