### Install Project Dependencies Source: https://github.com/beehiiv/typescript-sdk/blob/master/CONTRIBUTING.md Installs all necessary dependencies for the project using pnpm. Ensure Node.js 20 or higher and pnpm are installed. ```bash pnpm install ``` -------------------------------- ### Install Beehiiv TypeScript SDK Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Install the Beehiiv TypeScript SDK using npm. ```sh npm i -s @beehiiv/sdk ``` -------------------------------- ### Custom Pino Logger Example Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Implement a custom logger for the SDK using the 'pino' library by adhering to the `logging.ILogger` interface. ```typescript import pino from 'pino'; const pinoLogger = pino({...}); const logger: logging.ILogger = { debug: (msg, ...args) => pinoLogger.debug(args, msg), info: (msg, ...args) => pinoLogger.info(args, msg), warn: (msg, ...args) => pinoLogger.warn(args, msg), error: (msg, ...args) => pinoLogger.error(args, msg), }; ``` -------------------------------- ### Customize Fetch Client (Alternative Import) Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Customize the underlying HTTP client by providing your own `fetcher` implementation to the `BeehiivClient` options. This example uses an alternative import path for the SDK. ```typescript import { BeehiivClient } from 'beehiiv'; const beehiiv = new BeehiivClient({ apiKey: "...", fetcher: // provide your implementation here }); ``` -------------------------------- ### Custom Winston Logger Example Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Implement a custom logger for the SDK using the 'winston' library by adhering to the `logging.ILogger` interface. ```typescript import winston from 'winston'; const winstonLogger = winston.createLogger({...}); const logger: logging.ILogger = { debug: (msg, ...args) => winstonLogger.debug(msg, ...args), info: (msg, ...args) => winstonLogger.info(msg, ...args), warn: (msg, ...args) => winstonLogger.warn(msg, ...args), error: (msg, ...args) => winstonLogger.error(msg, ...args), }; ``` -------------------------------- ### Get Automation Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a specific automation by ID. ```APIDOC ## Get Automation ### Description Retrieve a specific automation by ID. ### Method GET ### Endpoint `/automations/{automation_id}` (This is an inferred endpoint based on the SDK method `client.automations.show`) ### Parameters #### Path Parameters - **publication_id** (string) - Required - The ID of the publication. - **automation_id** (string) - Required - The ID of the automation to retrieve. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **automation** (object) - The automation object. #### Response Example ```json { "automation_id": "aut_00000000-0000-0000-0000-000000000000", "name": "Welcome Series" } ``` ``` -------------------------------- ### Get Post Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a single post by its ID. ```APIDOC ## Get Post ### Description Retrieve a single post by its ID. ### Method GET ### Endpoint `/posts/{post_id}` (This is an inferred endpoint based on the SDK method `client.posts.show`) ### Parameters #### Path Parameters - **publication_id** (string) - Required - The ID of the publication. - **post_id** (string) - Required - The ID of the post to retrieve. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **post** (object) - The post object. #### Response Example ```json { "post_id": "post_00000000-0000-0000-0000-000000000000", "title": "My Newsletter Post" } ``` ``` -------------------------------- ### Get Post Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a single post by its unique ID. Requires both publication and post IDs. ```typescript const post = await client.posts.show( "pub_00000000-0000-0000-0000-000000000000", "post_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### Advanced Configuration: Access Raw Response Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Get access to raw response data including headers. ```APIDOC ```typescript const { data, rawResponse } = await client.subscriptions.index("pub_xxx").withRawResponse(); console.log(data); console.log(rawResponse.headers["x-rate-limit"]); ``` ``` -------------------------------- ### Get Custom Field Source: https://context7.com/beehiiv/typescript-sdk/llms.txt View a specific custom field. Requires publication and field IDs. ```typescript const field = await client.customFields.show("pub_00000000-0000-0000-0000-000000000000", "field_id"); ``` -------------------------------- ### Get Referral Program Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve details about a publication's referral program, including milestones and rewards. Requires the publication ID. ```typescript const referralProgram = await client.referralProgram.show("pub_00000000-0000-0000-0000-000000000000"); ``` -------------------------------- ### Configure Request Timeout Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Adjust the request timeout duration by specifying the 'timeoutInSeconds' option. This example sets the timeout to 30 seconds. ```typescript const response = await client.automationJourneys.create(..., { timeoutInSeconds: 30 // override timeout to 30s }); ``` -------------------------------- ### Get Segment Results Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Get a lightweight list of subscriber IDs for a segment. Requires publication and segment IDs. ```typescript const results = await client.segments.expandResults( "pub_00000000-0000-0000-0000-000000000000", "seg_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### Initialize Beehiiv Client and Create Automation Journey Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Instantiate the Beehiiv client with your API token and create an automation journey. Ensure you replace 'YOUR_TOKEN' with your actual API token. ```typescript import { BeehiivClient } from "@beehiiv/sdk"; const client = new BeehiivClient({ token: "YOUR_TOKEN" }); await client.automationJourneys.create("pub_00000000-0000-0000-0000-000000000000", "aut_00000000-0000-0000-0000-000000000000", { email: "test@example.com", double_opt_override: "on" }); ``` -------------------------------- ### Initialize Beehiiv Client Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Create a Beehiiv client instance using your API token. Configure optional parameters like timeout and retries. ```typescript import { BeehiivClient } from "@beehiiv/sdk"; const client = new BeehiivClient({ token: "YOUR_TOKEN", timeoutInSeconds: 60, maxRetries: 2 }); ``` -------------------------------- ### GET /subscriptions/getBySubscriberId Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Retrieves a single subscription by the subscriber ID. ```APIDOC ## GET /subscriptions/getBySubscriberId ### Description Retrieve a single subscription belonging to a specific publication using the subscriber's ID. ### Method GET ### Endpoint `/subscriptions/{publicationId}/subscriptions/subscriber/{subscriberId}` ### Parameters #### Path Parameters - **publicationId** (Beehiiv.PublicationId) - Required - The prefixed ID of the publication object. - **subscriberId** (string) - Required - The ID of the subscriber object. #### Query Parameters - **request** (Beehiiv.SubscriptionsGetBySubscriberIdRequest) - Optional - Additional request parameters. - **requestOptions** (SubscriptionsClient.RequestOptions) - Optional - Options for the request. ### Request Example ```typescript await client.subscriptions.getBySubscriberId("pub_00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000"); ``` ### Response #### Success Response (200) - **subscription** (Beehiiv.SubscriptionResponse) - Details of the retrieved subscription. ``` -------------------------------- ### Get Aggregate Post Stats Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve aggregate statistics for all posts. ```APIDOC ## Get Aggregate Post Stats ### Description Retrieve aggregate statistics for all posts. ### Method GET ### Endpoint `/posts/stats/aggregate` (This is an inferred endpoint based on the SDK method `client.posts.aggregateStats`) ### Parameters #### Path Parameters - **publication_id** (string) - Required - The ID of the publication. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **stats** (object) - An object containing aggregate statistics for posts. #### Response Example ```json { "total_posts": 100, "total_views": 50000 } ``` ``` -------------------------------- ### Run Test Suite Source: https://github.com/beehiiv/typescript-sdk/blob/master/CONTRIBUTING.md Executes the entire test suite for the project. Ensure all tests pass before committing changes. ```bash pnpm test ``` -------------------------------- ### Create Bulk Subscriptions with Beehiiv SDK Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Use this method to create new subscriptions for a publication. It allows specifying email, welcome email preference, and custom fields for each subscription. ```typescript await client.bulkSubscriptions.create("pub_00000000-0000-0000-0000-000000000000", { subscriptions: [{ email: "bruce.wayne@wayneenterprise.com", reactivate_existing: false, send_welcome_email: false, custom_fields: [{ name: "Favorite Color", value: "Red" }] }, { email: "lucius.fox@wayneenterprise.com", reactivate_existing: false, send_welcome_email: false, custom_fields: [{ name: "Favorite Color", value: "Blue" }] }] }); ``` -------------------------------- ### Get Webhook Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a specific webhook using its publication ID and webhook ID. ```typescript const webhook = await client.webhooks.show( "pub_00000000-0000-0000-0000-000000000000", "ep_0000000000000000000000000000" ); ``` -------------------------------- ### Get Tier Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a single tier by ID. Requires publication and tier IDs. ```typescript const tier = await client.tiers.show( "pub_00000000-0000-0000-0000-000000000000", "tier_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### Get Segment Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve information about a specific segment. Requires publication and segment IDs. ```typescript const segment = await client.segments.show( "pub_00000000-0000-0000-0000-000000000000", "seg_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### Create Post with Diverse Blocks Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Use this to create a post with a comprehensive set of content blocks. Ensure the client is initialized and the publication ID is correct. ```typescript await client.posts.create("pub_00000000-0000-0000-0000-000000000000", { title: "The Kitchen Sink Post (refactored version)", subtitle: "Contains lots of examples of each block type and the various settings you could use", blocks: [{ type: "heading", level: "2", textAlignment: "center", text: "This is my block!!!", anchorHeader: false, anchorIncludeInToc: false }, { type: "list", listType: "ordered", items: ["a", "b", "c"] }, { type: "list", listType: "ordered", items: ["d", "e", "f"], startNumber: 4 }, { type: "list", listType: "unordered", items: ["g", "h", "i"], startNumber: 4 }, { type: "table", headerRow: true, headerColumn: true, rows: [[{ text: "A" }, { text: "B", alignment: "center" }, { text: "C", alignment: "right" }], [{ text: "D", alignment: "right" }, { text: "E", alignment: "center" }, { text: "F", alignment: "left" }]] }, { type: "table", rows: [[{ text: "A" }, { text: "B" }, { text: "C" }], [{ text: "D" }, { text: "E" }, { text: "F" }]] }, { type: "table", headerRow: false, rows: [[{ text: "A" }, { text: "B" }, { text: "C" }], [{ text: "D" }, { text: "E" }, { text: "F" }]] }, { type: "columns", columns: [{ blocks: [{ type: "paragraph", plaintext: "Marble Column 1 {{email}}" }] }, { blocks: [{ type: "image", imageUrl: "https://cdn.britannica.com/89/164789-050-D6B5E2C7/Barack-Obama-2012.jpg", url: "https://www.whitehouse.gov/", title: "Barry O", alt_text: "A picture of Barry Obama", caption: "One Cool President", captionAlignment: "center", imageAlignment: "right", width: 75 }] }] }, { type: "advertisement", opportunity_id: "d8dfa6be-24b5-4cad-8350-ae44366dbd4c" }, { type: "image", imageUrl: "https://cdn.britannica.com/89/164789-050-D6B5E2C7/Barack-Obama-2012.jpg", url: "https://www.whitehouse.gov/", title: "Barry O", alt_text: "A picture of Barry Obama", caption: "One Cool President", captionAlignment: "center", imageAlignment: "right", width: 75 }, { type: "paragraph", formattedText: [{ text: "This is going to be " }, { text: "a really, really awesome time ", styling: ["bold"] }, { text: "Are you ready for this?", styling: ["italic", "bold"] }] }, { type: "button", href: "/subscribe", target: "_blank", alignment: "center", size: "large", text: "Subscribe" }, { type: "button", href: "/signup", target: "_blank", alignment: "right", size: "small", text: "Sign Up" }, { type: "button", href: "/", target: "_blank", text: "View Posts" }, { type: "heading", level: "4", textAlignment: "right", text: "This is my block!!!", anchorHeader: true, anchorIncludeInToc: true }] ``` -------------------------------- ### Get Automation Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a specific automation by its ID. Requires both publication and automation IDs. ```typescript const automation = await client.automations.show( "pub_00000000-0000-0000-0000-000000000000", "aut_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### Build the Project Source: https://github.com/beehiiv/typescript-sdk/blob/master/CONTRIBUTING.md Compiles the TypeScript project. This command should be run after making code changes or before testing. ```bash pnpm build ``` -------------------------------- ### Configure Custom Logging Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Configure logging with different log levels and custom logger implementations. Import logging utilities from the SDK. ```typescript import { BeehiivClient, logging } from "@beehiiv/sdk"; const client = new BeehiivClient({ token: "YOUR_TOKEN", logging: { level: logging.LogLevel.Debug, logger: new logging.ConsoleLogger(), silent: false } }); ``` -------------------------------- ### Create a New Post with Beehiiv TypeScript SDK Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Use this method to create a new post. It allows for extensive customization of email and web settings, social sharing options, and recipient targeting. Ensure all required fields like `post_template_id` and `scheduled_at` are correctly formatted. ```typescript await client.posts.create("pub_00000000-0000-0000-0000-000000000000", { post_template_id: "post_template_00000000-0000-0000-0000-000000000000", scheduled_at: "2024-12-25T12:00:00Z", custom_link_tracking_enabled: true, email_capture_type_override: "none", override_scheduled_at: "2022-10-26T14:01:16Z", social_share: "comments_and_likes_only", thumbnail_image_url: "https://images.squarespace-cdn.com/content/v1/56e4ca0540261d39b90e4b18/1605047208324-PONGEYKEAKTMM1LANHJ5/1ED706BF-A70B-4F26-B3D5-266B449DDA8A_1_105_c.jpeg", email_settings: { from_address: "from_address", custom_live_url: "https://beehiiv.com", display_title_in_email: true, display_byline_in_email: true, display_subtitle_in_email: true, email_header_engagement_buttons: "email_header_engagement_buttons", email_header_social_share: "email_header_social_share", email_preview_text: "email_preview_text", email_subject_line: "email_subject_line" }, web_settings: { display_thumbnail_on_web: true, hide_from_feed: true, slug: "and-this-is-gonna-rock" }, seo_settings: { default_description: "default_description", default_title: "default_title", og_description: "OpenGraph description", og_title: "Opengraph Title", twitter_description: "Twitter Stuff", twitter_title: "My Twitter Article" }, content_tags: ["Obama", "Care", "Rocks", "Healthcare"], recipients: { web: { tier_ids: ["premium"] }, email: { tier_ids: ["premium", "free"], include_segment_ids: ["seg_6426b403-39f5-42bd-86e9-9533fb0099e7"], exclude_segment_ids: ["seg_e34b4085-aef6-449f-a699-7563f915f852"] } } }); ``` -------------------------------- ### Get Subscription by Email Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a single subscription by its email address within a specific publication. ```typescript const subscription = await client.subscriptions.getByEmail( "pub_00000000-0000-0000-0000-000000000000", "work@example.com" ); ``` -------------------------------- ### Advanced Configuration: Custom Headers and Query Parameters Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Add custom headers and query parameters to requests. ```APIDOC ```typescript const response = await client.subscriptions.index("pub_xxx", {}, { headers: { "X-Custom-Header": "custom value" }, queryParams: { "custom_param": "custom_value" } } ); ``` ``` -------------------------------- ### GET /tiers/show Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Fetches the details of a single tier for a given publication using its unique tier ID. ```APIDOC ## GET /tiers/show ### Description Retrieve a single tier belonging to a specific publication. ### Method GET ### Endpoint /tiers/show ### Parameters #### Path Parameters - **publicationId** (Beehiiv.PublicationId) - Required - The prefixed ID of the publication object - **tierId** (Beehiiv.TierId) - Required - The prefixed ID of the tier object #### Request Body - **request** (Beehiiv.GetPublicationsPublicationIdTiersTierIdRequest) - Optional - Parameters for retrieving a specific tier. - **requestOptions** (TiersClient.RequestOptions) - Optional - Additional request options. ### Request Example ```typescript await client.tiers.show("pub_00000000-0000-0000-0000-000000000000", "tier_00000000-0000-0000-0000-000000000000"); ``` ### Response #### Success Response (200) - **TierResponse** (Beehiiv.TierResponse) - Details of the requested tier. ``` -------------------------------- ### Create Tier Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Create a new subscription tier with pricing options. Requires publication ID and tier details including name, description, and prices. ```typescript const tier = await client.tiers.create("pub_00000000-0000-0000-0000-000000000000", { name: "Gold Tier", description: "Our premium tier with exclusive benefits", prices_attributes: [ { currency: "usd", amount_cents: 500, enabled: true, interval: "month", interval_display: "Monthly", cta: "Subscribe Now", features: ["Exclusive content", "Ad-free experience", "Priority support"] } ] }); ``` -------------------------------- ### Create a Webhook Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Create a new webhook subscription for a publication. Specify the URL and the event types to subscribe to. ```typescript await client.webhooks.create("pub_00000000-0000-0000-0000-000000000000", { url: "https://example.com/webhook", event_types: ["post.sent"] }); ``` -------------------------------- ### Get Email Blast Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a single email blast by ID. Requires publication and blast IDs. ```typescript const blast = await client.emailBlasts.show( "pub_00000000-0000-0000-0000-000000000000", "blast_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### POST /tiers/create Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Creates a new tier for a specified publication. This endpoint allows for the definition of tier name, description, and pricing details. ```APIDOC ## POST /tiers/create ### Description Create a new tier for a publication. ### Method POST ### Endpoint /tiers/create ### Parameters #### Path Parameters - **publicationId** (Beehiiv.PublicationId) - Required - The prefixed ID of the publication object #### Request Body - **request** (Beehiiv.PostPublicationsPublicationIdTiersRequest) - Required - The payload for creating a new tier. - **requestOptions** (TiersClient.RequestOptions) - Optional - Additional request options. ### Request Example ```typescript await client.tiers.create("pub_00000000-0000-0000-0000-000000000000", { name: "Gold Tier", description: "Our premium tier with exclusive benefits", prices_attributes: [{ currency: "usd", amount_cents: 500, enabled: true, interval: "month", interval_display: "Monthly", cta: "Subscribe Now", features: ["Exclusive content", "Ad-free experience", "Priority support"] }] }); ``` ### Response #### Success Response (200) - **TierResponse** (Beehiiv.TierResponse) - Details of the created tier. ``` -------------------------------- ### Advanced Configuration: Custom Logging Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Configure logging with different log levels and custom loggers. ```APIDOC ```typescript import { BeehiivClient, logging } from "@beehiiv/sdk"; const client = new BeehiivClient({ token: "YOUR_TOKEN", logging: { level: logging.LogLevel.Debug, logger: new logging.ConsoleLogger(), silent: false } }); ``` ``` -------------------------------- ### Get Subscription by ID Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a single subscription by its unique subscription ID within a specific publication. ```typescript const subscription = await client.subscriptions.getById( "pub_00000000-0000-0000-0000-000000000000", "sub_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### Create a Subscription Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Creates a new subscription for a publication. Allows specifying various details like email, welcome email preference, UTM parameters, and custom fields. ```typescript await client.subscriptions.create("pub_00000000-0000-0000-0000-000000000000", { email: "bruce.wayne@wayneenterprise.com", reactivate_existing: false, send_welcome_email: false, utm_source: "WayneEnterprise", utm_medium: "organic", utm_campaign: "fall_2022_promotion", referring_site: "www.wayneenterprise.com/blog", custom_fields: [{ name: "First Name", value: "Bruce" }, { name: "Last Name", value: "Wayne" }], stripe_customer_id: "cus_12345abcde" }); ``` -------------------------------- ### GET /tiers/index Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Retrieves a list of all tiers associated with a specific publication. Useful for displaying available subscription tiers. ```APIDOC ## GET /tiers/index ### Description Retrieve all tiers belonging to a specific publication. ### Method GET ### Endpoint /tiers/index ### Parameters #### Path Parameters - **publicationId** (Beehiiv.PublicationId) - Required - The prefixed ID of the publication object #### Request Body - **request** (Beehiiv.GetPublicationsPublicationIdTiersRequest) - Optional - Parameters for filtering or paginating tiers. - **requestOptions** (TiersClient.RequestOptions) - Optional - Additional request options. ### Request Example ```typescript await client.tiers.index("pub_00000000-0000-0000-0000-000000000000"); ``` ### Response #### Success Response (200) - **IndexTiersResponse** (Beehiiv.IndexTiersResponse) - A list of tiers for the publication. ``` -------------------------------- ### GET /subscriptions/getById Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Retrieves a single subscription by its ID. This endpoint replaces a deprecated endpoint that used subscriber ID. ```APIDOC ## GET /subscriptions/getById ### Description Retrieve a single subscription belonging to a specific publication using its unique subscription ID. This endpoint is the recommended replacement for older methods that used subscriber IDs. ### Method GET ### Endpoint `/subscriptions/{publicationId}/subscriptions/{subscriptionId}` ### Parameters #### Path Parameters - **publicationId** (Beehiiv.PublicationId) - Required - The prefixed ID of the publication object. - **subscriptionId** (Beehiiv.SubscriptionId) - Required - The prefixed ID of the subscription object. #### Query Parameters - **request** (Beehiiv.SubscriptionsGetByIdRequest) - Optional - Additional request parameters. - **requestOptions** (SubscriptionsClient.RequestOptions) - Optional - Options for the request. ### Request Example ```typescript await client.subscriptions.getById("pub_00000000-0000-0000-0000-000000000000", "sub_00000000-0000-0000-0000-000000000000"); ``` ### Response #### Success Response (200) - **subscription** (Beehiiv.SubscriptionResponse) - Details of the retrieved subscription. ``` -------------------------------- ### Customize Fetch Client Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Customize the underlying HTTP client by providing your own `fetcher` implementation to the `BeehiivClient` options. This is useful for unsupported environments. ```typescript import { BeehiivClient } from "@beehiiv/sdk"; const client = new BeehiivClient({ ... fetcher: // provide your implementation here }); ``` -------------------------------- ### List Segment Members Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Get all members in a segment with full subscription data. Requires publication and segment IDs. ```typescript const members = await client.segments.listMembers( "pub_00000000-0000-0000-0000-000000000000", "seg_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### Import and Use Request/Response Types Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Import and utilize request and response types from the SDK using the Beehiiv namespace for type safety. ```typescript import { Beehiiv } from "@beehiiv/sdk"; const request: Beehiiv.AutomationJourneysCreateRequest = { ... }; ``` -------------------------------- ### Create Post Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Create a new post with various block types including headings, lists, tables, images, and buttons. ```APIDOC ## Create Post ### Description Create a new post with various block types including headings, lists, tables, images, and buttons. ### Method POST ### Endpoint `/posts` (This is an inferred endpoint based on the SDK method `client.posts.create`) ### Parameters #### Path Parameters - **publication_id** (string) - Required - The ID of the publication. #### Query Parameters None #### Request Body - **title** (string) - Required - The title of the post. - **subtitle** (string) - Optional - The subtitle of the post. - **blocks** (array) - Required - An array of blocks that make up the post content. - **type** (string) - Required - The type of block (e.g., "heading", "paragraph", "list", "button"). - **level** (string) - Optional - The heading level (e.g., "1", "2"). - **textAlignment** (string) - Optional - The text alignment for the block. - **text** (string) - Required for heading and paragraph blocks - The text content. - **anchorHeader** (boolean) - Optional - Whether to create an anchor for the header. - **anchorIncludeInToc** (boolean) - Optional - Whether to include the header anchor in the table of contents. - **formattedText** (array) - Optional - An array of text segments with styling for paragraph blocks. - **text** (string) - Required - The text content. - **styling** (array) - Optional - An array of styling options (e.g., "bold", "italic"). - **listType** (string) - Optional - The type of list ("ordered" or "unordered"). - **items** (array) - Required for list blocks - An array of list items. - **href** (string) - Required for button blocks - The URL the button links to. - **target** (string) - Optional - The target attribute for the link (e.g., "_blank"). - **alignment** (string) - Optional - The alignment of the button. - **size** (string) - Optional - The size of the button. - **scheduled_at** (string) - Optional - The date and time to schedule the post for (ISO 8601 format). - **email_settings** (object) - Optional - Settings for the email distribution. - **email_subject_line** (string) - Required - The subject line for the email. - **email_preview_text** (string) - Optional - The preview text for the email. - **web_settings** (object) - Optional - Settings for the web display. - **slug** (string) - Required - The slug for the post URL. - **hide_from_feed** (boolean) - Optional - Whether to hide the post from the feed. - **content_tags** (array) - Optional - An array of tags for the post. ### Request Example ```json { "title": "My Newsletter Post", "subtitle": "An exciting update for our subscribers", "blocks": [ { "type": "heading", "level": "2", "textAlignment": "center", "text": "Welcome to Our Newsletter", "anchorHeader": false, "anchorIncludeInToc": false }, { "type": "paragraph", "formattedText": [ { "text": "This is going to be " }, { "text": "a really exciting update ", "styling": ["bold"] }, { "text": "for all our readers!", "styling": ["italic", "bold"] } ] }, { "type": "list", "listType": "unordered", "items": ["Feature one", "Feature two", "Feature three"] }, { "type": "button", "href": "/subscribe", "target": "_blank", "alignment": "center", "size": "large", "text": "Subscribe Now" } ], "scheduled_at": "2024-12-25T12:00:00Z", "email_settings": { "email_subject_line": "Your Weekly Update", "email_preview_text": "Check out what's new this week" }, "web_settings": { "slug": "my-newsletter-post", "hide_from_feed": false }, "content_tags": ["News", "Updates"] } ``` ### Response #### Success Response (200) - **post** (object) - The created post object. #### Response Example ```json { "post_id": "post_00000000-0000-0000-0000-000000000000", "title": "My Newsletter Post" } ``` ``` -------------------------------- ### Get Automation Journey Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a single automation journey by its ID. Requires publication, automation, and journey IDs. ```typescript const journey = await client.automationJourneys.show( "pub_00000000-0000-0000-0000-000000000000", "aut_00000000-0000-0000-0000-000000000000", "aj_00000000-0000-0000-0000-000000000000" ); ``` -------------------------------- ### Get Aggregate Post Stats Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve aggregated statistics for all posts within a publication. Requires a publication ID. ```typescript const stats = await client.posts.aggregateStats("pub_00000000-0000-0000-0000-000000000000"); ``` -------------------------------- ### Check Code Style Source: https://github.com/beehiiv/typescript-sdk/blob/master/CONTRIBUTING.md Verifies code style and formatting without making changes. Use `pnpm run lint` for linting and `pnpm run format:check` for formatting checks. ```bash pnpm run lint ``` ```bash pnpm run format:check ``` -------------------------------- ### Run Specific Test Types Source: https://github.com/beehiiv/typescript-sdk/blob/master/CONTRIBUTING.md Allows running specific types of tests, such as unit tests or integration tests. Use `pnpm test:unit` for unit tests and `pnpm test:wire` for integration tests. ```bash pnpm test:unit ``` ```bash pnpm test:wire ``` -------------------------------- ### Get Publication by ID Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve a single publication by its unique ID. The response contains detailed information about the publication. ```typescript const publication = await client.publications.show("pub_ad76629e-4a39-43ad-8055-0ee89dc6db15"); // Returns: { data: { id: "pub_xxx", name: "My Newsletter", description: "...", ... } } ``` -------------------------------- ### Create Subscription Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Create a new subscription for a publication. Supports custom fields, welcome email preference, and UTM tracking parameters. ```typescript const subscription = await client.subscriptions.create("pub_00000000-0000-0000-0000-000000000000", { email: "bruce.wayne@wayneenterprise.com", reactivate_existing: false, send_welcome_email: false, utm_source: "WayneEnterprise", utm_medium: "organic", utm_campaign: "fall_2022_promotion", referring_site: "www.wayneenterprise.com/blog", custom_fields: [ { name: "First Name", value: "Bruce" }, { name: "Last Name", value: "Wayne" } ], stripe_customer_id: "cus_12345abcde" }); ``` -------------------------------- ### Configure SDK Logging Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Configure SDK logging by providing a `logging` object to the client options. You can set the log level, specify a logger implementation, and control whether logging is silent. ```typescript import { BeehiivClient, logging } from "@beehiiv/sdk"; const client = new BeehiivClient({ ... logging: { level: logging.LogLevel.Debug, // defaults to logging.LogLevel.Info logger: new logging.ConsoleLogger(), // defaults to ConsoleLogger silent: false, // defaults to true, set to false to enable logging } }); ``` -------------------------------- ### Create Webhook Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Create a new webhook for a publication to receive event notifications. Specify the URL and the event types to subscribe to. ```typescript const webhook = await client.webhooks.create("pub_00000000-0000-0000-0000-000000000000", { url: "https://example.com/webhook", event_types: ["post.sent", "subscription.confirmed"] }); ``` -------------------------------- ### GET /bulkSubscriptionUpdates Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Retrieves a list of Subscription Update objects for a specified publication. This endpoint is useful for auditing or tracking subscription changes. ```APIDOC ## GET /bulkSubscriptionUpdates ### Description Returns a list of Subscription Update objects for a publication. ### Method GET ### Endpoint `/bulkSubscriptionUpdates` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **publicationId** (Beehiiv.PublicationId) - Required - The prefixed ID of the publication object. - **requestOptions** (BulkSubscriptionUpdatesClient.RequestOptions) - Optional - Options for the request. ### Request Example ```typescript await client.bulkSubscriptionUpdates.index("publicationId"); ``` ### Response #### Success Response (200) - **BulkSubscriptionUpdatesListResponse** (object) - The response object containing a list of subscription updates. #### Response Example ```json { "updates": [ { "id": "upd_1234", "subscription_id": "sub_1234", "status": "updated" } ] } ``` ``` -------------------------------- ### POST /bulkSubscriptions Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Creates new subscriptions for a given publication. It allows specifying subscription details, whether to reactivate existing ones, send welcome emails, and set custom fields. ```APIDOC ## POST /bulkSubscriptions ### Description Creates new subscriptions for a publication. ### Method POST ### Endpoint `/bulkSubscriptions` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **publicationId** (Beehiiv.PublicationId) - Required - The prefixed ID of the publication object. - **request** (Beehiiv.BulkSubscriptionsCreateRequest) - Required - The request object containing subscription details. - **subscriptions** (array) - Required - An array of subscription objects. - **email** (string) - Required - The email address of the subscriber. - **reactivate_existing** (boolean) - Optional - Whether to reactivate existing subscriptions. - **send_welcome_email** (boolean) - Optional - Whether to send a welcome email. - **custom_fields** (array) - Optional - An array of custom fields. - **name** (string) - Required - The name of the custom field. - **value** (string) - Required - The value of the custom field. - **requestOptions** (BulkSubscriptionsClient.RequestOptions) - Optional - Options for the request. ### Request Example ```json { "publicationId": "pub_00000000-0000-0000-0000-000000000000", "request": { "subscriptions": [ { "email": "bruce.wayne@wayneenterprise.com", "reactivate_existing": false, "send_welcome_email": false, "custom_fields": [ { "name": "Favorite Color", "value": "Red" } ] }, { "email": "lucius.fox@wayneenterprise.com", "reactivate_existing": false, "send_welcome_email": false, "custom_fields": [ { "name": "Favorite Color", "value": "Blue" } ] } ] } } ``` ### Response #### Success Response (200) - **BulkSubscriptionCreateResponse** (object) - The response object containing details of the created bulk subscriptions. #### Response Example ```json { "message": "Subscriptions created successfully." } ``` ``` -------------------------------- ### List Automations Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve all automations for a publication. ```APIDOC ## List Automations ### Description Retrieve all automations for a publication. ### Method GET ### Endpoint `/automations` (This is an inferred endpoint based on the SDK method `client.automations.index`) ### Parameters #### Path Parameters - **publication_id** (string) - Required - The ID of the publication. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **automations** (array) - An array of automation objects. #### Response Example ```json [ { "automation_id": "aut_00000000-0000-0000-0000-000000000000", "name": "Welcome Series" } ] ``` ``` -------------------------------- ### Retrieve a single email blast Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Use this method to get a specific email blast for a given publication. Requires publication ID and email blast ID. ```typescript await client.emailBlasts.show("pub_00000000-0000-0000-0000-000000000000", "blast_00000000-0000-0000-0000-000000000000"); ``` -------------------------------- ### Advanced Configuration: Request Timeouts and Retries Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Configure timeouts and retry behavior per request. ```APIDOC ```typescript const response = await client.subscriptions.create("pub_xxx", { email: "test@example.com" }, { timeoutInSeconds: 30, maxRetries: 3 }); ``` ``` -------------------------------- ### Create Bulk Subscriptions Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Create multiple subscriptions simultaneously for a publication. Each subscription can have custom fields defined. ```typescript const result = await client.bulkSubscriptions.create("pub_00000000-0000-0000-0000-000000000000", { subscriptions: [ { email: "bruce.wayne@wayneenterprise.com", reactivate_existing: false, send_welcome_email: false, custom_fields: [{ name: "Favorite Color", value: "Red" }] }, { email: "lucius.fox@wayneenterprise.com", reactivate_existing: false, send_welcome_email: false, custom_fields: [{ name: "Favorite Color", value: "Blue" }] } ] }); ``` -------------------------------- ### GET /bulkSubscriptionUpdates/{id} Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Retrieves a single Subscription Update object for a specific publication using its ID. This allows for detailed inspection of a particular subscription update. ```APIDOC ## GET /bulkSubscriptionUpdates/{id} ### Description Returns a single Subscription Update object for a publication. ### Method GET ### Endpoint `/bulkSubscriptionUpdates/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the Subscription Update object. #### Query Parameters None #### Request Body - **publicationId** (Beehiiv.PublicationId) - Required - The prefixed ID of the publication object. - **requestOptions** (BulkSubscriptionUpdatesClient.RequestOptions) - Optional - Options for the request. ### Request Example ```typescript await client.bulkSubscriptionUpdates.show("publicationId", "id"); ``` ### Response #### Success Response (200) - **BulkSubscriptionUpdatesGetResponse** (object) - The response object containing the subscription update details. #### Response Example ```json { "id": "upd_1234", "subscription_id": "sub_1234", "status": "updated", "updated_at": "2023-01-01T12:00:00Z" } ``` ``` -------------------------------- ### Access Raw Response Data Source: https://github.com/beehiiv/typescript-sdk/blob/master/README.md Use `.withRawResponse()` to get access to the raw HTTP response, including headers, along with the data. This is useful for inspecting response metadata. ```typescript const { data, rawResponse } = await client.automationJourneys.create(...).withRawResponse(); console.log(data); console.log(rawResponse.headers['X-My-Header']); ``` -------------------------------- ### List Post Templates Source: https://context7.com/beehiiv/typescript-sdk/llms.txt Retrieve available post templates for a publication. ```APIDOC ## List Post Templates ### Description Retrieve available post templates for a publication. ### Method GET ### Endpoint `/post-templates` (This is an inferred endpoint based on the SDK method `client.postTemplates.index`) ### Parameters #### Path Parameters - **publication_id** (string) - Required - The ID of the publication. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **templates** (array) - An array of post template objects. #### Response Example ```json [ { "template_id": "tmpl_00000000-0000-0000-0000-000000000000", "name": "Default Template" } ] ``` ``` -------------------------------- ### Retrieve Post Templates Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Fetches a list of available post templates for a given publication. Requires the publication ID. ```typescript await client.postTemplates.index("pub_00000000-0000-0000-0000-000000000000"); ``` -------------------------------- ### Retrieve a Single Post by ID with TypeScript Source: https://github.com/beehiiv/typescript-sdk/blob/master/reference.md Get the details of a specific post using its `publicationId` and `postId`. This is useful for displaying a single post's content or metadata. Both IDs are required. ```typescript await client.posts.show("pub_00000000-0000-0000-0000-000000000000", "post_00000000-0000-0000-0000-000000000000"); ```