### Install Klaviyo Python SDK Source: https://context7.com/klaviyo/klaviyo-api-python/llms.txt Install the SDK using pip. This is the first step to using the library. ```bash pip install klaviyo-api ``` -------------------------------- ### Make Example API Request Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Make a basic API request to get a list of metrics using the instantiated Klaviyo client. ```python klaviyo.Metrics.get_metrics() ``` -------------------------------- ### Get Lists Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves all lists associated with the account. ```APIDOC ## GET /api/lists ### Description Retrieves all lists associated with the account. ### Method GET ### Endpoint /api/lists ### Parameters #### Query Parameters - **fields_flow** (List[str]) - Optional - Specifies which fields to return for the flow object. - **fields_list** (List[str]) - Optional - Specifies which fields to return for the list object. - **fields_tag** (List[str]) - Optional - Specifies which fields to return for the tag object. - **filter** (str) - Optional - Filters the results based on a query string. - **include** (List[str]) - Optional - Specifies related objects to include in the response. - **page_cursor** (str) - Optional - Used for pagination, indicating the starting point of the next page. - **sort** (str) - Optional - Specifies the order in which lists are returned. ``` -------------------------------- ### Get Webhook Topics Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of all available webhook topics. ```python klaviyo.Webhooks.get_webhook_topics() ``` -------------------------------- ### Get Coupons Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of coupons. Supports filtering by coupon fields and pagination. ```python klaviyo.Coupons.get_coupons(fields_coupon=fields_coupon, page_cursor=page_cursor) ``` -------------------------------- ### Get All Klaviyo Tracking Settings Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of all tracking settings in Klaviyo. Supports pagination and specifying fields. ```python klaviyo.Tracking_Settings.get_tracking_settings(fields_tracking_setting=fields_tracking_setting, page_cursor=page_cursor, page_size=page_size) ``` -------------------------------- ### Get Bulk Create Categories Jobs Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of bulk create categories jobs. ```APIDOC ## GET /api/bulk-create-catalog-categories-jobs ### Description Retrieves a list of bulk create categories jobs. ### Method GET ### Endpoint /api/bulk-create-catalog-categories-jobs ### Parameters #### Query Parameters - **fields_catalog_category_bulk_create_job** (List[str]) - Optional - Specifies which fields to include for the jobs. - **filter** (str) - Optional - Filters the results based on a given condition. - **page_cursor** (str) - Optional - Used for pagination to retrieve the next page of results. ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Initialize Klaviyo API Client Source: https://context7.com/klaviyo/klaviyo-api-python/llms.txt Instantiate the KlaviyoAPI client with your API key. Optional parameters for retry configuration are available. ```python from klaviyo_api import KlaviyoAPI klaviyo = KlaviyoAPI( "YOUR_API_KEY_HERE", max_delay=60, # Maximum delay in seconds for retries max_retries=3, # Number of retry attempts test_host=None # Optional test host override ) ``` -------------------------------- ### Get List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a specific list by its ID. ```APIDOC ## GET /api/lists/{id} ### Description Retrieves a specific list by its ID. ### Method GET ### Endpoint /api/lists/{id} ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the list. #### Query Parameters - **additional_fields_list** (List[str]) - Optional - Specifies additional fields to return for the list object. - **fields_flow** (List[str]) - Optional - Specifies which fields to return for the flow object. - **fields_list** (List[str]) - Optional - Specifies which fields to return for the list object. - **fields_tag** (List[str]) - Optional - Specifies which fields to return for the tag object. - **include** (List[str]) - Optional - Specifies related objects to include in the response. ``` -------------------------------- ### Instantiate Klaviyo Client Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Instantiate the KlaviyoAPI client with your API key. Advanced settings like max_delay and max_retries can be configured. ```python from klaviyo_api import KlaviyoAPI klaviyo = KlaviyoAPI("YOUR_API_KEY_HERE", max_delay=60, max_retries=3, test_host=None) ``` -------------------------------- ### Get Coupon Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a specific coupon by its ID. ```APIDOC ## GET /api/coupons/{id}/ ### Description Retrieves a specific coupon by its ID. ### Method GET ### Endpoint /api/coupons/{id}/ ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the coupon to retrieve. #### Query Parameters - **fields[coupon]** (list[string]) - Optional - Specifies which fields to include for the coupon. ### Response #### Success Response (200) - **data** (object) - The requested coupon. - **type** (string) - Always "coupon". - **id** (string) - The ID of the coupon. - **attributes** (object) - The attributes of the coupon. - **name** (string) - The name of the coupon. - **discount_type** (string) - The type of discount. - **discount_value** (number) - The value of the discount. - **coupon_code_prefix** (string) - The prefix for generated coupon codes. - **coupon_code_count** (integer) - The number of coupon codes generated. - **expiration_date** (string) - ISO 8601 timestamp of expiration. - **status** (string) - The status of the coupon. - **created_at** (string) - ISO 8601 timestamp of creation. - **updated_at** (string) - ISO 8601 timestamp of last update. - **links** (object) - Links related to the coupon. - **self** (string) - Link to the coupon resource. #### Response Example ```json { "data": { "type": "coupon", "id": "aBcDeFgHiJkLmNoPqRsT", "attributes": { "name": "Summer Sale 2023", "discount_type": "percentage", "discount_value": 15, "coupon_code_prefix": null, "coupon_code_count": 100, "expiration_date": "2023-08-31T23:59:59Z", "status": "active", "created_at": "2023-07-01T10:00:00Z", "updated_at": "2023-07-01T10:00:00Z" }, "links": { "self": "/v3/coupons/aBcDeFgHiJkLmNoPqRsT" } } } ``` ``` -------------------------------- ### Create Back In Stock Subscription Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a back-in-stock subscription for a product. Requires a dictionary containing the subscription details. ```python klaviyo.Catalogs.create_back_in_stock_subscription(body) ``` -------------------------------- ### Get Campaign Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a specific campaign by its ID. ```APIDOC ## GET /api/campaigns/{id} ### Description Retrieves a specific campaign by its ID. ### Method GET ### Endpoint /api/campaigns/{id} ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the campaign to retrieve. #### Query Parameters - **fields_campaign_message** (List[str]) - Optional - Specifies which campaign message fields to include in the response. - **fields_campaign** (List[str]) - Optional - Specifies which campaign fields to include in the response. - **fields_tag** (List[str]) - Optional - Specifies which tag fields to include in the response. - **include** (List[str]) - Optional - Specifies related resources to include in the response (e.g., "campaign_message", "tags"). ### Response #### Success Response (200) - **data** (object) - The campaign object with requested fields and included resources. #### Response Example ```json { "data": { "type": "campaign", "id": "example_campaign_id", "attributes": { "name": "Example Campaign", "subject": "Check this out!" }, "relationships": { "campaign_message": { "data": { "type": "campaign-message", "id": "example_message_id" } } } } } ``` ``` -------------------------------- ### Create Back-in-Stock Subscription Source: https://context7.com/klaviyo/klaviyo-api-python/llms.txt Set up a back-in-stock subscription for a specific catalog variant. Requires a profile with contact information and the variant's ID. ```python # Create back-in-stock subscription bis_body = { "data": { "type": "back-in-stock-subscription", "attributes": { "channels": ["EMAIL"], "profile": { "data": { "type": "profile", "attributes": { "email": "customer@example.com" } } } }, "relationships": { "variant": { "data": { "type": "catalog-variant", "id": "$custom:::$default:::VARIANT_ID" } } } } } klaviyo.Catalogs.create_back_in_stock_subscription(bis_body) ``` -------------------------------- ### Create List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a new list in Klaviyo. ```APIDOC ## POST /api/lists ### Description Creates a new list in Klaviyo. ### Method POST ### Endpoint /api/lists ### Parameters #### Request Body - **body** (dict) - Required - The request body containing list details. ``` -------------------------------- ### Get Campaigns Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of campaigns, optionally filtered. ```APIDOC ## GET /api/campaigns/ ### Description Retrieves a list of campaigns, optionally filtered. ### Method GET ### Endpoint /api/campaigns/ ### Parameters #### Query Parameters - **filter** (str) - Required - A filter string to narrow down the results (e.g., "name:"My Campaign""). - **fields_campaign_message** (List[str]) - Optional - Specifies which campaign message fields to include. - **fields_campaign** (List[str]) - Optional - Specifies which campaign fields to include. - **fields_tag** (List[str]) - Optional - Specifies which tag fields to include. - **include** (List[str]) - Optional - Specifies related resources to include. - **page_cursor** (str) - Optional - For pagination, the cursor for the next page of results. - **sort** (str) - Optional - Specifies the order of the results (e.g., "created:asc"). ### Response #### Success Response (200) - **data** (array) - A list of campaign objects. - **links** (object) - Pagination links. #### Response Example ```json { "data": [ { "type": "campaign", "id": "example_campaign_id_1", "attributes": { "name": "Campaign One" } }, { "type": "campaign", "id": "example_campaign_id_2", "attributes": { "name": "Campaign Two" } } ], "links": { "next": "/api/campaigns?page[cursor]=example_cursor" } } ``` ``` -------------------------------- ### Create Data Source Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a new data source. Requires a dictionary containing the data source configuration. ```python klaviyo.Custom_Objects.create_data_source(body) ``` -------------------------------- ### Get Segments for Profile Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves segment objects that a profile belongs to. ```APIDOC ## GET /api/profiles/{profile_id}/segments ### Description Retrieves segment objects for a given profile, with options to specify fields. ### Method GET ### Endpoint /api/profiles/{profile_id}/segments ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the profile. #### Query Parameters - **fields_segment** (List[str]) - Optional - Specifies which fields to include for the segment object. ### Request Example ```python klaviyo.Profiles.get_segments_for_profile(id='profile_id', fields_segment=['name']) ``` ### Response #### Success Response (200) - **data** (list) - A list of segment objects. #### Response Example ```json { "data": [ { "type": "segment", "id": "segment_id", "attributes": { "name": "Segment Name" } } ] } ``` ``` -------------------------------- ### Create and Send an Email Campaign Source: https://context7.com/klaviyo/klaviyo-api-python/llms.txt Creates a new email campaign with specified audience, send time, and message content, then sends it immediately. Ensure list IDs and campaign details are correctly configured. ```python # Create a new email campaign campaign_body = { "data": { "type": "campaign", "attributes": { "name": "Summer Sale Announcement", "audiences": { "included": ["LIST_ID_1"], "excluded": ["LIST_ID_2"] }, "send_strategy": { "method": "static", "options_static": { "datetime": "2023-07-01T10:00:00Z" } } }, "relationships": { "campaign-messages": { "data": [ { "type": "campaign-message", "attributes": { "channel": "email", "label": "Main Message" } } ] } } } } campaign = klaviyo.Campaigns.create_campaign(campaign_body) # Send the campaign immediately send_body = { "data": { "type": "campaign-send-job", "id": campaign.data.id } } klaviyo.Campaigns.send_campaign(send_body) ``` -------------------------------- ### Get All Accounts Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of all accounts. Accepts optional `fields_account` to specify which fields to return for each account. ```python ## Keyword Arguments # fields_account | List[str] klaviyo.Accounts.get_accounts(fields_account=fields_account) ``` -------------------------------- ### Get Tags for List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves tags associated with a specific list. ```APIDOC ## GET /api/lists/{id}/tags ### Description Retrieves tags associated with a specific list. ### Method GET ### Endpoint /api/lists/{id}/tags ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the list. #### Query Parameters - **fields_tag** (List[str]) - Optional - Specifies which fields to return for the tag object. ``` -------------------------------- ### Create Campaign Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a new campaign in Klaviyo. ```APIDOC ## POST /api/campaigns/ ### Description Creates a new campaign in Klaviyo. ### Method POST ### Endpoint /api/campaigns/ ### Parameters #### Request Body - **body** (dict) - Required - The campaign details, including name, subject, content, etc. ### Response #### Success Response (201) - **data** (object) - The newly created campaign object. #### Response Example ```json { "data": { "type": "campaign", "id": "example_campaign_id", "attributes": { "name": "New Campaign Name", "subject": "Exciting Offer!" } } } ``` ``` -------------------------------- ### Bulk Create Catalog Items Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Initiates a job to create multiple catalog items in bulk. Requires a dictionary containing the item data. ```python klaviyo.Catalogs.bulk_create_catalog_items(body) ``` ```python klaviyo.Catalogs.spawn_create_items_job(body) ``` ```python klaviyo.Catalogs.create_catalog_item_bulk_create_job(body) ``` -------------------------------- ### Get Profiles for List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves profiles associated with a specific list. ```APIDOC ## GET /api/lists/{id}/profiles ### Description Retrieves profiles associated with a specific list. ### Method GET ### Endpoint /api/lists/{id}/profiles ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the list. #### Query Parameters - **additional_fields_profile** (List[str]) - Optional - Specifies additional fields to return for the profile object. - **fields_profile** (List[str]) - Optional - Specifies which fields to return for the profile object. - **filter** (str) - Optional - Filters the results based on a query string. - **page_cursor** (str) - Optional - Used for pagination, indicating the starting point of the next page. - **page_size** (int) - Optional - The number of results to return per page. - **sort** (str) - Optional - Specifies the order in which profiles are returned. ``` -------------------------------- ### Exception Handling Example Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Demonstrates how to catch and handle exceptions that may occur during API calls, accessing status, reason, body, and headers of the error. ```python try: YOUR_CALL except Exception as e: print(e.status) print(e.reason) print(e.body) print(e.headers) ``` -------------------------------- ### Get Coupon Code Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a specific coupon code by its ID. ```APIDOC ## GET /api/coupon-codes/{id}/ ### Description Retrieves a specific coupon code by its ID. ### Method GET ### Endpoint /api/coupon-codes/{id}/ ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the coupon code to retrieve. #### Query Parameters - **fields[coupon_code]** (list[string]) - Optional - Specifies which fields to include for the coupon code. - **fields[coupon]** (list[string]) - Optional - Specifies which fields to include for the associated coupon. - **include** (list[string]) - Optional - Specifies related resources to include in the response. ### Response #### Success Response (200) - **data** (object) - The requested coupon code. - **type** (string) - Always "coupon-code". - **id** (string) - The ID of the coupon code. - **attributes** (object) - The attributes of the coupon code. - **coupon_code** (string) - The coupon code string. - **created_at** (string) - ISO 8601 timestamp of creation. - **updated_at** (string) - ISO 8601 timestamp of last update. - **links** (object) - Links related to the coupon code. - **self** (string) - Link to the coupon code resource. #### Response Example ```json { "data": { "type": "coupon-code", "id": "aBcDeFgHiJkLmNoPqRsT", "attributes": { "coupon_code": "UNIQUE_CODE_123", "created_at": "2023-07-01T10:00:00Z", "updated_at": "2023-07-01T10:00:00Z" }, "links": { "self": "/v3/coupon-codes/aBcDeFgHiJkLmNoPqRsT" } } } ``` ``` -------------------------------- ### Create List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a new list in Klaviyo. Requires a dictionary containing the list details in the 'body' argument. ```python klaviyo.Lists.create_list(body) ``` -------------------------------- ### Get Campaign Message Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a specific campaign message by its ID. ```APIDOC ## GET /api/campaign-messages/{id} ### Description Retrieves a specific campaign message by its ID. ### Method GET ### Endpoint /api/campaign-messages/{id} ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the campaign message to retrieve. #### Query Parameters - **fields_campaign_message** (List[str]) - Optional - Specifies which campaign message fields to include. - **fields_campaign** (List[str]) - Optional - Specifies which campaign fields to include. - **fields_image** (List[str]) - Optional - Specifies which image fields to include. - **fields_template** (List[str]) - Optional - Specifies which template fields to include. - **include** (List[str]) - Optional - Specifies related resources to include (e.g., "campaign", "image", "template"). ### Response #### Success Response (200) - **data** (object) - The campaign message object with requested fields and included resources. #### Response Example ```json { "data": { "type": "campaign-message", "id": "example_message_id", "attributes": { "html": "
Hello!
" }, "relationships": { "campaign": { "data": { "type": "campaign", "id": "example_campaign_id" } } } } } ``` ``` -------------------------------- ### Get Segment IDs for Profile Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the segment IDs that a profile belongs to. ```APIDOC ## GET /api/profiles/{profile_id}/segments ### Description Retrieves the IDs of all segments a given profile is a member of. ### Method GET ### Endpoint /api/profiles/{profile_id}/segments ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the profile. ### Request Example ```python klaviyo.Profiles.get_segment_ids_for_profile(id='profile_id') ``` ### Response #### Success Response (200) - **data** (list) - A list of segment IDs. #### Response Example ```json { "data": [ "segment_id_1", "segment_id_2" ] } ``` ``` -------------------------------- ### Create Profile Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Use this method to create a new profile. It accepts a profile dictionary and an optional list of additional fields. ```python klaviyo.Profiles.create_profile(body, additional_fields_profile=additional_fields_profile) ``` -------------------------------- ### Enable Dictionary Responses (Client-wide) Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Initialize a new KlaviyoAPI client with the options argument set to USE_DICTIONARY_FOR_RESPONSE_DATA: True to ensure all subsequent API calls return dictionaries. ```python # 2: Passing options to API Client dictionary_client = KlaviyoAPI( api_key, max_delay=0, max_retries=0, options={USE_DICTIONARY_FOR_RESPONSE_DATA : True} ) profiles_ = dictionary_client.Profiles.get_profiles() profile_0_id = profiles_["data"][0]['id'] profile_0 = dictionary_client.Profiles.get_profile(id=profile_0_id) profile_0_email = profile_0["data"]['attributes']['email'] ``` -------------------------------- ### Get Conversation for Profile Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the conversation associated with a specific profile ID. ```APIDOC ## GET /api/profiles/{id}/conversations/ ### Description Retrieves the conversation associated with a specific profile ID. ### Method GET ### Endpoint /api/profiles/{id}/conversations/ ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the profile. ``` -------------------------------- ### Create Static Schedule Options Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Instantiate StaticScheduleOptions with a specific datetime. Ensure the datetime string is correctly formatted. ```python schedule_options = StaticScheduleOptions(datetime_=datetime.datetime.strptime("2024-05-19T00:00:00+00:00", "%Y-%m-%dT%H:%M:%S%z") print(schedule_options.datetime_) ``` -------------------------------- ### Get Metric for Metric Property Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the metric associated with a metric property. ```APIDOC ## GET /api/metric-properties/{id}/metric/ ### Description Retrieves the metric associated with a metric property. ### Method GET ### Endpoint /api/metric-properties/{id}/metric/ ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the metric property. #### Query Parameters - **fields_metric** (List[str]) - Optional - Specifies which fields to include for the metric. ``` -------------------------------- ### Get Metric for Mapped Metric Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the metric associated with a mapped metric. ```APIDOC ## GET /api/mapped-metrics/{id}/metric/ ### Description Retrieves the metric associated with a mapped metric. ### Method GET ### Endpoint /api/mapped-metrics/{id}/metric/ ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the mapped metric. #### Query Parameters - **fields_metric** (List[str]) - Optional - Specifies which fields to include for the metric. ``` -------------------------------- ### Create Campaign Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Use this method to create a new campaign. Requires a dictionary containing campaign details in the body. ```python klaviyo.Campaigns.create_campaign(body) ``` -------------------------------- ### Create Profile Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a new profile. Allows specifying additional fields for the profile. ```APIDOC ## POST /api/profiles ### Description Creates a new profile. ### Method POST ### Endpoint /api/profiles ### Request Body - **body** (dict) - Required - The request body containing profile data. - **additional_fields_profile** (List[str]) - Optional - A list of additional fields to include for the profile. ### Request Example ```json { "example": "request body" } ``` ### Response #### Success Response (200) - **example** (string) - Description of the success response. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Get Flows Triggered by List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves flows that are triggered by a specific list. ```APIDOC ## GET /api/lists/{id}/flows ### Description Retrieves flows that are triggered by a specific list. ### Method GET ### Endpoint /api/lists/{id}/flows ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the list. #### Query Parameters - **fields_flow** (List[str]) - Optional - Specifies which fields to return for the flow object. ``` -------------------------------- ### Get Campaign Send Job Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the status of a campaign send job. ```APIDOC ## GET /api/campaign-send-jobs/{id} ### Description Retrieves the status of a campaign send job. ### Method GET ### Endpoint /api/campaign-send-jobs/{id} ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the send job. #### Query Parameters - **fields_campaign_send_job** (List[str]) - Optional - Specifies which send job fields to include. ### Response #### Success Response (200) - **data** (object) - The campaign send job object. #### Response Example ```json { "data": { "type": "campaign-send-job", "id": "example_send_job_id", "attributes": { "status": "sent" } } } ``` ``` -------------------------------- ### Create Catalog Item Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a new catalog item. Requires a dictionary containing the item details. ```python klaviyo.Catalogs.create_catalog_item(body) ``` -------------------------------- ### Get Campaign Recipient Estimation Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves an estimation of recipients for a campaign send. ```APIDOC ## GET /api/campaigns/{id}/recipient-estimation ### Description Retrieves an estimation of recipients for a campaign send. ### Method GET ### Endpoint /api/campaigns/{id}/recipient-estimation ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the campaign. #### Query Parameters - **fields_campaign_recipient_estimation** (List[str]) - Optional - Specifies which recipient estimation fields to include. ### Response #### Success Response (200) - **data** (object) - The recipient estimation details for the campaign. #### Response Example ```json { "data": { "type": "campaign-recipient-estimation", "attributes": { "estimated_recipient_count": 10000 } } } ``` ``` -------------------------------- ### Pagination with page[size] Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Use cursor-based pagination to retrieve a specified number of profile records. ```APIDOC ## GET /api/profiles/ ### Description Retrieves a paginated list of profile records using cursor-based pagination. ### Method GET ### Endpoint /api/profiles/ ### Query Parameters - **page[cursor]** (string) - Required - The cursor for the next page of results. - **page[size]** (integer) - Optional - The number of profiles to return per page. Defaults to 20. ### Request Example ```python klaviyo.Profiles.get_profiles( page_cursor="https://a.klaviyo.com/api/profiles/?page%5Bcursor%5D=bmV4dDo6aWQ6OjAxRjNaWk5ITlRYMUtFVEhQMzJTUzRBN0ZY", page_size=20 ) ``` ### Response #### Success Response (200) Returns a list of profile objects and pagination information. #### Response Example (Response structure depends on the API response, typically includes profile data and next/prev cursors) ``` -------------------------------- ### Create Catalog Item Source: https://context7.com/klaviyo/klaviyo-api-python/llms.txt Use this to create a new item in your product catalog. Ensure all required attributes like external_id, title, and price are provided. ```python # Create a catalog item item_body = { "data": { "type": "catalog-item", "attributes": { "external_id": "SKU-12345", "title": "Classic T-Shirt", "description": "Premium cotton t-shirt", "url": "https://example.com/products/classic-tshirt", "image_full_url": "https://example.com/images/tshirt.jpg", "price": 29.99, "custom_metadata": { "color": "blue", "size": "medium" } } } } klaviyo.Catalogs.create_catalog_item(item_body) ``` -------------------------------- ### Get Webhook Topic Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves information about a specific webhook topic using its ID. ```python klaviyo.Webhooks.get_webhook_topic(id) ``` -------------------------------- ### Bulk Create Catalog Items Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Initiates a job to create multiple catalog items in bulk. ```APIDOC ## POST /api/catalog-item-bulk-create-job/ ### Description Initiates a job to create multiple catalog items in bulk. ### Method POST ### Endpoint /api/catalog-item-bulk-create-job/ ### Parameters #### Request Body - **body** (dict) - Required - A dictionary containing the catalog items to create. ### Request Example ```json { "data": { "type": "catalog-item-bulk-create-job", "attributes": { "items": [ { "name": "Item 1", "description": "Description for Item 1", "url": "http://example.com/item1", "image_url": "http://example.com/item1.jpg", "price": 1000, "currency": "USD", "external_id": "ext_item_1", "categories": ["category_id_1"] } ] } } } ``` ### Response #### Success Response (2022-05-15) - **data** (object) - Contains information about the initiated bulk create job. #### Response Example ```json { "data": { "type": "catalog-item-bulk-create-job", "attributes": { "status": "queued", "created_at": "2026-04-15T10:00:00Z", "total_items": 1 }, "id": "job_id" } } ``` ``` -------------------------------- ### Get Push Tokens for Profile Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves all push tokens associated with a specific profile. ```APIDOC ## GET /api/profiles/{profile_id}/push-tokens ### Description Retrieves all push tokens for a given profile, with options to specify fields. ### Method GET ### Endpoint /api/profiles/{profile_id}/push-tokens ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the profile. #### Query Parameters - **fields_push_token** (List[str]) - Optional - Specifies which fields to include for the push token object. ### Request Example ```python klaviyo.Profiles.get_push_tokens_for_profile(id='profile_id', fields_push_token=['token']) ``` ### Response #### Success Response (200) - **data** (list) - A list of push token objects. #### Response Example ```json { "data": [ { "type": "push_token", "id": "push_token_id", "attributes": { "token": "device_token" } } ] } ``` ``` -------------------------------- ### Bulk Import Profiles Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Initiates a bulk import job for profiles. Requires a request body containing the profile data. ```python klaviyo.Profiles.bulk_import_profiles(body) ``` -------------------------------- ### Get Push Tokens Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of push tokens with filtering and inclusion options. ```APIDOC ## GET /api/push-tokens ### Description Retrieves a list of push tokens, with options to filter and include related profile data. ### Method GET ### Endpoint /api/push-tokens ### Parameters #### Query Parameters - **fields_profile** (List[str]) - Optional - Specifies which fields to include for the related profile object. - **fields_push_token** (List[str]) - Optional - Specifies which fields to include for the push token object. - **filter** (str) - Optional - Filters the results based on a given condition. - **include** (List[str]) - Optional - Specifies related resources to include in the response. - **page_cursor** (str) - Optional - Used for pagination to get the next page of results. - **page_size** (int) - Optional - The number of results to return per page. ### Request Example ```python klaviyo.Profiles.get_push_tokens(fields_profile=['email'], page_size=10) ``` ### Response #### Success Response (200) - **data** (list) - A list of push token objects. - **links** (dict) - Pagination links. #### Response Example ```json { "data": [ { "type": "push_token", "id": "push_token_id", "attributes": { "token": "device_token" }, "relationships": { "profile": { "data": { "type": "profile", "id": "profile_id" } } } } ], "links": { "self": "...", "next": "..." } } ``` ``` -------------------------------- ### Get List IDs for Profile Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the IDs of lists associated with a specific profile. ```APIDOC ## GET /api/profiles/{id}/relationships/lists/ ### Description Retrieves the IDs of lists associated with a specific profile. ### Method GET ### Endpoint /api/profiles/{id}/relationships/lists/ ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the profile. ``` -------------------------------- ### Get All Live Flows with Tags and Actions Source: https://context7.com/klaviyo/klaviyo-api-python/llms.txt Retrieves all live marketing flows, including their associated tags and flow actions. Useful for auditing or understanding active automation workflows. ```python # Get all flows with tags flows = klaviyo.Flows.get_flows( fields_flow=['name', 'status', 'trigger_type'], include=['tags', 'flow-actions'], filter='equals(status,"live")' ) ``` -------------------------------- ### Bulk Create Catalog Variants Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Initiates a job to create multiple catalog variants in bulk. Requires a dictionary containing the variant data. ```python klaviyo.Catalogs.bulk_create_catalog_variants(body) ``` ```python klaviyo.Catalogs.spawn_create_variants_job(body) ``` ```python klaviyo.Catalogs.create_catalog_variant_bulk_create_job(body) ``` -------------------------------- ### Get Metrics Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of metrics. Supports filtering, field selection, and pagination. ```python klaviyo.Metrics.get_metrics(fields_flow=fields_flow, fields_metric=fields_metric, filter=filter, include=include, page_cursor=page_cursor) ``` -------------------------------- ### Get Flows Triggered by Metric Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of flows that are triggered by a specific metric. ```APIDOC ## GET /api/metrics/{id}/flows/ ### Description Retrieves a list of flows that are triggered by a specific metric. ### Method GET ### Endpoint /api/metrics/{id}/flows/ ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the metric. #### Query Parameters - **fields_flow** (List[str]) - Optional - Specifies which fields to include for the flows. ``` -------------------------------- ### Create Webhook Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a new webhook. The request body should be provided as a dictionary. ```python klaviyo.Webhooks.create_webhook(body) ``` -------------------------------- ### Bulk Create Catalog Categories Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Initiates a job to create multiple catalog categories in bulk. Requires a dictionary containing the category data. ```python klaviyo.Catalogs.bulk_create_catalog_categories(body) ``` ```python klaviyo.Catalogs.spawn_create_categories_job(body) ``` ```python klaviyo.Catalogs.create_catalog_category_bulk_create_job(body) ``` -------------------------------- ### Get Tag IDs for List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the IDs of tags associated with a specific list. ```APIDOC ## GET /api/lists/{id}/relationships/tags ### Description Retrieves the IDs of tags associated with a specific list. ### Method GET ### Endpoint /api/lists/{id}/relationships/tags ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the list. ``` -------------------------------- ### Create Coupon Source: https://context7.com/klaviyo/klaviyo-api-python/llms.txt Create a new coupon with an external ID and description. This coupon can then be used to generate coupon codes. ```python # Create a coupon coupon_body = { "data": { "type": "coupon", "attributes": { "external_id": "SUMMER2023", "description": "Summer sale 20% off" } } } coupon = klaviyo.Coupons.create_coupon(coupon_body) ``` -------------------------------- ### Get Profile IDs for List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the IDs of profiles within a specific list. ```APIDOC ## GET /api/lists/{id}/relationships/profiles ### Description Retrieves the IDs of profiles within a specific list. ### Method GET ### Endpoint /api/lists/{id}/relationships/profiles ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the list. #### Query Parameters - **filter** (str) - Optional - Filters the results based on a query string. - **page_cursor** (str) - Optional - Used for pagination, indicating the starting point of the next page. - **page_size** (int) - Optional - The number of results to return per page. - **sort** (str) - Optional - Specifies the order in which profile IDs are returned. ``` -------------------------------- ### Get Tag IDs for Flow Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the IDs of tags associated with a specific flow. ```APIDOC ## GET /api/flow-relationships/tags/ids/ ### Description Retrieves the IDs of tags for a specific flow. ### Method GET ### Endpoint /api/flow-relationships/tags/ids/ ### Parameters #### Query Parameters - **id** (str) - Required - The ID of the flow. ``` -------------------------------- ### Create Data Source Record Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a single data source record. Requires a dictionary with the record's data. ```python klaviyo.Custom_Objects.create_data_source_record(body) ``` ```python klaviyo.Custom_Objects.create_data_source_record_create_job(body) ``` -------------------------------- ### Get Tag IDs for Flow Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves the IDs of tags associated with a specific flow. ```python ## Positional Arguments # id | str klaviyo.Flows.get_tag_ids_for_flow(id) ``` ```python klaviyo.Flows.get_flow_relationships_tags(id) ``` -------------------------------- ### Create Coupon Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Creates a new coupon. ```APIDOC ## POST /api/coupons/ ### Description Creates a new coupon. ### Method POST ### Endpoint /api/coupons/ ### Parameters #### Request Body - **data** (object) - Required - The coupon data to create. - **attributes** (object) - Required - The attributes of the coupon. - **name** (string) - Required - The name of the coupon. - **discount_type** (string) - Required - The type of discount (e.g., "percentage", "fixed_amount"). - **discount_value** (number) - Required - The value of the discount. - **coupon_code_prefix** (string) - Optional - A prefix for generated coupon codes. - **coupon_code_count** (integer) - Optional - The number of coupon codes to generate. - **expiration_date** (string) - Optional - ISO 8601 timestamp for expiration. - **status** (string) - Optional - The status of the coupon (e.g., "active", "inactive"). ### Request Example ```json { "data": { "attributes": { "name": "Summer Sale 2023", "discount_type": "percentage", "discount_value": 15, "coupon_code_count": 100, "expiration_date": "2023-08-31T23:59:59Z" } } } ``` ### Response #### Success Response (201) - **data** (object) - The created coupon. - **type** (string) - Always "coupon". - **id** (string) - The ID of the coupon. - **attributes** (object) - The attributes of the coupon. - **name** (string) - The name of the coupon. - **discount_type** (string) - The type of discount. - **discount_value** (number) - The value of the discount. - **coupon_code_prefix** (string) - The prefix for generated coupon codes. - **coupon_code_count** (integer) - The number of coupon codes generated. - **expiration_date** (string) - ISO 8601 timestamp of expiration. - **status** (string) - The status of the coupon. - **created_at** (string) - ISO 8601 timestamp of creation. - **updated_at** (string) - ISO 8601 timestamp of last update. - **links** (object) - Links related to the coupon. - **self** (string) - Link to the coupon resource. #### Response Example ```json { "data": { "type": "coupon", "id": "aBcDeFgHiJkLmNoPqRsT", "attributes": { "name": "Summer Sale 2023", "discount_type": "percentage", "discount_value": 15, "coupon_code_prefix": null, "coupon_code_count": 100, "expiration_date": "2023-08-31T23:59:59Z", "status": "active", "created_at": "2023-07-01T10:00:00Z", "updated_at": "2023-07-01T10:00:00Z" }, "links": { "self": "/v3/coupons/aBcDeFgHiJkLmNoPqRsT" } } } ``` ``` -------------------------------- ### Create or Update Profile Source: https://context7.com/klaviyo/klaviyo-api-python/llms.txt Create a new customer profile or update an existing one using the upsert pattern. Matching is done by email or external ID. ```python profile_data = { "data": { "type": "profile", "attributes": { "email": "sarah.mason@example.com", "first_name": "Sarah", "last_name": "Mason", "phone_number": "+15551234567", "properties": { "plan_type": "premium", "signup_date": "2023-01-15" } } } } response = klaviyo.Profiles.create_or_update_profile(profile_data) profile_id = response.data.id ``` -------------------------------- ### Get Bulk Create Catalog Items Jobs List Source: https://github.com/klaviyo/klaviyo-api-python/blob/main/README.md Retrieves a list of bulk create catalog items jobs. Supports filtering and pagination using cursor. ```python ## Keyword Arguments # fields_catalog_item_bulk_create_job | List[str] # filter | str # page_cursor | str klaviyo.Catalogs.get_bulk_create_catalog_items_jobs(fields_catalog_item_bulk_create_job=fields_catalog_item_bulk_create_job, filter=filter, page_cursor=page_cursor) ``` ```python klaviyo.Catalogs.get_create_items_jobs(fields_catalog_item_bulk_create_job=fields_catalog_item_bulk_create_job, filter=filter, page_cursor=page_cursor) ``` ```python klaviyo.Catalogs.get_catalog_item_bulk_create_jobs(fields_catalog_item_bulk_create_job=fields_catalog_item_bulk_create_job, filter=filter, page_cursor=page_cursor) ```