### Quick Start Example Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/README.md This snippet demonstrates how to initialize the DNSimple client with an access token and perform basic operations like fetching identity information and listing domains. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.DNSIMPLE_TOKEN, }); const { data: whoami } = await client.identity.whoami(); const { data: domains } = await client.domains.listDomains(whoami.account.id); ``` -------------------------------- ### Complete Domain Setup Workflow Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/INDEX.md This example demonstrates a full workflow for setting up a domain, including creating the domain, adding DNS records, enabling DNSSEC, and checking rate limits. It also includes error handling for common client and not found errors. Ensure your DNSIMPLE_TOKEN environment variable is set. ```typescript import { DNSimple, NotFoundError, ClientError, } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.DNSIMPLE_TOKEN, }); async function setupDomain(domainName: string, ipAddress: string) { try { // 1. Get account ID const { data: user } = await client.identity.whoami(); const accountId = user.account.id; console.log(`Using account: ${accountId}`); // 2. Create domain const { data: domain } = await client.domains.createDomain(accountId, { name: domainName, }); console.log(`Domain created: ${domain.name}`); // 3. Add DNS record const { data: record } = await client.zones.createZoneRecord( accountId, domainName, { name: "www", type: "A", content: ipAddress, ttl: 3600, } ); console.log(`Record created: ${record.name} → ${record.content}`); // 4. Enable DNSSEC const { data: dnssec } = await client.domains.enableDnssec( accountId, domainName ); console.log(`DNSSEC enabled: ${dnssec.enabled}`); // 5. Check rate limits const allDomains = await client.domains.listDomains(accountId); console.log(`Rate limit remaining: ${allDomains.rateLimit.remaining}`); return { domain, record, dnssec }; } catch (error) { if (error instanceof ClientError) { console.error("Validation error:", error.attributeErrors()); } else if (error instanceof NotFoundError) { console.error("Resource not found"); } else { throw error; } } } await setupDomain("example.com", "192.0.2.1"); ``` -------------------------------- ### Execute Example Script Source: https://github.com/dnsimple/dnsimple-node/blob/main/README.md Command to run the example JavaScript file, ensuring the access token is passed as an environment variable. ```shell TOKEN=[TOKEN VALUE GOES HERE] node test.js ``` -------------------------------- ### Basic DNSimple Client Setup and Operations Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/INDEX.md Initialize the DNSimple client with an access token and perform basic operations like getting user identity, listing domains, and creating a new domain. Ensure your DNSIMPLE_TOKEN environment variable is set. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.DNSIMPLE_TOKEN, }); // Get current user and account const response = await client.identity.whoami(); const accountId = response.data.account.id; // List domains const { data: domains } = await client.domains.listDomains(accountId); // Create a domain const { data: newDomain } = await client.domains.createDomain(accountId, { name: "example.com", }); ``` -------------------------------- ### Install Dependencies Source: https://github.com/dnsimple/dnsimple-node/blob/main/CONTRIBUTING.md Install the necessary project dependencies using npm. This should be done after cloning the repository. ```shell npm install ``` -------------------------------- ### Install DNSimple Node.js Client Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/INDEX.md Install the dnsimple package using npm. This command is used to add the library to your Node.js project. ```bash npm install dnsimple ``` -------------------------------- ### Get Single Domain Response Example Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Demonstrates accessing the 'data' and 'rateLimit' properties from a response when fetching a single domain. ```typescript const response = await client.domains.getDomain(1010, "example.com"); response.data // { id: 123, name: "example.com", ... } response.rateLimit // { limit: 2400, remaining: 2399, reset: 1234567890 } ``` -------------------------------- ### Get Domain Pricing Information Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/registrar.md Retrieves pricing details for a domain, including registration, renewal, and transfer costs. This example demonstrates accessing the `getDomainPrices` method and logging various pricing components, including trustee pricing if available. ```typescript const { data: prices } = await client.registrar.getDomainPrices(1010, "example.com"); console.log(`Domain: ${prices.domain}`); console.log(`Premium: ${prices.premium}`); console.log(`Registration: $${prices.registration_price}`); console.log(`Renewal: $${prices.renewal_price}`); console.log(`Transfer: $${prices.transfer_price}`); if (prices.trustee_price) { console.log(`Trustee: $${prices.trustee_price}`); } ``` -------------------------------- ### OAuth Token Setup in TypeScript Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/README.md Illustrates setting up the DNSimple client with an OAuth token. This is essential for authenticating API requests. ```typescript import { DnsimpleClient } from "dnsimple"; const client = new DnsimpleClient(process.env.DNSIMPLE_API_TOKEN); // Use the client for API requests... ``` -------------------------------- ### getPrimaryServer Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/other-modules.md Gets a primary server. ```APIDOC ## GET /{account}/secondary_dns/primaries/{primary} ### Description Gets a primary server. ### Method GET ### Endpoint `/{account}/secondary_dns/primaries/{primary}` ### Parameters #### Path Parameters - **account** (number) - Required - The account ID. - **primary** (number) - Required - The ID of the primary server to retrieve. #### Query Parameters - **params** (QueryParams) - Optional - Additional query parameters. ``` -------------------------------- ### Sandbox Environment DNSimple Client Setup Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Sets up the client to communicate with the DNSimple sandbox environment. Use a separate access token for the sandbox. ```typescript const sandboxClient = new DNSimple({ baseUrl: "https://api.sandbox.dnsimple.com", accessToken: process.env.DNSIMPLE_SANDBOX_TOKEN, }); // All requests use sandbox API // Note: Sandbox and production accounts are separate ``` -------------------------------- ### Basic Production DNSimple Client Setup Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Configures the client for the default production API endpoint. Ensure your DNSIMPLE_TOKEN environment variable is set for authentication. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.DNSIMPLE_TOKEN, }); // All requests use default production API const { data: whoami } = await client.identity.whoami(); ``` -------------------------------- ### Initialize DNSimple Client and Perform Registrar Operations Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/registrar.md Demonstrates initializing the DNSimple client and performing common registrar operations like checking domain availability, getting pricing, and registering a domain. Ensure your DNSimple API token is set as an environment variable. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.TOKEN }); // Check domain availability const { data: check } = await client.registrar.checkDomain(1010, "example.com"); // Get domain pricing const { data: prices } = await client.registrar.getDomainPrices(1010, "example.com"); // Register a domain const { data: registration } = await client.registrar.registerDomain(1010, "newdomain.com", { registrant_id: 5678, whois_privacy: true, }); ``` -------------------------------- ### Multiple Environment DNSimple Client Setup Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md A factory function to create DNSimple clients for different environments (production or sandbox) with specific configurations. ```typescript function createClient(env: "production" | "sandbox") { if (env === "sandbox") { return new DNSimple({ baseUrl: "https://api.sandbox.dnsimple.com", accessToken: process.env.DNSIMPLE_SANDBOX_TOKEN, userAgent: "myapp-test", }); } return new DNSimple({ accessToken: process.env.DNSIMPLE_TOKEN, userAgent: "myapp", }); } const prodClient = createClient("production"); const testClient = createClient("sandbox"); ``` -------------------------------- ### Initialize DNSimple Client and Basic Domain Operations Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/domains.md Demonstrates how to initialize the DNSimple client and perform common domain operations like listing, creating, and getting domain details. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.TOKEN }); // List all domains in an account const { data: domains } = await client.domains.listDomains(1010); // Create a new domain const { data: newDomain } = await client.domains.createDomain(1010, { name: "example.com", }); // Get domain details const { data: domain } = await client.domains.getDomain(1010, "example.com"); ``` -------------------------------- ### List Domains Response Example with Pagination Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Illustrates the structure of a response from a list endpoint, including 'data', 'pagination', and 'rateLimit' properties. ```typescript const response = await client.domains.listDomains(1010); response.data // Array response.pagination // { current_page: 1, per_page: 30, total_entries: 150, total_pages: 5 } response.rateLimit // Rate limit information ``` -------------------------------- ### Create Webhook Example Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/other-modules.md Use this snippet to register a new webhook endpoint in your account. Ensure you provide a valid URL for the webhook to receive events. ```typescript const { data: webhook } = await client.webhooks.createWebhook(1010, { url: "https://myapp.com/webhooks/dnsimple", }); console.log(`Webhook created: ${webhook.id}`); ``` -------------------------------- ### Error Handling Example in TypeScript Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/README.md Demonstrates how to catch and handle specific DNSimple API errors. Ensure the client is configured. ```typescript import { DnsimpleClient, RequestError } from "dnsimple"; const client = new DnsimpleClient(process.env.DNSIMPLE_API_TOKEN); async function main() { try { await client.zones.findZone(1, "example.com"); } catch (e) { if (e instanceof RequestError) { console.error(`Request failed with status ${e.statusCode} and message: ${e.message}`); } else { throw e; } } } main(); ``` -------------------------------- ### Iterate All Certificates using DNSimple Client Source: https://github.com/dnsimple/dnsimple-node/blob/main/README.md Example of using the `iterateAll` submethod to asynchronously iterate through all certificates for a given account ID and domain. This fetches pages as needed. ```typescript // iterateAll for await (const certificate of client.certificates.listCertificates.iterateAll(1010, "bingo.pizza")) { console.log(certificate); } ``` -------------------------------- ### Iterate and Collect All Certificates Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/certificates.md Provides examples for iterating through all certificates for a domain using pagination helpers. Use `iterateAll` for sequential processing or `collectAll` to gather all results into an array. ```typescript // Iterate for await (const cert of client.certificates.listCertificates.iterateAll(1010, "example.com")) { console.log(cert.common_name); } // Collect all const allCerts = await client.certificates.listCertificates.collectAll(1010, "example.com", { sort: "expiration:asc", }); ``` -------------------------------- ### List Zones with Filtering and Sorting Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/zones.md Demonstrates how to list zones with specific filters, such as filtering by name substring and sorting the results. This example shows practical usage for retrieving targeted zone information. ```typescript const { data: zones } = await client.zones.listZones(1010, { name_like: "example", sort: "name:asc", }); zones.forEach((zone) => { console.log(`Zone: ${zone.name} (Active: ${zone.active})`); }); ``` -------------------------------- ### Monitor API Rate Limits Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/INDEX.md This example shows how to check the remaining API rate limit after making a request. It's crucial for understanding your usage and avoiding rate limiting errors. ```typescript const response = await client.domains.listDomains(accountId); console.log(`Remaining requests: ${response.rateLimit.remaining}`); if (response.rateLimit.remaining < 100) { console.warn("Approaching rate limit"); } ``` -------------------------------- ### List Domains with Sorting and Pagination Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/domains.md An example of listing domains with specific sorting criteria (expiration date ascending) and accessing pagination information. ```typescript const { data: domains, pagination } = await client.domains.listDomains(1010, { sort: "expiration:asc", }); console.log(`Showing ${domains.length} of ${pagination.total_entries} domains`); domains.forEach((domain) => { console.log(`${domain.name} - expires: ${domain.expires_at}`); }); ``` -------------------------------- ### List Domains with Filtering and Sorting Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/api-reference.md Example of how to list domains using the DNSimple Node.js client, applying filters like 'name_like' and sorting criteria. Requires a client instance and domain ID. ```typescript // List domains with filtering and sorting const { data: domains } = await client.domains.listDomains(1010, { name_like: "example", sort: "name:asc", page: 2, per_page: 50, }); ``` -------------------------------- ### Create Email Forward Example Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/domains.md Use this snippet to create a new email forward for a domain. Ensure you provide the account ID, domain name, and the alias and destination email addresses. ```typescript const { data: forward } = await client.domains.createEmailForward(1010, "example.com", { alias_email: "info@example.com", destination_email: "contact@example.org", }); ``` -------------------------------- ### Initialize DNSimple Client and Fetch Account Details Source: https://github.com/dnsimple/dnsimple-node/blob/main/README.md Demonstrates how to initialize the DNSimple client with an access token and fetch the authenticated user's details. Ensure the ACCESS_TOKEN environment variable is set. ```javascript const { DNSimple } = require("dnsimple"); // Or use this if you're using TypeScript: // import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.TOKEN, }); // Fetch your details const response = await client.identity.whoami(); // All responses have a `data` property if there's response data. const accountId = response.data.account.id; ``` -------------------------------- ### Custom Fetcher Interface and Implementation Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Defines the structure for a custom fetcher and provides an example implementation. This allows for custom HTTP clients or middleware integration. ```typescript interface Fetcher { (request: { url: string; method: string; headers: Record; timeout: number; body?: string; }): Promise<{ status: number; body: string; rateLimit: RateLimitHeaders; }>; } const customFetcher: Fetcher = async (request) => { // Custom implementation return { status: 200, body: "{}", rateLimit: { limit: null, remaining: null, reset: null }, }; }; const client = new DNSimple({ accessToken: token, fetcher: customFetcher, }); ``` -------------------------------- ### DNSimple Client Initialization Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/api-reference.md Demonstrates how to import and instantiate the DNSimple client class with various configuration options, including access tokens, custom base URLs for sandbox environments, and custom user agents. ```APIDOC ## DNSimple Client Initialization ### Description Instantiate the main `DNSimple` client class to interact with the DNSimple API. You can configure authentication, API endpoints, and request behavior. ### Constructor ```typescript new DNSimple({ accessToken?: string; baseUrl?: string; fetcher?: Fetcher; timeout?: number; userAgent?: string; }) ``` ### Parameters #### Constructor Parameters - **accessToken** (string) - Optional - OAuth access token for API authentication. - **baseUrl** (string) - Optional - API endpoint base URL. Defaults to `https://api.dnsimple.com`. Use `https://api.sandbox.dnsimple.com` for sandbox. - **fetcher** (Fetcher) - Optional - HTTP fetcher implementation. Auto-detected at runtime. - **timeout** (number) - Optional - Request timeout in milliseconds. Defaults to `120000`. - **userAgent** (string) - Optional - Custom user agent prefix. The final agent will be `{userAgent} dnsimple-node/{version}`. ### Usage Examples **Production Environment:** ```javascript const { DNSimple } = require("dnsimple"); const client = new DNSimple({ accessToken: process.env.TOKEN, }); ``` **Sandbox Environment:** ```javascript const { DNSimple } = require("dnsimple"); const sandboxClient = new DNSimple({ baseUrl: "https://api.sandbox.dnsimple.com", accessToken: process.env.SANDBOX_TOKEN, }); ``` **Custom User Agent and Timeout:** ```javascript const { DNSimple } = require("dnsimple"); const customClient = new DNSimple({ accessToken: process.env.TOKEN, userAgent: "my-app/1.0", timeout: 30000, // 30 second timeout }); ``` ### Service Modules The `DNSimple` client instance provides access to the following service modules: - **accounts**: Account management operations. - **billing**: Billing and charge history. - **certificates**: SSL/TLS certificate management. - **contacts**: Registrant contact management. - **domains**: Domain hosting and management. - **identity**: Current authenticated user information. - **oauth**: OAuth token exchange. - **registrar**: Domain registration and transfer. - **services**: One-click service configuration. - **templates**: DNS record templates. - **tlds**: Top-level domain information. - **vanityNameServers**: Vanity name server management. - **webhooks**: Webhook endpoint registration. - **zones**: DNS zone management. ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/dnsimple/dnsimple-node/blob/main/CONTRIBUTING.md Clone the DNSimple Node.js repository and navigate into the project directory to begin development. ```shell git clone git@github.com:dnsimple/dnsimple-node.git cd dnsimple-node ``` -------------------------------- ### Processing Domains with TypeScript Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Example of how to process domains using the DNSimple client within a TypeScript function. The function returns a Promise resolving to an array of Domain objects. ```typescript async function processDomains(accountId: number): Promise { const { data } = await client.domains.listDomains(accountId); return data; // Type: Domain[] } ``` -------------------------------- ### Checking API Rate Limits Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Example of how to check remaining API requests and log a warning when approaching the rate limit. The reset time is converted to a readable date. ```typescript const response = await client.domains.listDomains(1010); if (response.rateLimit.remaining < 100) { console.warn("Approaching rate limit"); const resetTime = new Date(response.rateLimit.reset * 1000); console.warn(`Reset at: ${resetTime}`); } ``` -------------------------------- ### List and Create Domains with DNSimple Client Source: https://github.com/dnsimple/dnsimple-node/blob/main/README.md Shows how to list domains for a given account ID, including pagination, and how to create a new domain. Requires a valid account ID. ```javascript // List your domains const { data: domains1 } = await client.domains.listDomains(accountId); const { data: domains3 } = await client.domains.listDomains(accountId, { page: 3 }); // Create a domain const { data: createdDomain } = await client.domains.createDomain(accountId, { name: "example.com" }); // Get a domain const { data: domain } = await client.domains.getDomain(accountId, "example.com"); ``` -------------------------------- ### getTld Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/other-modules.md Gets details about a specific TLD. ```APIDOC ## GET /tlds/{tld} ### Description Gets details about a specific TLD. ### Method GET ### Endpoint /tlds/{tld} ### Parameters #### Path Parameters - **tld** (string) - Required - TLD string (e.g., "com", "co.uk") ### Request Example ```typescript const { data: tld } = await client.tlds.getTld("com"); console.log(`TLD: ${tld.tld}`); console.log(`Registration enabled: ${tld.registration_enabled}`); console.log(`Renewal enabled: ${tld.renewal_enabled}`); console.log(`Transfer enabled: ${tld.transfer_enabled}`); console.log(`WHOIS privacy: ${tld.whois_privacy}`); console.log(`Min registration: ${tld.minimum_registration} years`); ``` ### Response #### Success Response (200) - **data** (TLD) - A TLD object containing details about the specified TLD. ``` -------------------------------- ### getDnssec Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/domains.md Gets the DNSSEC status for a domain. ```APIDOC ## GET /{account}/domains/{domain}/dnssec ### Description Gets the DNSSEC status for a domain. ### Method GET ### Endpoint `/{account}/domains/{domain}/dnssec` ### Parameters #### Path Parameters - **account** (number) - Required - Account ID - **domain** (string) - Required - Domain name or ID ### Response #### Success Response (200) - **data** (DNSSEC) - DNSSEC object with enabled status ``` -------------------------------- ### Get Certificate Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves details for a specific certificate. ```APIDOC ## GET /v2/{account}/domains/{domain}/certificates/{certificate} ### Description Retrieves details for a specific certificate. ### Method GET ### Endpoint /v2/{account}/domains/{domain}/certificates/{certificate} ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **domain** (string) - Required - The domain name. - **certificate** (string) - Required - The certificate identifier. #### Query Parameters - **params** (object) - Optional - Additional parameters for the request. ### Response #### Success Response (200) - **data** (Certificate) - The certificate details. ``` -------------------------------- ### Initialize DNSimple Client and List Certificates Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/certificates.md Initializes the DNSimple client using an access token and demonstrates listing certificates for a domain. Ensure the ACCESS_TOKEN environment variable is set. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.TOKEN }); // List certificates for a domain const { data: certs } = await client.certificates.listCertificates(1010, "example.com"); // Get certificate details const { data: cert } = await client.certificates.getCertificate(1010, "example.com", 12345); // Download certificate const { data: download } = await client.certificates.downloadCertificate(1010, "example.com", 12345); ``` -------------------------------- ### DNSimple API v2 Account-Specific Paths Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Examples of common HTTP methods for account-specific API endpoints, including domains and zone records. Requires an account ID, domain name, or zone name. ```typescript // Account-specific GET /v2/{account}/domains POST /v2/{account}/domains GET /v2/{account}/domains/{domain} DELETE /v2/{account}/domains/{domain} // Zone records GET /v2/{account}/zones/{zone}/records POST /v2/{account}/zones/{zone}/records GET /v2/{account}/zones/{zone}/records/{record} PATCH /v2/{account}/zones/{zone}/records/{record} DELETE /v2/{account}/zones/{zone}/records/{record} ``` -------------------------------- ### getWhoisPrivacy Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/domains.md Gets the WHOIS privacy status for a domain. ```APIDOC ## GET /{account}/domains/{domain}/whois_privacy ### Description Gets the WHOIS privacy status for a domain. ### Method GET ### Endpoint `/{account}/domains/{domain}/whois_privacy` ### Parameters #### Path Parameters - **account** (number) - Required - The account ID. - **domain** (string) - Required - The domain name. #### Query Parameters - **params** (QueryParams) - Optional - Additional query parameters. ``` -------------------------------- ### Get Service Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves details for a specific service by its ID. ```APIDOC ## GET /v2/services/{service} ### Description Retrieves details for a specific service by its ID. ### Method GET ### Endpoint /v2/services/{service} ### Parameters #### Path Parameters - **service** (string) - Required - The service identifier. #### Query Parameters - **params** (object) - Optional - Additional query parameters. ### Response #### Success Response (200) - **data** (Service) - The requested Service object. ``` -------------------------------- ### getWebhook Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/other-modules.md Gets a specific webhook by its ID within an account. ```APIDOC ## GET /{account}/webhooks/{webhook} ### Description Gets a webhook. ### Method GET ### Endpoint `/{account}/webhooks/{webhook}` ### Parameters #### Path Parameters - **account** (number) - Required - The account ID. - **webhook** (number) - Required - The ID of the webhook to retrieve. ``` -------------------------------- ### Initialize DNSimple Client and List Zones Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/zones.md Initializes the DNSimple client using an access token and demonstrates listing zones within an account. Ensure the ACCESS_TOKEN environment variable is set. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.TOKEN }); // List zones in an account const { data: zones } = await client.zones.listZones(1010); // Get a specific zone const { data: zone } = await client.zones.getZone(1010, "example.com"); // List DNS records for a zone const { data: records } = await client.zones.listZoneRecords(1010, "example.com"); ``` -------------------------------- ### getService Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/other-modules.md Gets details of a specific service by its ID or slug. ```APIDOC ## GET /services/{service} ### Description Gets details of a specific service. ### Method GET ### Endpoint /services/{service} ### Parameters #### Path Parameters - **service** (string) - Required - Service ID or slug ### Response #### Success Response (200) - **data** (Service) - The Service object. ``` -------------------------------- ### Create DNSimple Client Using Static Defaults Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Demonstrates how to create a DNSimple client instance explicitly using the static default values for base URL and timeout, alongside a provided access token. ```typescript console.log(`Using DNSimple client v${DNSimple.VERSION}`); console.log(`Default timeout: ${DNSimple.DEFAULT_TIMEOUT}ms`); console.log(`Production API: ${DNSimple.DEFAULT_BASE_URL}`); // Create client with explicit defaults const client = new DNSimple({ accessToken: token, baseUrl: DNSimple.DEFAULT_BASE_URL, timeout: DNSimple.DEFAULT_TIMEOUT, }); ``` -------------------------------- ### Domains: Get Domain Source: https://github.com/dnsimple/dnsimple-node/blob/main/README.md Retrieves a specific domain by its name. ```APIDOC ## GET /v2/domains/{domain_name} ### Description Retrieves a specific domain by its name. ### Method GET ### Endpoint /v2/domains/{domain_name} ### Parameters #### Path Parameters - **domain_name** (string) - Required - The name of the domain to retrieve. ### Response #### Success Response (200) - **data** (object) - The domain object. - **id** (integer) - The domain ID. - **name** (string) - The domain name. - **unicode_name** (string) - The domain name in Unicode. - **state** (string) - The current state of the domain. - **created_at** (string) - The date and time the domain was created. - **updated_at** (string) - The date and time the domain was last updated. ### Response Example ```json { "data": { "id": 1, "name": "example.com", "unicode_name": "example.com", "state": "live", "created_at": "2014-01-01T10:00:00Z", "updated_at": "2014-01-01T10:00:00Z" } } ``` ``` -------------------------------- ### Instantiate DNSimple with Configuration (Previous Versions) Source: https://github.com/dnsimple/dnsimple-node/blob/main/UPGRADE.md How to instantiate DNSimple with initial configuration and modify properties in previous versions. ```javascript const DNSimple = require("dnsimple"); // Provide initial configuration. const dnsimple = DNSimple({ accessToken: "secret", userAgent: "world", }); // Changing after instantiation. dnsimple.setTimeout(3); dnsimple.setUserAgent("hello"); ``` -------------------------------- ### Get Template Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves a specific template by its ID for a given account. ```APIDOC ## GET /v2/{account}/templates/{template} ### Description Retrieves a specific template by its ID for a given account. ### Method GET ### Endpoint /v2/{account}/templates/{template} ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **template** (string) - Required - The ID of the template to retrieve. #### Query Parameters - **params** (object) - Optional - Parameters for the request. ### Response #### Success Response (200) - **data** (Template) - The requested Template object. ``` -------------------------------- ### Get Webhook Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves a specific webhook by its ID for the specified account. ```APIDOC ## GET /v2/{account}/webhooks/{webhook} ### Description Retrieves a specific webhook by its ID for the specified account. ### Method GET ### Endpoint /v2/{account}/webhooks/{webhook} ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **webhook** (string) - Required - The webhook identifier. #### Query Parameters - **params** (object) - Optional - Additional query parameters. ### Response #### Success Response (200) - **data** (Webhook) - The requested Webhook object. ``` -------------------------------- ### Configure DNSimple Client for Sandbox Environment Source: https://github.com/dnsimple/dnsimple-node/blob/main/README.md Illustrates how to configure the DNSimple client to use the sandbox environment by specifying a custom `baseUrl`. Ensure you use a sandbox-specific access token. ```javascript const { DNSimple } = require("dnsimple"); const client = new DNSimple({ baseUrl: "https://api.sandbox.dnsimple.com", accessToken: process.env.TOKEN, }); ``` -------------------------------- ### Get Domain Transfer Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves the details of a specific domain transfer. ```APIDOC ## GET /v2/{account}/registrar/domains/{domain}/transfers/{domaintransfer} ### Description Retrieves the details of a specific domain transfer. ### Method GET ### Endpoint /v2/{account}/registrar/domains/{domain}/transfers/{domaintransfer} ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **domain** (string) - Required - The domain name. - **domaintransfer** (string) - Required - The domain transfer identifier. #### Query Parameters - **params** (object) - Optional - Parameters for the request. ### Response #### Success Response (200) - **data** (DomainTransfer) - The details of the domain transfer. ``` -------------------------------- ### Get Domain Registration Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves the details of a specific domain registration. ```APIDOC ## GET /v2/{account}/registrar/domains/{domain}/registrations/{domainregistration} ### Description Retrieves the details of a specific domain registration. ### Method GET ### Endpoint /v2/{account}/registrar/domains/{domain}/registrations/{domainregistration} ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **domain** (string) - Required - The domain name. - **domainregistration** (string) - Required - The domain registration identifier. #### Query Parameters - **params** (object) - Optional - Parameters for the request. ### Response #### Success Response (200) - **data** (DomainRegistration) - The details of the domain registration. ``` -------------------------------- ### Initialize DNSimple Client and Manage Contacts Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/contacts-accounts-identity.md Demonstrates how to initialize the DNSimple client with an access token and perform basic contact management operations such as listing and creating contacts. Ensure your access token is stored in the environment variable `TOKEN`. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.TOKEN }); // List contacts const { data: contacts } = await client.contacts.listContacts(1010); // Create a contact const { data: contact } = await client.contacts.createContact(1010, { first_name: "John", last_name: "Doe", email: "john@example.com", address1: "123 Main St", city: "San Francisco", state_province: "CA", postal_code: "94105", country: "US", phone: "+1.4155551234", }); ``` -------------------------------- ### Get Domain Prices Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves the pricing details for a specific domain. ```APIDOC ## GET /v2/{account}/registrar/domains/{domain}/prices ### Description Retrieves the pricing details for a specific domain. ### Method GET ### Endpoint /v2/{account}/registrar/domains/{domain}/prices ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **domain** (string) - Required - The domain name. #### Query Parameters - **params** (object) - Optional - Parameters for the request. ### Response #### Success Response (200) - **data** (DomainPrices) - The pricing details for the domain. ``` -------------------------------- ### Initialize DNSimple Client with Access Token Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/INDEX.md Configure the DNSimple client with an access token from environment variables, a custom base URL, and a timeout. The user agent is optional. ```typescript const client = new DNSimple({ accessToken: process.env.DNSIMPLE_TOKEN, baseUrl: "https://api.dnsimple.com", // or sandbox URL timeout: 120000, // 2 minutes userAgent: "my-app/1.0", // optional }); ``` -------------------------------- ### Import DNSimple Class (Previous Versions) Source: https://github.com/dnsimple/dnsimple-node/blob/main/UPGRADE.md How to import the DNSimple class in previous versions using require. ```javascript const DNSimple = require("dnsimple"); const dnsimple = DNSimple({}); ``` -------------------------------- ### Get Contact Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves a specific contact by its ID for the given account. ```APIDOC ## GET /v2/{account}/contacts/{contact} ### Description Retrieves a specific contact by its ID for the given account. ### Method GET ### Endpoint /v2/{account}/contacts/{contact} ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **contact** (string) - Required - The contact identifier. #### Query Parameters - **params** (object) - Optional - Parameters for the request. ### Response #### Success Response (200) - **data** (Contact) - The requested Contact object. ``` -------------------------------- ### Get Zone Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves a specific zone by its identifier for the given account. ```APIDOC ## Get Zone ### Description Retrieves a specific zone by its identifier for the given account. ### Method GET ### Endpoint /v2/{account}/zones/{zone} ### Response #### Success Response (200) - **data** (Zone) - The requested Zone object. ``` -------------------------------- ### Get Domain Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves a specific domain by its ID for the given account. ```APIDOC ## GET /v2/{account}/domains/{domain} ### Description Retrieves a specific domain by its ID for the given account. ### Method GET ### Endpoint /v2/{account}/domains/{domain} ### Response #### Success Response (200) - data (Domain) - The requested domain object. ### Response Example { "data": { "id": 123, "account_id": 12345, "name": "example.com", "created_at": "2023-01-01T12:00:00Z", "updated_at": "2023-01-01T12:00:00Z" } } ``` -------------------------------- ### Initialize DNSimple Client with Environment Variables Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Instantiate the DNSimple client using environment variables for access token, base URL, timeout, and user agent. Ensure the timeout is parsed as an integer. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken: process.env.DNSIMPLE_TOKEN, baseUrl: process.env.DNSIMPLE_API_URL, timeout: parseInt(process.env.DNSIMPLE_TIMEOUT || "120000"), userAgent: `${process.env.APP_NAME}/${process.env.APP_VERSION}`, }); ``` -------------------------------- ### Get TLD Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves details for a specific Top-Level Domain (TLD) by its name. ```APIDOC ## GET /v2/tlds/{tld} ### Description Retrieves details for a specific Top-Level Domain (TLD) by its name. ### Method GET ### Endpoint /v2/tlds/{tld} ### Parameters #### Path Parameters - **tld** (string) - Required - The TLD identifier. #### Query Parameters - **params** (object) - Optional - Additional query parameters. ### Response #### Success Response (200) - **data** (TLD) - The requested TLD object. ``` -------------------------------- ### Create a New Domain Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/domains.md Demonstrates the process of creating a new domain within a specified account by providing the domain name. ```typescript const { data: domain } = await client.domains.createDomain(1010, { name: "mynewdomain.com", }); console.log(`Domain created: ${domain.name} (ID: ${domain.id})`); ``` -------------------------------- ### Get Certificate Private Key Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves the private key for a specific certificate. ```APIDOC ## GET /v2/{account}/domains/{domain}/certificates/{certificate}/private_key ### Description Retrieves the private key for a specific certificate. ### Method GET ### Endpoint /v2/{account}/domains/{domain}/certificates/{certificate}/private_key ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **domain** (string) - Required - The domain name. - **certificate** (string) - Required - The certificate identifier. #### Query Parameters - **params** (object) - Optional - Additional parameters for the request. ### Response #### Success Response (200) - **data** (CertificatePrivateKey) - The certificate's private key. ``` -------------------------------- ### Instantiate DNSimple Client Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/api-reference.md Create a new instance of the DNSimple client. Supports production, sandbox, and custom configurations. ```javascript const { DNSimple } = require("dnsimple"); // Production environment const client = new DNSimple({ accessToken: process.env.TOKEN, }); // Sandbox environment const sandboxClient = new DNSimple({ baseUrl: "https://api.sandbox.dnsimple.com", accessToken: process.env.SANDBOX_TOKEN, }); // Custom user agent const customClient = new DNSimple({ accessToken: process.env.TOKEN, userAgent: "my-app/1.0", timeout: 30000, // 30 second timeout }); ``` -------------------------------- ### Get Zone Record Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves a specific DNS record for a given zone. ```APIDOC ## Get Zone Record ### Description Retrieves a specific DNS record for a given zone. ### Method GET ### Endpoint /v2/{account}/zones/{zone}/records/{record} ### Response #### Success Response (200) - **data** (ZoneRecord) - The requested ZoneRecord object. ``` -------------------------------- ### Initialize DNSimple Client in Browser Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Configures the DNSimple client for a browser environment, utilizing the default Fetch API. Requires an access token. ```typescript // In browser context const client = new DNSimple({ accessToken: token, // Uses browser Fetch API automatically }); ``` -------------------------------- ### Get Zone File Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves the zone file content for a specific zone. ```APIDOC ## Get Zone File ### Description Retrieves the zone file content for a specific zone. ### Method GET ### Endpoint /v2/{account}/zones/{zone}/file ### Response #### Success Response (200) - **data** (ZoneFile) - The ZoneFile object containing the zone file content. ``` -------------------------------- ### Get Extended Attributes Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves the extended attributes for a given Top-Level Domain (TLD). ```APIDOC ## GET /v2/tlds/{tld}/extended_attributes ### Description Retrieves the extended attributes for a given Top-Level Domain (TLD). ### Method GET ### Endpoint /v2/tlds/{tld}/extended_attributes ### Parameters #### Path Parameters - **tld** (string) - Required - The Top-Level Domain. #### Query Parameters - **params** (object) - Optional - Parameters for the request. ### Response #### Success Response (200) - **data** (Array) - A list of ExtendedAttribute objects. ``` -------------------------------- ### Delete a Domain Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/domains.md Provides an example of how to permanently delete a domain from an account using its name or ID. ```typescript await client.domains.deleteDomain(1010, "old-domain.com"); console.log("Domain deleted"); ``` -------------------------------- ### createPrimaryServer Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/other-modules.md Creates a primary server. ```APIDOC ## POST /{account}/secondary_dns/primaries ### Description Creates a primary server. ### Method POST ### Endpoint `/{account}/secondary_dns/primaries` ### Parameters #### Path Parameters - **account** (number) - Required - The account ID. #### Query Parameters - **params** (QueryParams) - Optional - Additional query parameters. #### Request Body - **data** (Partial) - Required - The data for the primary server. - **name** (string) - Optional - The name of the primary server. - **ip** (string) - Optional - The IP address of the primary server. - **port** (number) - Optional - The port of the primary server. ``` -------------------------------- ### Get WHOIS Privacy Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves the WHOIS privacy status for a specific domain within an account. ```APIDOC ## GET /v2/{account}/domains/{domain}/whois_privacy ### Description Retrieves the WHOIS privacy status for a specific domain within an account. ### Method GET ### Endpoint /v2/{account}/domains/{domain}/whois_privacy ### Parameters #### Path Parameters - **account** (string) - Required - The account identifier. - **domain** (string) - Required - The domain name. ### Response #### Success Response (200) - **data** (WhoisPrivacy) - An object containing the domain's WHOIS privacy status. ``` -------------------------------- ### Instantiate DNSimple with Configuration (Version 7) Source: https://github.com/dnsimple/dnsimple-node/blob/main/UPGRADE.md How to instantiate DNSimple with initial configuration and modify properties in version 7. Configuration properties are now accessed directly. ```typescript import { DNSimple } from "dnsimple"; // Provide initial configuration, or omit to use defaults. const dnsimple = new DNSimple({ accessToken: "secret", userAgent: "world", }); // Changing after instantiation. dnsimple.timeout = 3; dnsimple.userAgent = "hello"; ``` -------------------------------- ### Get DNSSEC Status Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves the DNSSEC status for a specific domain within the given account. ```APIDOC ## GET /v2/{account}/domains/{domain}/dnssec ### Description Retrieves the DNSSEC status for a specific domain within the given account. ### Method GET ### Endpoint /v2/{account}/domains/{domain}/dnssec ### Response #### Success Response (200) - data (DNSSEC) - The DNSSEC status object. ### Response Example { "data": { "enabled": true } } ``` -------------------------------- ### Get TLD Details Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/other-modules.md Retrieves details for a specific TLD. Ensure the TLD string is valid. ```typescript const { data: tld } = await client.tlds.getTld("com"); console.log(`TLD: ${tld.tld}`); console.log(`Registration enabled: ${tld.registration_enabled}`); console.log(`Renewal enabled: ${tld.renewal_enabled}`); console.log(`Transfer enabled: ${tld.transfer_enabled}`); console.log(`WHOIS privacy: ${tld.whois_privacy}`); console.log(`Min registration: ${tld.minimum_registration} years`); ``` -------------------------------- ### Creating a Zone Record with TypeScript Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Demonstrates creating a zone record using the DNSimple client in TypeScript. It handles the asynchronous operation and returns the created ZoneRecord. ```typescript async function createRecord( accountId: number, zone: string, record: Partial ): Promise { const { data } = await client.zones.createZoneRecord( accountId, zone, record as any ); return data; } ``` -------------------------------- ### DNSimple Client Constructor Options Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/configuration.md Defines the available options for configuring the DNSimple client during instantiation. The access token is required for authenticated requests. ```typescript import { DNSimple } from "dnsimple"; const client = new DNSimple({ accessToken?: string; baseUrl?: string; fetcher?: Fetcher; timeout?: number; userAgent?: string; }); ``` -------------------------------- ### Get Current User and Account Source: https://github.com/dnsimple/dnsimple-node/blob/main/_autodocs/endpoints.md Retrieves information about the currently authenticated user and their associated account. ```APIDOC ## GET /v2/whoami ### Description Retrieves information about the currently authenticated user and their associated account. ### Method GET ### Endpoint /v2/whoami ### Response #### Success Response (200) - data (object) - Contains account and user information. ### Response Example { "data": { "account": { "id": 12345, "name": "example-account", "plan": "free", "created_at": "2023-01-01T12:00:00Z", "updated_at": "2023-01-01T12:00:00Z" }, "user": { "id": 67890, "email": "user@example.com", "name": "Test User", "created_at": "2023-01-01T12:00:00Z", "updated_at": "2023-01-01T12:00:00Z" } } } ```