### Installing PostGrid Node.js Client with npm Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to install the `postgrid-node-client` library using the npm package manager. It's the standard way to add the client to your Node.js project dependencies. ```bash npm install postgrid-node-client ``` -------------------------------- ### Initializing PostGrid Client with Webhook Configuration (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This example demonstrates how to initialize the PostGrid client while also configuring webhook options. It allows specifying a `webhookUrl` for callbacks, a `webhookSecret` for payload encryption, and an array of `webhookEvents` to subscribe to. ```typescript const client = new PostGrid({ mail: '[Your Mail API Key]', addr: '[Your Addr API Key]' }, { webhookUrl: 'https://my.service.com/postgrid/callback', webhookSecret: 'abc123456the-tall-brown-bear', webhookEvents: ['letter.created', 'letter.updated'] } ) ``` -------------------------------- ### Example Response for Creating a Webhook (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet shows the successful response structure after creating a webhook. It includes the webhook's `id`, `description`, `url`, `enabledEvents`, and a `secret` for verification, confirming its successful creation and configuration. ```javascript { "success": true, "webhook": { "id": "webhook_wb6AAoBMcm1CNwWH3mkbr1", "object": "webhook", "live": false, "description": "Cool new webhook", "enabled": true, "enabledEvents": [ "letter.created" ], "secret": "webhook_secret_uAMxoCjLyHoCFWoA6XvhdC", "url": "https://my.service.com/postgrid/callback", "createdAt": "2021-07-15T20:11:51.032Z", "updatedAt": "2021-07-15T20:11:51.032Z" } } ``` -------------------------------- ### Example Response for Listing Webhook Invocations (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON object demonstrates the expected response when listing webhook invocations. It includes pagination metadata (`limit`, `skip`, `totalCount`) and a `data` array which will contain invocation records if any exist for the specified webhook. ```javascript { "success": true, "invocations": { "object": "list", "limit": 40, "skip": 0, "totalCount": 0, "data": [] } } ``` -------------------------------- ### Example Success Response for Address Lookup Info (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON object represents a successful response from the address lookup info call. It provides the `status`, a `message`, and `data` containing `freeLimit` (total available lookups) and `used` (current consumption). ```javascript { "success": true, "info": { "status": "success", "message": "Successfully retrieved addver info.", "data": { "freeLimit": 500, "used": 5 } } } ``` -------------------------------- ### Example Response for Listing Webhooks (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON object illustrates the typical response structure when listing webhooks using the PostGrid API. It includes pagination details (`limit`, `skip`, `totalCount`) and an array of webhook objects, each containing details like ID, object type, live status, description, enabled events, secret, URL, and timestamps. ```javascript { "success": true, "webhooks": { "object": "list", "limit": 40, "skip": 0, "totalCount": 1, "data": [ { "id": "webhook_rqjK6m3T71butzwSd7zU4N", "object": "webhook", "live": false, "description": "Cool new webhook", "enabled": true, "enabledEvents": [ "letter.created" ], "secret": "webhook_secret_ve1xLLrBWRfDhjhNZZMRn3", "url": "https://my.service.com/postgrid/callback", "createdAt": "2021-07-15T20:14:11.060Z", "updatedAt": "2021-07-15T20:14:11.060Z" } ] } } ``` -------------------------------- ### Get Autocomplete Previews Call (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md Demonstrates how to use the "autocompletePreviews" function to retrieve a list of partial address suggestions based on a given street address. This function helps users find potential addresses before full autocompletion. ```typescript const list = await client.address.autocompletePreviews('77 main st') ``` -------------------------------- ### Example Response for Listing Checks (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet illustrates the expected structure of the response when listing checks using the PostGrid API. It includes pagination details like `limit`, `skip`, and `totalCount`, along with an array of `data` containing individual check objects, each with detailed properties such as `id`, `amount`, `bankAccount`, and contact information. ```javascript { "success": true, "checks": { "object": "list", "limit": 40, "skip": 0, "totalCount": 3, "data": [ { "id": "cheque_1rLks7fM6nSC1jNpidv1fg", "object": "cheque", "live": false, "amount": 10000, "bankAccount": "bank_gMpKxPyiGzt1ZwACTmLHHn", "currencyCode": "USD", "description": "Cool new check", "from": { "id": "contact_fo3HwdeFZ3wwNuHFAgszHt", "object": "contact", "addressLine1": "123 MAIN STREET", "addressLine2": null, "addressStatus": "verified", "city": "ATLANTA", "companyName": "US Steel", "country": "UNITED STATES", "countryCode": "US", "firstName": "John", "lastName": "Quincy", "postalOrZip": "12345", "provinceOrState": "GA" }, "letterHtml": "Hello {{to.firstName}}", "memo": "Invoice 1233", "number": 9667, "sendDate": "2021-07-19T10:02:28.324Z", "status": "ready", "to": { "id": "contact_f8NLBJXjV82HnM8emVow3r", "object": "contact", "addressLine1": "5454 WEST 34TH STREET", "addressLine2": null, "addressStatus": "verified", "city": "INDIANAPOLIS", "companyName": "Acme Rentals", "country": "UNITED STATES", "countryCode": "US", "firstName": "Steve", "lastName": "Smith", "postalOrZip": "46224", "provinceOrState": "IN" }, "createdAt": "2021-07-19T10:02:28.327Z", "updatedAt": "2021-07-19T10:02:28.327Z" }, ... ] } } ``` -------------------------------- ### Example Error Response for Address Lookup Info (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON object illustrates an error response from the address lookup info call. It indicates `success: false`, `verified: false`, and includes an `error` object with `type` and `message` detailing the issue encountered during the lookup. ```javascript { "success": false, "verified": false, "error": { "type": "PostGrid_type", "message": "(Error message from PostGrid...)" } } ``` -------------------------------- ### Example Response for Deleting a Webhook (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON object illustrates the response received after successfully deleting a webhook. It confirms the `success` status and provides details of the deleted webhook, including its `id`, `object` type, and a `deleted` flag set to `true`. ```javascript { "success": true, "webhook": { "id": "webhook_rqjK6m3T71butzwSd7zU4N", "object": "webhook", "deleted": true } } ``` -------------------------------- ### Example Error Response from PostGrid API (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet illustrates the standard error response format from the PostGrid API. When an operation fails, the `success` field will be `false`, and an `error` object will provide details, including the `type` of error (e.g., `PostGrid_type`) and a descriptive `message`. ```javascript { "success": false, "error": { "type": "PostGrid_type", "message": "(Error message from PostGrid...)" } } ``` -------------------------------- ### Bank Account Creation Error Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet shows an example of an error response from the PostGrid API when bank account creation fails. The "success" flag is "false", and an "error" object provides details including the "type" of error (e.g., 'PostGrid_type') and a descriptive "message". ```javascript { "success": false, "error": { "type": "PostGrid_type", "message": "(Error message from PostGrid...)" } } ``` -------------------------------- ### Example Response for Deleting a Check (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet illustrates the expected response structure after successfully deleting a check. It indicates `success: true` and provides the `id` and `object` type of the deleted check, along with a `deleted: true` flag. ```javascript { "success": true, "check": { "id": "cheque_7GrdUQPmbkAXJg8vLkJK9B", "object": "cheque", "deleted": true } } ``` -------------------------------- ### Retrieving a Postcard by ID (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to retrieve the details of an existing postcard using its unique ID. The `get` method of the `client.postcard` object takes the postcard's ID as a parameter and returns a postcard object similar to the one received during a successful creation. ```typescript const doc = await client.postcard.get(id) ``` -------------------------------- ### Running PostGrid Client Tests (Bash) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This Bash command demonstrates how to execute the self-contained test scripts for the PostGrid client using npm. Running this command will initiate a series of API calls to create, fetch, list, and delete contacts, reporting 'Success!' for each completed step. ```bash $ npm run ts tests/contacts.ts creating a single Contact... Success! fetching a single Contact... Success! listing the first page of 40 Contacts... Success! deleting a single Contact... Success! ``` -------------------------------- ### Initializing PostGrid Client with Mail API Key (Legacy, TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet shows the legacy constructor for the PostGrid client, where only the Print-Mail API key is provided directly as a string. This method is suitable if you only subscribe to the Print-Mail service. ```typescript import { PostGrid } from 'postgrid-node-client' const client = new PostGrid('[Your Mail API Key]') ``` -------------------------------- ### Initializing PostGrid Client with Both API Keys (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This code initializes the PostGrid client with both Print-Mail and Address Verification API keys. It's the recommended way to set up the client when subscribing to both PostGrid services, allowing access to all functionalities. ```typescript import { PostGrid } from 'postgrid-node-client' const client = new PostGrid({ mail: '[Your Mail API Key]', addr: '[Your Addr API Key]' }) ``` -------------------------------- ### Creating a Webhook with PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to create a new webhook using the PostGrid Node.js client. It requires a `description`, a `url` where PostGrid will send notifications, and an array of `enabledEvents` to subscribe to. This webhook will serve as the notification system for any updates on the specified events. ```typescript const letter = await client.webhook.create({ description: 'Cool new webhook', url: 'https://my.service.com/postgrid/callback', enabledEvents: ['letter.created'], }) ``` -------------------------------- ### Creating a Bank Account using PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to create a new bank account with the PostGrid API using the Node.js client. It requires providing detailed bank information such as description, bank name, address, routing number, account number, and signature text. The client.bankAccount.create method sends this data to the API. ```typescript const account = await client.bankAccount.create({ description: 'This is where to put your marshmallows', bankName: 'Bank of Marshmallows', bankPrimaryLine: '3288 Tara Lane', bankSecondaryLine: 'Indianapolis, IN', bankCountryCode: 'US', routingNumber: '123456789', accountNumber: '100010001001', signatureText: 'Stay Puff' }) ``` -------------------------------- ### Listing All Webhooks in PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet shows how to list all webhooks associated with the API Key. It supports optional `limit` and `skip` parameters for pagination, defaulting to `skip: 0` and `limit: 40` if omitted. The function returns a list object containing webhook data. ```typescript const doc = await client.webhook.list() ``` -------------------------------- ### Retrieving Address Lookup Information in PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to query the status of free address lookups available through PostGrid. The `client.address.lookupInfo()` call returns information about the free lookup limit and current usage, allowing users to monitor their quota. ```typescript const info = await client.address.lookupInfo() ``` -------------------------------- ### Creating a Letter from a PDF Buffer using PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet illustrates how to create a letter by loading a PDF file from the local filesystem into a Node.js Buffer and passing it as the 'pdf' source. This method requires importing the 'fs' module to read the file. ```typescript import fs from 'fs' const doc = fs.readFileSync('/my/local/file.pdf') const letter = await client.letter.create({ description: 'Cool new letter', pdf: doc, to: 'contact_f8NLBJXjV82HnM8emVow3r', from: 'contact_fo3HwdeFZ3wwNuHFAgszHt' }) ``` -------------------------------- ### Listing Bank Accounts using PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet shows how to list all bank accounts associated with the API Key using the PostGrid Node.js client. The `client.bankAccount.list` method supports optional `limit` and `skip` parameters for pagination, defaulting to `skip: 0` and `limit: 40` if omitted. ```typescript const accts = await client.bankAccount.list() ``` -------------------------------- ### Listing Webhook Invocations in PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet retrieves a list of invocations for a specific webhook identified by its `id`. Similar to listing webhooks, it supports optional `limit` and `skip` parameters for pagination, defaulting to `skip: 0` and `limit: 40`. The response includes invocation details for the specified webhook. ```typescript const doc = await client.webhook.invocations(id) ``` -------------------------------- ### Creating a Postcard with Full Address Details (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to create a postcard by providing complete 'to' and 'from' address details directly within the `create` method. It specifies the postcard's description, size, and HTML content for both front and back sides. This method allows for on-the-fly contact creation or reuse if the contact already exists. ```typescript const postcard = await client.postcard.create({ description: 'Cool new postcard', size: '6x4', frontHTML: 'Hello, {{to.firstName}}', backHTML: 'Hello again, {{to.firstName}}', to: { firstName: 'Steve', lastName: 'Smith', companyName: 'Acme Rentals', addressLine1: '5454 West 34th Street', city: 'Indianapolis', provinceOrState: 'IN', postalOrZip: '46224', countryCode: 'US' }, from: { firstName: 'John', lastName: 'Quincy', companyName: 'US Steel', addressLine1: '123 Main Street', city: 'Atlanta', provinceOrState: 'GA', postalOrZip: '12345', countryCode: 'US' } }) ``` -------------------------------- ### Successful Autocomplete Previews Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md Represents a successful response from the PostGrid "autocompletePreviews" API. It contains a "success" flag and a "previews" object with a "data" array, listing partial address suggestions including "line1", "city", and "provinceOrState". ```javascript { "success": true, "previews": { "status": 'success', "message": 'Retrieved verified address completions successfully.', "data": [ { "line1": '77 N MAIN ST', "city": undefined, "provinceOrState": 'UT' }, { "line1": '77 S MAIN ST', "city": undefined, "provinceOrState": 'UT' }, { "line1": '77 N MAIN ST', "city": undefined, "provinceOrState": 'UT' }, { "line1": '77 S MAIN ST', "city": undefined, "provinceOrState": 'UT' }, { "line1": '77 E MAIN ST', "city": undefined, "provinceOrState": 'UT' }, { "line1": '77 W MAIN ST', "city": undefined, "provinceOrState": 'UT' }, { "line1": '77 N MAIN ST', "city": 'ABERDEEN', "provinceOrState": 'ID' }, { "line1": '77 S MAIN ST', "city": 'ABERDEEN', "provinceOrState": 'ID' }, { "line1": '77 N MAIN ST', "city": 'ABERDEEN', "provinceOrState": 'SD' }, { "line1": '77 S MAIN ST', "city": 'ABERDEEN', "provinceOrState": 'SD' } ] } } ``` -------------------------------- ### Successful Bank Account Creation Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet illustrates a successful response from the PostGrid API after creating a bank account. It includes the "success" flag set to "true" and an "account" object containing details like "id", "object" type, "live" status, and all provided bank account information, along with "createdAt" and "updatedAt" timestamps. ```javascript { "success": true, "account": { "id": "bank_gMpKxPyiGzt1ZwACTmLHHn", "object": "bank_account", "live": false, "accountNumberLast4": "1001", "bankCountryCode": "US", "bankName": "Bank of Marshmallows", "bankPrimaryLine": "3288 Tara Lane", "bankSecondaryLine": "Indianapolis, IN", "description": "This is where to put your marshmallows", "routingNumber": "123456789", "signatureText": "Stay Puff", "createdAt": "2021-07-18T16:19:35.626Z", "updatedAt": "2021-07-18T16:19:35.626Z" } } ``` -------------------------------- ### Creating a Postcard with PDF from Node Buffer (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet illustrates how to create a postcard by providing the PDF content directly from a Node.js `Buffer` object, typically loaded from a local file. It requires importing the `fs` module to read the file into a buffer, which is then passed as the `pdf` parameter along with existing contact IDs. ```typescript import fs from 'fs' const doc = fs.readFileSync('/my/local/file.pdf') const postcard = await client.postcard.create({ description: 'Cool new postcard', pdf: doc, to: 'contact_f8NLBJXjV82HnM8emVow3r', from: 'contact_fo3HwdeFZ3wwNuHFAgszHt' }) ``` -------------------------------- ### Creating a Letter with Full Address Details using PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to create a new letter by providing complete 'to' and 'from' address details directly within the create call. It includes parameters for a description and a PDF URL, initiating the letter's journey to the recipient. ```typescript const letter = await client.letter.create({ description: 'Cool new letter', pdf: 'https://www.icnaam.org/documents/8x11singlesample.pdf', to: { firstName: 'Steve', lastName: 'Smith', companyName: 'Acme Rentals', addressLine1: '5454 West 34th Street', city: 'Indianapolis', provinceOrState: 'IN', postalOrZip: '46224', countryCode: 'US' }, from: { firstName: 'John', lastName: 'Quincy', companyName: 'US Steel', addressLine1: '123 Main Street', city: 'Atlanta', provinceOrState: 'GA', postalOrZip: '12345', countryCode: 'US' } }) ``` -------------------------------- ### Progressing a Test Postcard with PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This function allows moving a 'Test Postcard' through its server-side processing steps one at a time, primarily for verifying webhook calls. It is exclusively available for test postcards and requires the postcard's `id` as a parameter. The response format is similar to `client.postcard.get(id)`. ```typescript const move = await client.postcard.progress(id) ``` -------------------------------- ### Verify Address with Structured Object (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md Illustrates verifying an address using a structured object input, providing explicit components like line1, city, and postal code. This approach offers precise control over address data for verification. ```typescript const address = await client.address.verify({ line1: '3288 Tara Ln', city: 'Indianapolis', postalOrZip: '46224', provinceOrState: 'IN', }) ``` -------------------------------- ### Creating a Contact using PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to create a new contact record using the PostGrid Node.js client. It requires an object with contact details such as address, name, email, and phone number. If a contact with identical details already exists, the API returns the existing contact instead of creating a new one. ```typescript const contact = await client.contact.create({ addressLine1: '2929 Eagledale Dr', provinceOrState: 'IN', postalOrZip: '46224', countryCode: 'US', firstName: 'Jim', lastName: 'Harrison', email: 'jim@jimmys.com', phoneNumber: '317-555-1212', companyName: 'Jimmys Bar', jobTitle: 'Barkeep', }) ``` -------------------------------- ### Suggesting Addresses with PostGrid (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This function helps find addresses that are similar or 'close' to a provided estimated address. It takes a structured address object as input and returns potential matches. ```typescript const info = await client.address.suggestAddresses({ line1: '77 MAIN ST', city: 'ABERDEEN', provinceOrState: 'SD' }) ``` -------------------------------- ### Listing Postcards with PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to retrieve a list of all postcards associated with the API key using the PostGrid Node.js client. It supports optional `limit` and `skip` parameters for pagination, which default to `40` and `0` respectively if omitted. The response includes a `postcards` object containing a `data` array of postcard details. ```typescript const doc = await client.postcard.list() ``` ```javascript { "success": true, "postcards": { "object": "list", "limit": 40, "skip": 0, "totalCount": 3, "data": [ { "id": "postcard_agV7LbeDfRbdNUdnfePAyD", "object": "postcard", "live": false, "backHtml": "Hello again, {{to.firstName}}", "description": "Cool new postcard", "from": { "id": "contact_fo3HwdeFZ3wwNuHFAgszHt", "object": "contact", "addressLine1": "123 MAIN STREET", "addressLine2": null, "addressStatus": "verified", "city": "ATLANTA", "companyName": "US Steel", "country": "UNITED STATES", "countryCode": "US", "firstName": "John", "lastName": "Quincy", "postalOrZip": "12345", "provinceOrState": "GA" }, "frontHtml": "Hello, {{to.firstName}}", "sendDate": "2021-07-16T14:14:37.023Z", "size": "6x4", "status": "ready", "to": { "id": "contact_f8NLBJXjV82HnM8emVow3r", "object": "contact", "addressLine1": "5454 WEST 34TH STREET", "addressLine2": null, "addressStatus": "verified", "city": "INDIANAPOLIS", "companyName": "Acme Rentals", "country": "UNITED STATES", "countryCode": "US", "firstName": "Steve", "lastName": "Smith", "postalOrZip": "46224", "provinceOrState": "IN" }, "createdAt": "2021-07-16T14:14:37.027Z", "updatedAt": "2021-07-16T14:14:37.027Z" }, { "id": "postcard_48Fm3w14DGjRKKpsD2GrXJ", "object": "postcard", "live": false, "backHtml": "Hello again, {{to.firstName}}", "description": "Cool new postcard", "from": { "id": "contact_fo3HwdeFZ3wwNuHFAgszHt", "object": "contact", "addressLine1": "123 MAIN STREET", "addressLine2": null, "addressStatus": "verified", "city": "ATLANTA", "companyName": "US Steel", "country": "UNITED STATES", "countryCode": "US", "firstName": "John", "lastName": "Quincy", "postalOrZip": "12345", "provinceOrState": "GA" }, "frontHtml": "Hello, {{to.firstName}}", "pageCount": 2, "sendDate": "2021-07-16T14:09:38.286Z", "size": "6x4", "status": "cancelled", "to": { "id": "contact_f8NLBJXjV82HnM8emVow3r", "object": "contact", "addressLine1": "5454 WEST 34TH STREET", "addressLine2": null, "addressStatus": "verified", "city": "INDIANAPOLIS", "companyName": "Acme Rentals", "country": "UNITED STATES", "countryCode": "US", "firstName": "Steve", "lastName": "Smith", "postalOrZip": "46224", "provinceOrState": "IN" }, "url": "https://pg-prod-bucket-1.s3.amazonaws.com/test/...", "createdAt": "2021-07-16T14:09:38.290Z", "updatedAt": "2021-07-16T14:09:42.691Z" }, ... ] } } ``` -------------------------------- ### Listing All Contacts using PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to retrieve a list of all contacts associated with the API Key. It supports optional "limit" and "skip" parameters for pagination, defaulting to "skip=0" and "limit=40" if omitted. The response includes a list object with pagination metadata and an array of contact data. ```typescript const doc = await client.contacts.list() ``` -------------------------------- ### Listing Letters with PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to retrieve a list of all letters associated with the API key using the PostGrid Node.js client. It supports pagination via optional `limit` and `skip` parameters, which default to `40` and `0` respectively. The response includes a list of letter objects with detailed properties. ```typescript const doc = await client.letter.list() ``` ```json { "success": true, "letters": { "object": "list", "limit": 40, "skip": 0, "totalCount": 27, "data": [ { "id": "letter_3j3st1ZzZmFPv9bn1BnMeE", "object": "letter", "live": false, "addressPlacement": "insert_blank_page", "color": false, "description": "Cool new letter", "doubleSided": false, "from": { "id": "contact_fo3HwdeFZ3wwNuHFAgszHt", "object": "contact", "addressLine1": "123 MAIN STREET", "addressLine2": null, "addressStatus": "verified", "city": "ATLANTA", "companyName": "US Steel", "country": "UNITED STATES", "countryCode": "US", "firstName": "John", "lastName": "Quincy", "postalOrZip": "12345", "provinceOrState": "GA" }, "sendDate": "2021-07-15T20:02:55.417Z", "status": "ready", "to": { "id": "contact_f8NLBJXjV82HnM8emVow3r", "object": "contact", "addressLine1": "5454 WEST 34TH STREET", "addressLine2": null, "addressStatus": "verified", "city": "INDIANAPOLIS", "companyName": "Acme Rentals", "country": "UNITED STATES", "countryCode": "US", "firstName": "Steve", "lastName": "Smith", "postalOrZip": "46224", "provinceOrState": "IN" }, "uploadedPdf": "https://pg-prod-bucket-1.s3.amazonaws.com/test/...", "createdAt": "2021-07-15T20:02:55.421Z", "updatedAt": "2021-07-15T20:02:55.421Z" }, ... ] } } ``` -------------------------------- ### Batch Verifying Addresses with PostGrid (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This function allows batch verification of multiple addresses, accepting both freeform strings and structured objects. It parses, verifies, and tags each address individually, returning detailed status for each entry. ```typescript const info = await client.address.batchVerify([ '3288 Tara Ln, Indianapolis, IN 46224', '3000 Tara Ln, Indianapolis, IN 46224', { line1: '77 S MAIN ST', city: 'ABERDEEN', provinceOrState: 'SD', postalOrZip: '57401' } ]) ``` -------------------------------- ### Successful Bank Account List Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet illustrates a successful response when listing bank accounts. It includes the "success" flag, an "accounts" object with pagination details ("object", "limit", "skip", "totalCount"), and a "data" array containing individual bank account objects, each with their respective details. ```javascript { "success": true, "accounts": { "object": "list", "limit": 40, "skip": 0, "totalCount": 1, "data": [ { "id": "bank_a2M4zstWGeYeJ8gbtVKKr5", "object": "bank_account", "live": false, "accountNumberLast4": "1001", "bankCountryCode": "US", "bankName": "Bank of Marshmallows", "bankPrimaryLine": "3288 Tara Lane", "bankSecondaryLine": "Indianapolis, IN", "description": "This is where to put your marshmallows", "routingNumber": "123456789", "signatureText": "Stay Puff", "createdAt": "2021-07-18T16:22:44.579Z", "updatedAt": "2021-07-18T16:22:44.579Z" } ] } } ``` -------------------------------- ### Listing Checks with PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet shows how to retrieve a list of all checks associated with the API Key using the PostGrid Node.js client. It supports optional `limit` and `skip` parameters for pagination, defaulting to `0` for `skip` and `40` for `limit` if omitted. The function returns a paginated list of check objects. ```typescript const checks = await client.check.list() ``` -------------------------------- ### Creating a Postcard using Existing Contact IDs (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates an alternative method for creating a postcard by referencing existing 'to' and 'from' contacts using their unique IDs. This is useful when contact information has already been created or is known, streamlining the postcard creation process by avoiding redundant data submission. ```typescript const postcard = await client.postcard.create({ description: 'Cool new postcard', pdf: 'https://my.artwork.com/postcards/6x4sample.pdf', to: 'contact_f8NLBJXjV82HnM8emVow3r', from: 'contact_fo3HwdeFZ3wwNuHFAgszHt' }) ``` -------------------------------- ### Verify Address with Freeform String (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md Demonstrates verifying an address using a freeform string input with the PostGrid Node.js client. This method parses and validates the address, returning a detailed verification status. ```typescript const address = await client.address.verify('3288 Tara Ln, Indianapolis, IN') ``` -------------------------------- ### Autocomplete an Address Call (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md Demonstrates using the "autocompleteAddress" function to obtain a complete address from partial information, typically sourced from autocomplete previews. This call fills in missing details like postal code and country. ```typescript const info = await client.address.autocompleteAddress({ line1: '77 S MAIN ST', city: 'ABERDEEN', provinceOrState: 'SD', }) ``` -------------------------------- ### Successful Letter Creation Response from PostGrid API (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet illustrates the JSON structure returned by the PostGrid API upon a successful letter creation. It includes details such as the letter's unique ID, object type, live status, and comprehensive information about the 'from' and 'to' contacts. ```javascript { "success": true, "letter": { "id": "letter_hBy6M5DMKEqp7z1paW1TDM", "object": "letter", "live": false, "addressPlacement": "insert_blank_page", "color": false, "description": "Cool new letter", "doubleSided": false, "from": { "id": "contact_fo3HwdeFZ3wwNuHFAgszHt", "object": "contact", "addressLine1": "123 MAIN STREET", "addressLine2": null, "addressStatus": "verified", "city": "ATLANTA", "companyName": "US Steel", "country": "UNITED STATES", "countryCode": "US", "firstName": "John", "lastName": "Quincy", "postalOrZip": "12345", "provinceOrState": "GA" }, "sendDate": "2021-07-15T19:51:50.356Z", "status": "ready", "to": { "id": "contact_f8NLBJXjV82HnM8emVow3r", "object": "contact", "addressLine1": "5454 WEST 34TH STREET", "addressLine2": null, "addressStatus": "verified", "city": "INDIANAPOLIS", "companyName": "Acme Rentals", "country": "UNITED STATES", "countryCode": "US", "firstName": "Steve", "lastName": "Smith", "postalOrZip": "46224", "provinceOrState": "IN" }, "uploadedPdf": "https://pg-prod-bucket-1.s3.amazonaws.com/test/...", "createdAt": "2021-07-15T19:51:50.360Z", "updatedAt": "2021-07-15T19:51:50.360Z" } } ``` -------------------------------- ### Retrieving a Bank Account by ID using PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to retrieve a specific bank account using its unique `id` with the PostGrid Node.js client. The `client.bankAccount.get` method takes the bank account ID as a parameter and returns the account details, similar to the successful creation response. ```typescript const account = await client.bankAccount.get(id) ``` -------------------------------- ### Successful PostGrid City/State Lookup Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JavaScript object illustrates the structure of a successful response from the PostGrid API when looking up city and state information. It indicates 'success: true' and provides the city and province/state within the 'data' object. ```javascript { "success": true, "address": { "status": "success", "message": "Success.", "data": { "city": "NAPERVILLE", "provinceOrState": "IL" } } } ``` -------------------------------- ### Successful Postcard Creation Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON object illustrates the structure of a successful response after creating a postcard. It includes a `success` flag, the `postcard` object with its unique ID, status, and detailed information about the 'to' and 'from' contacts, including their verified address status and other metadata. ```javascript { "success": true, "postcard": { "id": "postcard_48Fm3w14DGjRKKpsD2GrXJ", "object": "postcard", "live": false, "backHtml": "Hello again, {{to.firstName}}", "description": "Cool new postcard", "from": { "id": "contact_fo3HwdeFZ3wwNuHFAgszHt", "object": "contact", "addressLine1": "123 MAIN STREET", "addressLine2": null, "addressStatus": "verified", "city": "ATLANTA", "companyName": "US Steel", "country": "UNITED STATES", "countryCode": "US", "firstName": "John", "lastName": "Quincy", "postalOrZip": "12345", "provinceOrState": "GA" }, "frontHtml": "Hello, {{to.firstName}}", "sendDate": "2021-07-16T14:09:38.286Z", "size": "6x4", "status": "ready", "to": { "id": "contact_f8NLBJXjV82HnM8emVow3r", "object": "contact", "addressLine1": "5454 WEST 34TH STREET", "addressLine2": null, "addressStatus": "verified", "city": "INDIANAPOLIS", "companyName": "Acme Rentals", "country": "UNITED STATES", "countryCode": "US", "firstName": "Steve", "lastName": "Smith", "postalOrZip": "46224", "provinceOrState": "IN" }, "createdAt": "2021-07-16T14:09:38.290Z", "updatedAt": "2021-07-16T14:09:38.290Z" } } ``` -------------------------------- ### Progressing a Test Check with PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to advance a test check through its server-side processing steps, primarily for verifying webhook calls. This functionality is exclusively available for test checks. The `id` parameter is the unique identifier of the test check, and the response is similar to that of `client.check.get(id)`. ```typescript const move = await client.check.progress(id) ``` -------------------------------- ### Successful Address Verification Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md Represents a successful response from the PostGrid address verification API. It includes "success: true", "verified: true", and a detailed "address" object with verified components and status. ```javascript { "success": true, "verified": true, "address": { "status": 'success', "message": 'Address verification processed.', "data": { "line1": '3288 Tara Ln', "city": 'Indianapolis', "provinceOrState": 'IN', "postalOrZip": '46224', "zipPlus4": '2231', "country": 'us', "countryName": 'UNITED STATES', "errors": {}, "status": 'verified' } } } ``` -------------------------------- ### Looking Up City/State from Postal Code using PostGrid Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This TypeScript snippet demonstrates how to use the PostGrid client's address service to look up the city and state associated with a given postal code. It takes a postal code string as input and returns an object containing the address information. ```typescript const info = await client.address.lookupCityState('60540') ``` -------------------------------- ### Successful Autocomplete Address Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md Represents a successful response from the PostGrid "autocompleteAddress" API. It includes a "success" flag and a "previews" object containing a "data" array with the fully completed address details, including "postalOrZip" and "country". ```javascript { "success": true, "previews": { "status": 'success', "message": 'Retrieved verified address completions successfully.', "data": [ { line1: '77 S MAIN ST', city: 'ABERDEEN', provinceOrState: 'SD', postalOrZip: '57401', country: 'US' } ] } } ``` -------------------------------- ### Successful Contact Creation Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet illustrates the expected successful response structure after creating a contact. It includes the unique contact ID, object type, live status, and all provided contact details, along with creation and update timestamps. The "success" field indicates the operation's outcome. ```javascript { "success": true, "contact": { "id": "contact_igdxsBys7TPJYf47PevBJj", "object": "contact", "live": false, "addressLine1": "2929 EAGLEDALE DR", "addressLine2": null, "addressStatus": "verified", "city": null, "companyName": "Jimmys Bar", "country": "UNITED STATES", "countryCode": "US", "email": "jim@jimmys.com", "firstName": "Jim", "jobTitle": "Barkeep", "lastName": "Harrison", "phoneNumber": "317-555-1212", "postalOrZip": "46224", "provinceOrState": "IN", "createdAt": "2021-07-15T18:36:45.348Z", "updatedAt": "2021-07-15T18:36:45.348Z" } } ``` -------------------------------- ### Creating a Check with Full Address Details in TypeScript Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to create a check using the PostGrid Node.js client by providing complete address details for both the 'to' and 'from' contacts. It includes a 'letterHTML' field for an accompanying letter and references a 'bankAccount' ID. The 'amount', 'memo', and 'number' fields specify the check's value and details. ```typescript const check = await client.check.create({ description: 'Cool new check', letterHTML: 'Hello {{to.firstName}}', to: { firstName: 'Steve', lastName: 'Smith', companyName: 'Acme Rentals', addressLine1: '5454 West 34th Street', city: 'Indianapolis', provinceOrState: 'IN', postalOrZip: '46224', countryCode: 'US', }, from: { firstName: 'John', lastName: 'Quincy', companyName: 'US Steel', addressLine1: '123 Main Street', city: 'Atlanta', provinceOrState: 'GA', postalOrZip: '12345', countryCode: 'US', }, bankAccount: 'bank_gMpKxPyiGzt1ZwACTmLHHn', amount: 10000, memo: 'Invoice 1233', number: 9667, }) ``` -------------------------------- ### Creating a Postcard with an Idempotency Key (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet shows how to include an optional idempotency key when creating a postcard. The idempotency key, provided as a second parameter to the `create()` function, ensures that duplicate postcards are not created within a 24-hour window if the same key is used for subsequent calls, preventing unintended multiple submissions. ```typescript const postcard = await client.postcard.create({ description: 'Cool new postcard', pdf: 'https://my.artwork.com/postcards/6x4sample.pdf', to: 'contact_f8NLBJXjV82HnM8emVow3r', from: 'contact_fo3HwdeFZ3wwNuHFAgszHt' }, { idempotencyKey: '9d972254-34eb-492e-90c2-739087a8487d' }) ``` -------------------------------- ### Progressing a Test Letter with PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This function advances a Test Letter through its server-side processing stages, enabling verification of webhook calls. This functionality is exclusively available for Test Letters. The `id` parameter is the unique identifier for the letter, and the response structure mirrors that of retrieving a letter by ID. ```typescript const move = await client.letter.progress(id) ``` -------------------------------- ### Successful Contact List Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet illustrates the expected successful response structure when listing contacts. It provides pagination details like "limit", "skip", and "totalCount", along with a "data" array containing multiple contact objects. Each contact object includes its ID, type, and detailed information. ```javascript { "success": true, "contacts": { "object": "list", "limit": 40, "skip": 0, "totalCount": 12, "data": [ { "id": "contact_2rWLmfNFPKQLtZEy72qT8e", "object": "contact", "live": false, "addressLine1": "2929 EAGLEDALE DR", "addressLine2": null, "addressStatus": "verified", "city": null, "companyName": "Jimmys Bar", "country": "UNITED STATES", "countryCode": "US", "email": "jim@jimmys.com", "firstName": "Jim", "jobTitle": "Barkeep", "lastName": "Harrison", "phoneNumber": "317-555-1212", "postalOrZip": "46224", "provinceOrState": "IN", "createdAt": "2021-07-15T18:54:44.521Z", "updatedAt": "2021-07-15T18:54:44.521Z" }, ... ] } } ``` -------------------------------- ### Error Response for PostGrid API Calls (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON snippet demonstrates the structure of an error response from the PostGrid API. It includes a "success" field set to "false" and an "error" object containing the "type" and a descriptive "message" about the issue encountered during the API call. ```javascript { "success": false, "error": { "type": "PostGrid_type", "message": "(Error message from PostGrid...)" } } ``` -------------------------------- ### Successful Address Suggestion Response (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This JSON object represents a successful response from the address suggestion API. It contains an array of suggested address objects, each with parsed components and verification status. ```javascript { "success": true, "addresses": { "status": "success", "message": "Address suggestions retrieved successfully.", "data": [ { "city": "Aberdeen", "country": "us", "countryName": "UNITED STATES", "errors": {}, "line1": "77 N Main St", "postalOrZip": "57401", "provinceOrState": "SD", "status": "verified", "zipPlus4": "3428" }, { "city": "Aberdeen", "country": "us", "countryName": "UNITED STATES", "errors": {}, "line1": "77 S Main St", "postalOrZip": "57401", "provinceOrState": "SD", "status": "verified", "zipPlus4": "4218" } ] } } ``` -------------------------------- ### Creating a Letter with an Idempotency Key using PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to include an optional idempotency key when creating a letter. This key ensures that PostGrid will not create a duplicate letter if the same 'create()' call with the same key is made within a 24-hour period, preventing unintended repetitions. ```typescript const letter = await client.letter.create({ description: 'Cool new letter', pdf: 'https://www.icnaam.org/documents/8x11singlesample.pdf', to: 'contact_f8NLBJXjV82HnM8emVow3r', from: 'contact_fo3HwdeFZ3wwNuHFAgszHt' }, { idempotencyKey: '9d972254-34eb-492e-90c2-739087a8487d' }) ``` -------------------------------- ### Error Response from PostGrid API during Letter Creation (JavaScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet shows the JSON format of an error response from the PostGrid API. It indicates that the letter creation was unsuccessful and provides details about the error type and a descriptive message. ```javascript { "success": false, "error": { "type": "PostGrid_type", "message": "(Error message from PostGrid...)" } } ``` -------------------------------- ### Retrieving a Webhook in PostGrid Node.js Client (TypeScript) Source: https://github.com/flexbase-eng/postgrid-node-client/blob/main/README.md This snippet demonstrates how to retrieve a specific webhook by its ID using the PostGrid Node.js client. The `id` parameter is the unique identifier for the webhook, and the function returns a webhook object similar to the one created by `client.webhook.create()`. ```typescript const doc = await client.webhook.get(id) ```