{"library":"postgrid-node-client","title":"PostGrid Node.js Client","description":"The `postgrid-node-client` library provides a Node.js and TypeScript client for interacting with the PostGrid Business API, facilitating postal delivery services (Print-Mail) and address verification/autocomplete. Currently at version 0.11.0, this package offers a convenient, typed interface over PostGrid's dual REST API structure. A key differentiator is its robust handling of two distinct API keys required by PostGrid: one for Print-Mail and another for Address Verification, allowing developers to instantiate a single client that intelligently routes requests. While a specific release cadence isn't published, its pre-1.0 versioning implies active development. The client simplifies common tasks such as creating contacts, sending documents, and verifying addresses, abstracting away direct HTTP requests and JSON parsing, and supports webhook configuration for event notifications.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install postgrid-node-client"],"cli":null},"imports":["import { PostGrid } from 'postgrid-node-client';","import { PostGrid } from 'postgrid-node-client';","import { PostGrid } from 'postgrid-node-client';\nconst client = new PostGrid({ mail: 'key1', addr: 'key2' }, { webhookUrl: 'url', webhookSecret: 'secret' });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { PostGrid } from 'postgrid-node-client';\n\n// For demonstration, use environment variables for API keys.\n// In a real application, consider a secure configuration manager.\nconst mailApiKey = process.env.POSTGRID_MAIL_API_KEY ?? 'YOUR_MAIL_API_KEY';\nconst addrApiKey = process.env.POSTGRID_ADDR_API_KEY ?? 'YOUR_ADDR_API_KEY';\n\n// Instantiate the client with both Mail and Address Verification API keys.\n// It's not necessary to supply both if you only use one service.\nconst client = new PostGrid({\n  mail: mailApiKey,\n  addr: addrApiKey\n}, {\n  // Optional: Configure webhook details if your application processes PostGrid webhooks\n  webhookUrl: 'https://my.service.com/postgrid/callback',\n  webhookSecret: 'abc123456the-tall-brown-bear',\n  webhookEvents: ['letter.created', 'letter.updated']\n});\n\nasync function runExample() {\n  try {\n    console.log('Attempting to create a contact...');\n    const newContact = await client.contacts.create({\n      first_name: 'John',\n      last_name: 'Doe',\n      address: {\n        address_line1: '123 Main St',\n        city: 'Anytown',\n        state: 'CA',\n        zip: '90210',\n        country: 'US'\n      },\n      email: 'john.doe@example.com',\n      phone_number: '+15551234567'\n    });\n    console.log('Contact created successfully:', newContact.id);\n\n    // Example of Address Verification (requires addr API key)\n    console.log('\\nAttempting Address Verification...');\n    const verifiedAddress = await client.addresses.verify({\n      address_line1: '123 Main St',\n      city: 'Anytown',\n      state: 'CA',\n      zip: '90210',\n      country: 'US'\n    });\n    console.log('Address Verification result:', verifiedAddress.success ? 'Verified' : 'Failed');\n\n  } catch (error: any) {\n    console.error('Error interacting with PostGrid:', error.message);\n    if (error.response?.data) {\n      console.error('API Response Data:', error.response.data);\n    }\n  }\n}\n\nrunExample();","lang":"typescript","description":"This quickstart demonstrates how to instantiate the PostGrid client with both Mail and Address Verification API keys (retrieved from environment variables) and then perform basic operations: creating a contact and verifying an address. It also shows optional webhook configuration.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}