From 79a8c0aed3533ac07b113d3bdec47402840ff1db Mon Sep 17 00:00:00 2001 From: Oscar Perez Date: Thu, 26 Nov 2026 16:12:50 +0100 Subject: [PATCH] feat(mcp): expose idempotency_key on tools whose operation accepts Idempotency-Key The MCP generator dropped every optional header, so Idempotency-Key never reached the tool surface even though the API and SDK support it. An agent retrying after a timeout or a stopped chat could create a second copy. - Generator exposes Idempotency-Key as idempotency_key wherever the spec declares it (optional, or required where the spec requires it) with one agent-oriented description; other optional headers stay hidden. - Ad-create tools with an argument-derived key prefer the caller's key. - No key is sent when the caller passes none, so the API's content duplicate check still applies. - Tests drive every such tool through the MCP server and assert the header on the wire. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + scripts/generate_mcp_tools.py | 39 ++- src/late/mcp/generated_tools.py | 358 +++++++++++++++++---- tests/test_mcp_header_and_binary_params.py | 6 +- tests/test_mcp_idempotency_key.py | 215 +++++++++++++ 5 files changed, 553 insertions(+), 66 deletions(-) create mode 100644 tests/test_mcp_idempotency_key.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c55f109..8339acc8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- **`idempotency_key` on every MCP tool whose API operation accepts `Idempotency-Key` (63 tools, including `posts_create_post`).** The generator used to drop all optional headers, so an agent whose chat stopped or timed out mid-create had no safe way to retry: retrying could create a second post, message, transfer or campaign. The tool now takes the key and sends it as the header; a retry with the same key within 24 hours returns the original result, or 409 while it is still processing. It stays optional (required only where the spec requires it, as on the two tracking-site tools), and no key is invented when the caller passes none, because a key turns off the API's content duplicate check. The four ad-create tools that derive a key from their arguments use the caller's key when given and keep the derived one otherwise. Other optional headers (`x-request-id`, `If-Match`, connect tokens) stay hidden. - **`transport=` on `Late` / `Zernio`.** Pass an `httpx.BaseTransport` to reuse connections and TLS sessions across requests and clients. The caller owns it; the client never closes it. Without it nothing changes: a new connection per request. - **Tool call telemetry on the hosted MCP server.** One JSON log line per tool call (tool, latency, outcome, hashed caller), and with `SENTRY_DSN` one Sentry transaction per tool call. `/health` reports the deployed commit. - **Tool result size on the hosted MCP server.** `mcp_tool_call` gains `result_chars` and the Sentry transaction gains `mcp.tool.result.chars`, the characters of text a tool returned, so oversized results (one `ad_campaigns_get_ad_tree` call returned 284,873 characters) show per tool. Only the length is recorded, never the content. diff --git a/scripts/generate_mcp_tools.py b/scripts/generate_mcp_tools.py index ee37838b3..3f76bf355 100644 --- a/scripts/generate_mcp_tools.py +++ b/scripts/generate_mcp_tools.py @@ -90,6 +90,21 @@ "another on purpose, or if that 409 does not clear, change an argument such as the name." ) +IDEMPOTENCY_KEY_PARAM: dict[str, Any] = { + "name": "idempotency_key", + "type": "str | None", + "required": False, + "default": "None", + "description": ( + "Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. " + "Sent as the Idempotency-Key header. If this call times out or the chat stops, retry " + "with the same key: within 24 hours you get the original result instead of a second " + "copy, or 409 while the first call is still processing (retry shortly). Use a new key " + "for a new action." + ), + "sdk_name": "idempotency_key", +} + # Operations to SKIP (not useful for MCP) SKIP_OPERATIONS = { # OAuth redirect endpoints @@ -543,7 +558,22 @@ def add_param(entry: dict[str, Any]) -> None: if "name" not in param: continue - # Optional headers (Idempotency-Key, x-request-id, ...) stay off the tool + # Only the caller knows that a retry is the same logical action, so + # Idempotency-Key is exposed wherever the spec declares it. + if param.get("in") == "header" and param["name"].lower() == "idempotency-key": + if param.get("required", False): + add_param({ + **IDEMPOTENCY_KEY_PARAM, + "type": "str", + "required": True, + "default": '""', + "description": IDEMPOTENCY_KEY_PARAM["description"].replace("Optional key", "Key", 1), + }) + else: + add_param(IDEMPOTENCY_KEY_PARAM) + continue + + # Other optional headers (x-request-id, If-Match, ...) stay off the tool # surface; required ones are SDK positional args, so the tool must pass them. if param.get("in") == "header" and not param.get("required", False): continue @@ -740,9 +770,14 @@ def generate_tool_handler( sdk_args = [(p.get("sdk_name", p["name"]), p.get("sdk_value", p["name"])) for p in params] call_args = [f"{name}={value}" for name, value in sdk_args] if idempotency_scope: + # A caller key wins; without one, identical arguments derive the same key. + caller_key = any(name == "idempotency_key" for name, _ in sdk_args) + sdk_args = [(name, value) for name, value in sdk_args if name != "idempotency_key"] + call_args = [f"{name}={value}" for name, value in sdk_args] entries = ", ".join(f'"{name}": {value}' for name, value in sdk_args) lines.append(f" same_arguments: dict[str, Any] = {{{entries}}}") - call_args.append(f'idempotency_key=same_arguments_key("{idempotency_scope}", same_arguments)') + derived = f'same_arguments_key("{idempotency_scope}", same_arguments)' + call_args.append(f"idempotency_key={'idempotency_key or ' if caller_key else ''}{derived}") lines.append(" try:") lines.append(f" response = client.{resource}.{sdk_method}({', '.join(call_args)})") diff --git a/src/late/mcp/generated_tools.py b/src/late/mcp/generated_tools.py index 603487794..48eb14091 100644 --- a/src/late/mcp/generated_tools.py +++ b/src/late/mcp/generated_tools.py @@ -5311,7 +5311,9 @@ def ad_accounts_get_ad_account_live_entities( openWorldHint=True, ) ) - def ad_accounts_create_ad_account(body: dict[str, Any]) -> str: + def ad_accounts_create_ad_account( + body: dict[str, Any], idempotency_key: str | None = None + ) -> str: """Create ad account Creates a new Meta ad account in the user's own business portfolio, or a Google Ads client account under a manager (MCC) account the connection reaches. Billing must then be set up on the platform. @@ -5338,10 +5340,13 @@ def ad_accounts_create_ad_account(body: dict[str, Any]) -> str: Platforms: meta, google Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. body: Full request body as documented in the API reference. (required)""" client = _get_client() try: - response = client.ad_accounts.create_ad_account(body=body) + response = client.ad_accounts.create_ad_account( + idempotency_key=idempotency_key, body=body + ) return _format_response(response) except Exception as e: raise ToolError(f"Error: {e}") from e @@ -6011,7 +6016,7 @@ def ad_audiences_replace_ad_audience_companies( ) ) def ad_campaign_results_upload_campaign_results( - rows: list[dict[str, Any]] | None, + rows: list[dict[str, Any]] | None, idempotency_key: str | None = None ) -> str: """Upload your results per campaign @@ -6024,10 +6029,13 @@ def ad_campaign_results_upload_campaign_results( Platforms: meta, google, tiktok, linkedin, pinterest, x, reddit Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. rows: Each item is an object with keys: date (string, required) - The day, at most 400 days ago.; campaignId (string) - The platform campaign id.; utmCampaign (string) - The `utm_campaign` value on the campaign's ads.; campaignName (string) - The campaign's name, matched case-insensitively.; adAccountId (string) - Platform ad account id. Narrows matching to one ad account.; values (object, required) - Metric key (snake_case, up to 40 characters) to a non-negative number. 1 to 20 per row. (required)""" client = _get_client() try: - response = client.ad_campaign_results.upload_campaign_results(rows=rows) + response = client.ad_campaign_results.upload_campaign_results( + idempotency_key=idempotency_key, rows=rows + ) return _format_response(response) except Exception as e: raise ToolError(f"Error: {e}") from e @@ -7038,6 +7046,7 @@ def ad_campaigns_create_ad_campaign( "page_likes", "page_visits", ], + idempotency_key: str | None = None, is_skadnetwork_attribution: bool | None = None, promoted_object: dict[str, Any] | None = None, buying_type: Literal["AUCTION", "RESERVED"] | None = None, @@ -7099,6 +7108,7 @@ def ad_campaigns_create_ad_campaign( Platforms: meta, google, linkedin, tiktok, x, pinterest, openai, reddit Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: Zernio SocialAccount id (posting or ads variant); its platform decides where the campaign is created. (required) ad_account_id: Platform ad account id (Meta act_, Google customer id, LinkedIn account id, ...). (required) name: (required) @@ -7141,6 +7151,7 @@ def ad_campaigns_create_ad_campaign( client = _get_client() try: response = client.ad_campaigns.create_ad_campaign( + idempotency_key=idempotency_key, account_id=account_id, ad_account_id=ad_account_id, name=name, @@ -7758,6 +7769,7 @@ def ad_campaigns_bulk_update_ad_campaign_status( def ad_campaigns_duplicate_ad_campaign( campaign_id: str, platform: Literal["facebook", "instagram", "tiktok", "linkedin", "google"], + idempotency_key: str | None = None, deep_copy: bool = True, status_option: Literal["ACTIVE", "PAUSED", "INHERITED_FROM_SOURCE"] = "PAUSED", start_time: str | None = None, @@ -7792,6 +7804,7 @@ def ad_campaigns_duplicate_ad_campaign( Platforms: meta, tiktok, linkedin, google Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. campaign_id: Source platform campaign ID (required) platform: (required) deep_copy: Copy child ad sets + ads + creatives + targeting @@ -7815,6 +7828,7 @@ def ad_campaigns_duplicate_ad_campaign( client = _get_client() try: response = client.ad_campaigns.duplicate_ad_campaign( + idempotency_key=idempotency_key, campaign_id=campaign_id, platform=platform, deep_copy=deep_copy, @@ -8044,6 +8058,7 @@ def ad_campaigns_create_ad_set( ], campaign_id: str, name: str, + idempotency_key: str | None = None, status: Literal["ACTIVE", "PAUSED"] = "PAUSED", max_cpc: float | None = None, ad_account_id: str | None = None, @@ -8077,6 +8092,7 @@ def ad_campaigns_create_ad_set( Platforms: google, reddit Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: Zernio SocialAccount id owning the Google Ads or Reddit Ads connection. (required) platform: "google" and "reddit" are implemented; every other value returns 501. (required) campaign_id: Platform campaign ID the ad group is created under (numeric on Google). (required) @@ -8097,6 +8113,7 @@ def ad_campaigns_create_ad_set( client = _get_client() try: response = client.ad_campaigns.create_ad_set( + idempotency_key=idempotency_key, account_id=account_id, platform=platform, campaign_id=campaign_id, @@ -8130,6 +8147,7 @@ def ad_campaigns_create_ad_set( def ad_campaigns_duplicate_ad_set( ad_set_id: str, platform: Literal["facebook", "instagram", "tiktok"], + idempotency_key: str | None = None, campaign_id: str | None = None, deep_copy: bool = True, status_option: Literal["ACTIVE", "PAUSED", "INHERITED_FROM_SOURCE"] = "PAUSED", @@ -8159,6 +8177,7 @@ def ad_campaigns_duplicate_ad_set( Platforms: meta, tiktok Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. ad_set_id: Source platform ad set ID (required) platform: (required) campaign_id: Destination platform campaign id (defaults to the source's campaign) @@ -8179,6 +8198,7 @@ def ad_campaigns_duplicate_ad_set( client = _get_client() try: response = client.ad_campaigns.duplicate_ad_set( + idempotency_key=idempotency_key, ad_set_id=ad_set_id, platform=platform, campaign_id=campaign_id, @@ -8205,6 +8225,7 @@ def ad_campaigns_duplicate_ad_set( ) def ad_campaigns_duplicate_ad( ad_id: str, + idempotency_key: str | None = None, ad_set_id: str | None = None, status_option: Literal["ACTIVE", "PAUSED", "INHERITED_FROM_SOURCE"] = "PAUSED", rename_strategy: Literal["DEEP_RENAME", "ONLY_TOP_LEVEL_RENAME", "NO_RENAME"] @@ -8235,6 +8256,7 @@ def ad_campaigns_duplicate_ad( Platforms: meta Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. ad_id: Zernio ad ID or platform ad ID (required) ad_set_id: Destination platform ad set id (defaults to the source's ad set) status_option @@ -8250,6 +8272,7 @@ def ad_campaigns_duplicate_ad( client = _get_client() try: response = client.ad_campaigns.duplicate_ad( + idempotency_key=idempotency_key, ad_id=ad_id, ad_set_id=ad_set_id, status_option=status_option, @@ -9818,6 +9841,7 @@ def ad_campaigns_boost_post( "conversions", "app_promotion", ], + idempotency_key: str | None = None, creative_features: dict[str, Any] | None = None, post_id: str | None = None, platform_post_id: str | None = None, @@ -9928,6 +9952,7 @@ def ad_campaigns_boost_post( Platforms: meta, google, tiktok, linkedin, pinterest, x, reddit Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. creative_features post_id: The Zernio post id (24 hex characters) returned when the post was created through Zernio. Send this or platformPostId. A value that is not a Zernio id is boosted as the platform post id, the same as platformPostId; a Zernio id that matches no post is a 404 on postId. platform_post_id: Platform post ID (alternative to postId). @@ -10163,6 +10188,7 @@ def ad_campaigns_boost_post( client = _get_client() try: response = client.ad_campaigns.boost_post( + idempotency_key=idempotency_key, creative_features=creative_features, post_id=post_id, platform_post_id=platform_post_id, @@ -10542,6 +10568,7 @@ def ad_campaigns_replace_google_listing_group_filters( def ad_campaigns_create_standalone_ad( account_id: str, ad_account_id: str, + idempotency_key: str | None = None, name: str | None = None, campaign_name: str | None = None, ad_set_name: str | None = None, @@ -10872,6 +10899,7 @@ def ad_campaigns_create_standalone_ad( Safe to retry: an identical call within 24 hours returns the first result instead of creating a second one, and answers 409 while the first is still running. To create another on purpose, or if that 409 does not clear, change an argument such as the name. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: (required) ad_account_id: (required) name: Omitted, the ad is named `Ad ` (UTC) and the response reports it in `appliedDefaults.name`. @@ -11673,7 +11701,8 @@ def ad_campaigns_create_standalone_ad( is_skadnetwork_attribution=is_skadnetwork_attribution, campaign_attribution=campaign_attribution, promoted_object=promoted_object, - idempotency_key=same_arguments_key( + idempotency_key=idempotency_key + or same_arguments_key( "ad_campaigns_create_standalone_ad", same_arguments ), ) @@ -16490,7 +16519,9 @@ def automations_list_automations( openWorldHint=True, ) ) - def automations_create_automation(body: dict[str, Any]) -> str: + def automations_create_automation( + body: dict[str, Any], idempotency_key: str | None = None + ) -> str: """Create an automation Creates an automation. Its shape picks the kind: @@ -16502,10 +16533,13 @@ def automations_create_automation(body: dict[str, Any]) -> str: Everything an automation cannot hold is refused at once: the 400 lists every problem with its JSON path in `details.problems`. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. body: Full request body as documented in the API reference. (required)""" client = _get_client() try: - response = client.automations.create_automation(body=body) + response = client.automations.create_automation( + idempotency_key=idempotency_key, body=body + ) return _format_response(response) except Exception as e: raise ToolError(f"Error: {e}") from e @@ -16837,6 +16871,7 @@ def automations_list_automation_templates(scope: Literal["team"] = "team") -> st ) def automations_create_automation_template( name: str, + idempotency_key: str | None = None, description: str = "", from_: dict[str, Any] | None = None, automations: list[dict[str, Any]] | None = None, @@ -16852,6 +16887,7 @@ def automations_create_automation_template( A template that would not install is refused: the 400 lists every problem in `details.problems`. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. name: (required) description from_: Copy existing automations: your own (`automationIds`), one of Zernio's templates (`templateId`, for example `stop_losers`), or a template shared by link (`shareToken`). Object with keys: automationIds (list of string, required) @@ -16859,7 +16895,11 @@ def automations_create_automation_template( client = _get_client() try: response = client.automations.create_automation_template( - name=name, description=description, from_=from_, automations=automations + idempotency_key=idempotency_key, + name=name, + description=description, + from_=from_, + automations=automations, ) return _format_response(response) except Exception as e: @@ -16968,6 +17008,7 @@ def automations_delete_automation_template(template_id: str) -> str: ) def automations_install_automation_template( template_id: str, + idempotency_key: str | None = None, inputs: dict[str, Any] | None = None, targets: list[dict[str, Any]] | None = None, status: Literal["active", "paused"] = "paused", @@ -16980,13 +17021,18 @@ def automations_install_automation_template( Args: template_id: The template's id. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. inputs: A value for each input, by its `key`. Required inputs without a default must be sent. targets: Install several times in one call, for example on many ad accounts. Each target is its own install, all or nothing, and its `inputs` win over the shared `inputs`. A failed target leaves the others in place. Each item is an object with keys: inputs (object, required) status: The status of every automation created.""" client = _get_client() try: response = client.automations.install_automation_template( - template_id=template_id, inputs=inputs, targets=targets, status=status + template_id=template_id, + idempotency_key=idempotency_key, + inputs=inputs, + targets=targets, + status=status, ) return _format_response(response) except Exception as e: @@ -17026,6 +17072,7 @@ def automations_get_shared_automation_template(share_token: str) -> str: ) def automations_install_shared_automation_template( share_token: str, + idempotency_key: str | None = None, inputs: dict[str, Any] | None = None, targets: list[dict[str, Any]] | None = None, status: Literal["active", "paused"] = "paused", @@ -17038,13 +17085,18 @@ def automations_install_shared_automation_template( Args: share_token: The token from the template's `share.token`. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. inputs: A value for each input, by its `key`. Required inputs without a default must be sent. targets: Install several times in one call, for example on many ad accounts. Each target is its own install, all or nothing, and its `inputs` win over the shared `inputs`. A failed target leaves the others in place. Each item is an object with keys: inputs (object, required) status: The status of every automation created.""" client = _get_client() try: response = client.automations.install_shared_automation_template( - share_token=share_token, inputs=inputs, targets=targets, status=status + share_token=share_token, + idempotency_key=idempotency_key, + inputs=inputs, + targets=targets, + status=status, ) return _format_response(response) except Exception as e: @@ -17084,6 +17136,7 @@ def automations_get_zernio_automation_template(template_id: str) -> str: ) def automations_install_zernio_automation_template( template_id: str, + idempotency_key: str | None = None, inputs: dict[str, Any] | None = None, targets: list[dict[str, Any]] | None = None, status: Literal["active", "paused"] = "paused", @@ -17096,13 +17149,18 @@ def automations_install_zernio_automation_template( Args: template_id: The id of one of Zernio's templates, for example `stop_losers`. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. inputs: A value for each input, by its `key`. Required inputs without a default must be sent. targets: Install several times in one call, for example on many ad accounts. Each target is its own install, all or nothing, and its `inputs` win over the shared `inputs`. A failed target leaves the others in place. Each item is an object with keys: inputs (object, required) status: The status of every automation created.""" client = _get_client() try: response = client.automations.install_zernio_automation_template( - template_id=template_id, inputs=inputs, targets=targets, status=status + template_id=template_id, + idempotency_key=idempotency_key, + inputs=inputs, + targets=targets, + status=status, ) return _format_response(response) except Exception as e: @@ -17602,6 +17660,7 @@ def blogs_create_blog_article( account_id: str, blog_id: str, title: str, + idempotency_key: str | None = None, body_html: str | None = None, handle: str | None = None, tags: list[str] | None = None, @@ -17643,6 +17702,7 @@ def blogs_create_blog_article( Args: account_id: Connected Shopify, WordPress, Wix or Webflow account id. (required) blog_id: Platform-native blog/site id returned by the list operation. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. title: (required) body_html: Article body as HTML. handle: URL slug. Generated from the title when omitted. @@ -17661,6 +17721,7 @@ def blogs_create_blog_article( response = client.blogs.create_blog_article( account_id=account_id, blog_id=blog_id, + idempotency_key=idempotency_key, title=title, body_html=body_html, handle=handle, @@ -17863,6 +17924,7 @@ def branded_calling_create_branded_calling_enterprise( billing_contact: dict[str, Any] | None, physical_address: dict[str, Any] | None, billing_address: dict[str, Any] | None, + idempotency_key: str | None = None, ) -> str: """Register a business for Branded Calling @@ -17873,6 +17935,7 @@ def branded_calling_create_branded_calling_enterprise( Send an `Idempotency-Key` so a retry replays the original response instead of registering the business twice. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. legal_name: Exactly as on the tax record. (required) doing_business_as: (required) organization_type: (required) @@ -17890,6 +17953,7 @@ def branded_calling_create_branded_calling_enterprise( client = _get_client() try: response = client.branded_calling.create_branded_calling_enterprise( + idempotency_key=idempotency_key, legal_name=legal_name, doing_business_as=doing_business_as, organization_type=organization_type, @@ -18040,6 +18104,7 @@ def branded_calling_create_branded_calling_identity( call_reasons: list[str] | None, authorizer: dict[str, Any] | None, references: dict[str, Any] | None, + idempotency_key: str | None = None, logo_url: str | None = None, ) -> str: """Create a caller identity @@ -18062,6 +18127,7 @@ def branded_calling_create_branded_calling_identity( - Branded calls add $0.10 each, counted on every outbound call from a verified branded number to a US destination (whether or not the callee's carrier ... Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. enterprise_id: A business from POST /v1/branded-calling/enterprises. (required) display_name: Shown on the callee's screen. No emoji. (required) call_reasons: 1 to 10 reasons you call, each up to 64 characters. Pick from GET /v1/branded-calling/call-reasons to skip manual vetting. (required) @@ -18071,6 +18137,7 @@ def branded_calling_create_branded_calling_identity( client = _get_client() try: response = client.branded_calling.create_branded_calling_identity( + idempotency_key=idempotency_key, enterprise_id=enterprise_id, display_name=display_name, call_reasons=call_reasons, @@ -21657,6 +21724,7 @@ def comments_reply_to_inbox_post( post_id: str, account_id: str, message: str, + idempotency_key: str | None = None, attachment_url: str | None = None, comment_id: str | None = None, mention_author: bool | None = None, @@ -21684,6 +21752,7 @@ def comments_reply_to_inbox_post( Args: post_id: Zernio post ID or platform-specific post ID. On LinkedIn, pass the post id exactly as the feed returns it (urn:li:share: or urn:li:ugcPost:); a bare number is read as an activity id (urn:li:activity:). (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: (required) message: Reply text. On LinkedIn, mention with @[https://www.linkedin.com/in/vanity] (resolved to LinkedIn's live name, same rules and errors as post content) or @[Name](urn:li:person|organization:ID); a hand-written name must match LinkedIn's exactly or it renders as plain text. (required) attachment_url: (Facebook only) URL of an image to attach, publishing a photo comment alongside the text. The URL must be publicly accessible so Meta can fetch it. Returns 400 for other platforms. @@ -21700,6 +21769,7 @@ def comments_reply_to_inbox_post( try: response = client.comments.reply_to_inbox_post( post_id=post_id, + idempotency_key=idempotency_key, account_id=account_id, message=message, attachment_url=attachment_url, @@ -22373,6 +22443,7 @@ def commerce_update_commerce_order( def commerce_create_commerce_refund( order_id: str, account_id: str, + idempotency_key: str | None = None, line_items: list[dict[str, Any]] | None = None, shipping: dict[str, Any] | None = None, amount: str | None = None, @@ -22393,6 +22464,7 @@ def commerce_create_commerce_refund( Args: order_id: Platform-native order id. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: Connected store SocialAccount id. (required) line_items: Each item is an object with keys: lineItemId (string, required) - A line item id from the order (`lineItems[].id`).; quantity (integer, required); restock (boolean) - Put the units back in stock. Unshipped units are cancelled and shipped ones count as returned. shipping: Refund the shipping: `{ "full": true }` for what is left of it, or `{ "amount": "5.00" }` for part of it. Object with keys: full (boolean, required) - Must be true. @@ -22405,6 +22477,7 @@ def commerce_create_commerce_refund( try: response = client.commerce.create_commerce_refund( order_id=order_id, + idempotency_key=idempotency_key, account_id=account_id, line_items=line_items, shipping=shipping, @@ -22429,6 +22502,7 @@ def commerce_create_commerce_refund( def commerce_create_commerce_order_edit( order_id: str, account_id: str, + idempotency_key: str | None = None, add: list[dict[str, Any]] | None = None, quantities: list[dict[str, Any]] | None = None, notify_customer: bool = False, @@ -22447,6 +22521,7 @@ def commerce_create_commerce_order_edit( Args: order_id: Platform-native order id. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: Connected store SocialAccount id. (required) add: Each item is an object with keys: variantId (string, required); quantity (integer, required) quantities: Each item is an object with keys: lineItemId (string, required) - A line item id from the order.; quantity (integer, required) - The new quantity; 0 removes the line.; restock (boolean) - Put removed units back in stock. @@ -22457,6 +22532,7 @@ def commerce_create_commerce_order_edit( try: response = client.commerce.create_commerce_order_edit( order_id=order_id, + idempotency_key=idempotency_key, account_id=account_id, add=add, quantities=quantities, @@ -22527,6 +22603,7 @@ def commerce_cancel_commerce_order( def commerce_create_commerce_draft_order( account_id: str, line_items: list[dict[str, Any]] | None, + idempotency_key: str | None = None, customer_id: str | None = None, email: str | None = None, discount: dict[str, Any] | None = None, @@ -22544,6 +22621,7 @@ def commerce_create_commerce_draft_order( Platforms: shopify Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: Connected store SocialAccount id. (required) customer_id: The customer it is for, from the customers endpoints. email @@ -22556,6 +22634,7 @@ def commerce_create_commerce_draft_order( client = _get_client() try: response = client.commerce.create_commerce_draft_order( + idempotency_key=idempotency_key, account_id=account_id, customer_id=customer_id, email=email, @@ -28510,6 +28589,7 @@ def connect_create_google_business_location( title: str, language_code: str, primary_category: str, + idempotency_key: str | None = None, additional_categories: list[str] | None = None, storefront_address: dict[str, Any] | None = None, service_area: dict[str, Any] | None = None, @@ -28533,6 +28613,7 @@ def connect_create_google_business_location( Args: account_id: (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. title: Business name as shown on Google. (required) language_code: BCP-47 language of the listing (e.g. "es"). Immutable after creation. (required) primary_category: Category name from GET gmb-categories (e.g. "categories/gcid:cafe"). A bare "gcid:cafe" is also accepted. (required) @@ -28548,6 +28629,7 @@ def connect_create_google_business_location( try: response = client.connect.create_google_business_location( account_id=account_id, + idempotency_key=idempotency_key, title=title, language_code=language_code, primary_category=primary_category, @@ -30329,6 +30411,7 @@ def conversions_list_events( def conversions_send_events( profile_id: str, events: list[dict[str, Any]] | None, + idempotency_key: str | None = None, destinations: list[dict[str, Any]] | None = None, consent: dict[str, Any] | None = None, test_code: str | None = None, @@ -30355,6 +30438,7 @@ def conversions_send_events( Platforms: meta, google, tiktok, linkedin, pinterest, reddit Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. profile_id: Profile the events belong to. Its saved destinations receive the events. (required) events: Each item is an object with keys: eventName (string, required) - Standard event name (Purchase, Lead, CompleteRegistration, AddToCart, InitiateCheckout, AddPaymentInfo, Subscribe, StartTrial, ViewContent, Search, Contact, ...; eventTime (integer, required) - When the conversion happened, in unix seconds.; eventId (string, required) - Unique dedup key. Use the same eventId on pixel + CAPI to prevent double-counting. Mapped to: - Meta: event_id. - Google: transactionId. - LinkedIn: eventId. ...; value (number) - Conversion value in the specified currency.; currency (string) - ISO 4217 currency code.; user (object with keys email, phone, firstName, lastName, externalId, ipAddress, userAgent, country, city, state, zip, dob, gender, leadId, visitorId, clickIds, required) - User identity fields. More signals mean higher match rates.; items (list of objects with keys id, name, price, quantity, category) - Item-level detail for ecommerce events.; sourceUrl (string) - URL where the conversion originated (used by Meta).; campaign (object with keys id, name) - The ad campaign behind the event, when you know it. Read only by `POST /v1/events`, which ties the event to the campaign named by `campaign.id`, then by the ...; actionSource (one of: web, app, offline, crm, phone_call, system_generated, business_messaging) - Where the conversion happened. Used by Meta. Google also requires an event source internally; omitting this field sends OTHER to Google. Send an explicit ...; messaging (object with keys channel, wabaId, ctwaClid, pageId, instagramBusinessAccountId, pageScopedUserId, instagramScopedUserId) - Meta only, read when `actionSource` is `business_messaging` (Conversions API for Business Messaging). - `channel` is sent as the event's `messaging_channel` ...; platformData (object) - Escape hatch for platform-specific fields we haven't normalized. On Meta, keys are shallow-merged into `custom_data` only: fields Zernio already builds ... (required) destinations: Send to these destinations instead of the saved ones (every event goes to each). Each item is an object with keys: accountId (string, required) - Connected ads account ID (metaads, googleads, linkedinads, tiktokads, openaiads, pinterestads or redditads).; destinationId (string, required) - Platform destination, as listed by GET /v1/ads/conversions/destinations. @@ -30364,6 +30448,7 @@ def conversions_send_events( client = _get_client() try: response = client.conversions.send_events( + idempotency_key=idempotency_key, profile_id=profile_id, events=events, destinations=destinations, @@ -30791,7 +30876,7 @@ def conversions_create_tracking_site( The ad accounts you picked for each connection get a forwarding rule, so website conversions reach them at once. `checks` shows each step; `setup.status` turns `ready` when all have passed. Args: - idempotency_key: A unique key per site you create, such as a UUID. A retry with the same key and body returns the same site. (required) + idempotency_key: Key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. (required) body: Full request body as documented in the API reference. (required)""" client = _get_client() try: @@ -30892,7 +30977,7 @@ def conversions_rotate_tracking_site_key(site_id: str, idempotency_key: str) -> Args: site_id: (required) - idempotency_key: A unique key per rotation, such as a UUID. (required)""" + idempotency_key: Key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. (required)""" client = _get_client() try: response = client.conversions.rotate_tracking_site_key( @@ -31850,6 +31935,7 @@ def creator_campaigns_create_creator_campaign( name: str, brand_name: str, economics: dict[str, Any] | None, + idempotency_key: str | None = None, caps: dict[str, Any] | None = None, platforms: list[ Literal[ @@ -31890,6 +31976,7 @@ def creator_campaigns_create_creator_campaign( `feature_not_available`. `profileId` must be a profile this key can reach, otherwise 404. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. profile_id: Profile the campaign lives in. Creator accounts connect into the same workspace. (required) name: (required) brand_name: (required) @@ -31917,6 +32004,7 @@ def creator_campaigns_create_creator_campaign( client = _get_client() try: response = client.creator_campaigns.create_creator_campaign( + idempotency_key=idempotency_key, profile_id=profile_id, name=name, brand_name=brand_name, @@ -32116,7 +32204,7 @@ def creator_campaigns_update_creator_campaign( ) ) def creator_campaigns_raise_creator_campaign_budget( - campaign_id: str, budget_cents: int + campaign_id: str, budget_cents: int, idempotency_key: str | None = None ) -> str: """Raise creator campaign budget @@ -32130,11 +32218,14 @@ def creator_campaigns_raise_creator_campaign_budget( Args: campaign_id: Campaign ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. budget_cents: The new total budget in cents. (required)""" client = _get_client() try: response = client.creator_campaigns.raise_creator_campaign_budget( - campaign_id=campaign_id, budget_cents=budget_cents + campaign_id=campaign_id, + idempotency_key=idempotency_key, + budget_cents=budget_cents, ) return _format_response(response) except Exception as e: @@ -32228,7 +32319,10 @@ def creator_campaigns_close_creator_campaign(campaign_id: str) -> str: ) ) def creator_campaigns_create_campaign_participant( - campaign_id: str, display_name: str, email: str | None = None + campaign_id: str, + display_name: str, + idempotency_key: str | None = None, + email: str | None = None, ) -> str: """Invite campaign participant @@ -32248,12 +32342,16 @@ def creator_campaigns_create_campaign_participant( Args: campaign_id: Campaign ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. display_name: (required) email""" client = _get_client() try: response = client.creator_campaigns.create_campaign_participant( - campaign_id=campaign_id, display_name=display_name, email=email + campaign_id=campaign_id, + idempotency_key=idempotency_key, + display_name=display_name, + email=email, ) return _format_response(response) except Exception as e: @@ -32330,7 +32428,7 @@ def creator_campaigns_get_campaign_participant( ) ) def creator_campaigns_approve_campaign_participant( - campaign_id: str, participant_id: str + campaign_id: str, participant_id: str, idempotency_key: str | None = None ) -> str: """Approve pending campaign participant @@ -32349,11 +32447,14 @@ def creator_campaigns_approve_campaign_participant( Args: campaign_id: Campaign ID. (required) - participant_id: Participant ID. (required)""" + participant_id: Participant ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action.""" client = _get_client() try: response = client.creator_campaigns.approve_campaign_participant( - campaign_id=campaign_id, participant_id=participant_id + campaign_id=campaign_id, + participant_id=participant_id, + idempotency_key=idempotency_key, ) return _format_response(response) except Exception as e: @@ -32368,7 +32469,7 @@ def creator_campaigns_approve_campaign_participant( ) ) def creator_campaigns_deny_campaign_participant( - campaign_id: str, participant_id: str + campaign_id: str, participant_id: str, idempotency_key: str | None = None ) -> str: """Deny pending campaign participant @@ -32376,11 +32477,14 @@ def creator_campaigns_deny_campaign_participant( Args: campaign_id: Campaign ID. (required) - participant_id: Participant ID. (required)""" + participant_id: Participant ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action.""" client = _get_client() try: response = client.creator_campaigns.deny_campaign_participant( - campaign_id=campaign_id, participant_id=participant_id + campaign_id=campaign_id, + participant_id=participant_id, + idempotency_key=idempotency_key, ) return _format_response(response) except Exception as e: @@ -32519,7 +32623,7 @@ def creator_campaigns_move_campaign_participant( ) ) def creator_campaigns_resend_campaign_participant_invite( - campaign_id: str, participant_id: str + campaign_id: str, participant_id: str, idempotency_key: str | None = None ) -> str: """Resend campaign participant invite @@ -32532,11 +32636,14 @@ def creator_campaigns_resend_campaign_participant_invite( Args: campaign_id: Campaign ID. (required) - participant_id: Participant ID. (required)""" + participant_id: Participant ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action.""" client = _get_client() try: response = client.creator_campaigns.resend_campaign_participant_invite( - campaign_id=campaign_id, participant_id=participant_id + campaign_id=campaign_id, + participant_id=participant_id, + idempotency_key=idempotency_key, ) return _format_response(response) except Exception as e: @@ -32553,6 +32660,7 @@ def creator_campaigns_resend_campaign_participant_invite( def creator_campaigns_settle_campaign_participant( campaign_id: str, participant_id: str, + idempotency_key: str | None = None, amount_cents: int | None = None, external_reference: str | None = None, record_only: bool | None = None, @@ -32572,6 +32680,7 @@ def creator_campaigns_settle_campaign_participant( Args: campaign_id: Campaign ID. (required) participant_id: Participant ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. amount_cents: Defaults to the whole payable balance. external_reference: Your payout id. Required when the campaign settles externally. record_only: Treasury campaigns only, and required there: record a payout you already made outside Zernio. Ignored on other settlement modes, which always record.""" @@ -32580,6 +32689,7 @@ def creator_campaigns_settle_campaign_participant( response = client.creator_campaigns.settle_campaign_participant( campaign_id=campaign_id, participant_id=participant_id, + idempotency_key=idempotency_key, amount_cents=amount_cents, external_reference=external_reference, record_only=record_only, @@ -32597,6 +32707,7 @@ def creator_campaigns_settle_campaign_participant( ) ) def creator_campaigns_create_campaign_payout_batch( + idempotency_key: str | None = None, participant_ids: list[str] | None = None, exclude_participant_ids: list[str] | None = None, payment_method_id: str | None = None, @@ -32616,12 +32727,14 @@ def creator_campaigns_create_campaign_payout_batch( A creator whose payouts were disabled before the hold ended is skipped and stays payable. A charge refunded or disputed during the hold pays nobody: every amount is payable again. ... Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. participant_ids: Pay only these participants. Defaults to every payable participant who is ready. exclude_participant_ids: Leave these participants out. payment_method_id: A saved card of the billing owner's (`pm_...`). Defaults to the default payment method.""" client = _get_client() try: response = client.creator_campaigns.create_campaign_payout_batch( + idempotency_key=idempotency_key, participant_ids=participant_ids, exclude_participant_ids=exclude_participant_ids, payment_method_id=payment_method_id, @@ -32854,7 +32967,7 @@ def creator_campaigns_get_campaign_submission( ) ) def creator_campaigns_approve_campaign_submission( - campaign_id: str, submission_id: str + campaign_id: str, submission_id: str, idempotency_key: str | None = None ) -> str: """Approve campaign submission @@ -32875,11 +32988,14 @@ def creator_campaigns_approve_campaign_submission( Args: campaign_id: Campaign ID. (required) - submission_id: Submission ID. (required)""" + submission_id: Submission ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action.""" client = _get_client() try: response = client.creator_campaigns.approve_campaign_submission( - campaign_id=campaign_id, submission_id=submission_id + campaign_id=campaign_id, + submission_id=submission_id, + idempotency_key=idempotency_key, ) return _format_response(response) except Exception as e: @@ -32894,7 +33010,10 @@ def creator_campaigns_approve_campaign_submission( ) ) def creator_campaigns_reject_campaign_submission( - campaign_id: str, submission_id: str, reason: str + campaign_id: str, + submission_id: str, + reason: str, + idempotency_key: str | None = None, ) -> str: """Reject campaign submission @@ -32905,11 +33024,15 @@ def creator_campaigns_reject_campaign_submission( Args: campaign_id: Campaign ID. (required) submission_id: Submission ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. reason: (required)""" client = _get_client() try: response = client.creator_campaigns.reject_campaign_submission( - campaign_id=campaign_id, submission_id=submission_id, reason=reason + campaign_id=campaign_id, + submission_id=submission_id, + idempotency_key=idempotency_key, + reason=reason, ) return _format_response(response) except Exception as e: @@ -32924,7 +33047,7 @@ def creator_campaigns_reject_campaign_submission( ) ) def creator_campaigns_reopen_campaign_submission( - campaign_id: str, submission_id: str + campaign_id: str, submission_id: str, idempotency_key: str | None = None ) -> str: """Reopen campaign submission @@ -32943,11 +33066,14 @@ def creator_campaigns_reopen_campaign_submission( Args: campaign_id: Campaign ID. (required) - submission_id: Submission ID. (required)""" + submission_id: Submission ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action.""" client = _get_client() try: response = client.creator_campaigns.reopen_campaign_submission( - campaign_id=campaign_id, submission_id=submission_id + campaign_id=campaign_id, + submission_id=submission_id, + idempotency_key=idempotency_key, ) return _format_response(response) except Exception as e: @@ -33028,7 +33154,7 @@ def creator_campaigns_get_campaign_draft(campaign_id: str, draft_id: str) -> str ) ) def creator_campaigns_approve_campaign_draft( - campaign_id: str, draft_id: str + campaign_id: str, draft_id: str, idempotency_key: str | None = None ) -> str: """Approve campaign draft @@ -33038,11 +33164,14 @@ def creator_campaigns_approve_campaign_draft( Args: campaign_id: Campaign ID. (required) - draft_id: Draft version ID. (required)""" + draft_id: Draft version ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action.""" client = _get_client() try: response = client.creator_campaigns.approve_campaign_draft( - campaign_id=campaign_id, draft_id=draft_id + campaign_id=campaign_id, + draft_id=draft_id, + idempotency_key=idempotency_key, ) return _format_response(response) except Exception as e: @@ -33059,6 +33188,7 @@ def creator_campaigns_approve_campaign_draft( def creator_campaigns_request_campaign_draft_revision( campaign_id: str, draft_id: str, + idempotency_key: str | None = None, note: str | None = None, comments: list[dict[str, Any]] | None = None, ) -> str: @@ -33073,12 +33203,17 @@ def creator_campaigns_request_campaign_draft_revision( Args: campaign_id: Campaign ID. (required) draft_id: Draft version ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. note: What to change overall. Stored as `reviewNote`. comments: Each item is an object with keys: atMs (integer) - Milliseconds into the video the comment is about. Null or omitted for a general comment.; body (string, required)""" client = _get_client() try: response = client.creator_campaigns.request_campaign_draft_revision( - campaign_id=campaign_id, draft_id=draft_id, note=note, comments=comments + campaign_id=campaign_id, + draft_id=draft_id, + idempotency_key=idempotency_key, + note=note, + comments=comments, ) return _format_response(response) except Exception as e: @@ -33093,7 +33228,7 @@ def creator_campaigns_request_campaign_draft_revision( ) ) def creator_campaigns_reject_campaign_draft( - campaign_id: str, draft_id: str, reason: str + campaign_id: str, draft_id: str, reason: str, idempotency_key: str | None = None ) -> str: """Reject campaign draft @@ -33104,11 +33239,15 @@ def creator_campaigns_reject_campaign_draft( Args: campaign_id: Campaign ID. (required) draft_id: Draft version ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. reason: (required)""" client = _get_client() try: response = client.creator_campaigns.reject_campaign_draft( - campaign_id=campaign_id, draft_id=draft_id, reason=reason + campaign_id=campaign_id, + draft_id=draft_id, + idempotency_key=idempotency_key, + reason=reason, ) return _format_response(response) except Exception as e: @@ -33161,7 +33300,7 @@ def creator_campaigns_list_campaign_samples( ) ) def creator_campaigns_approve_campaign_sample( - campaign_id: str, sample_id: str + campaign_id: str, sample_id: str, idempotency_key: str | None = None ) -> str: """Approve campaign sample request @@ -33178,11 +33317,14 @@ def creator_campaigns_approve_campaign_sample( Args: campaign_id: Campaign ID. (required) - sample_id: Sample request ID. (required)""" + sample_id: Sample request ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action.""" client = _get_client() try: response = client.creator_campaigns.approve_campaign_sample( - campaign_id=campaign_id, sample_id=sample_id + campaign_id=campaign_id, + sample_id=sample_id, + idempotency_key=idempotency_key, ) return _format_response(response) except Exception as e: @@ -33197,7 +33339,10 @@ def creator_campaigns_approve_campaign_sample( ) ) def creator_campaigns_decline_campaign_sample( - campaign_id: str, sample_id: str, reason: str + campaign_id: str, + sample_id: str, + reason: str, + idempotency_key: str | None = None, ) -> str: """Decline campaign sample request @@ -33206,11 +33351,15 @@ def creator_campaigns_decline_campaign_sample( Args: campaign_id: Campaign ID. (required) sample_id: Sample request ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. reason: Shown to the creator. (required)""" client = _get_client() try: response = client.creator_campaigns.decline_campaign_sample( - campaign_id=campaign_id, sample_id=sample_id, reason=reason + campaign_id=campaign_id, + sample_id=sample_id, + idempotency_key=idempotency_key, + reason=reason, ) return _format_response(response) except Exception as e: @@ -33225,7 +33374,10 @@ def creator_campaigns_decline_campaign_sample( ) ) def creator_campaigns_ship_campaign_sample( - campaign_id: str, sample_id: str, tracking_url: str | None = None + campaign_id: str, + sample_id: str, + idempotency_key: str | None = None, + tracking_url: str | None = None, ) -> str: """Mark campaign sample shipped @@ -33234,11 +33386,15 @@ def creator_campaigns_ship_campaign_sample( Args: campaign_id: Campaign ID. (required) sample_id: Sample request ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. tracking_url: The carrier tracking link, shown to the creator.""" client = _get_client() try: response = client.creator_campaigns.ship_campaign_sample( - campaign_id=campaign_id, sample_id=sample_id, tracking_url=tracking_url + campaign_id=campaign_id, + sample_id=sample_id, + idempotency_key=idempotency_key, + tracking_url=tracking_url, ) return _format_response(response) except Exception as e: @@ -33278,7 +33434,11 @@ def creator_campaigns_list_campaign_payables(campaign_id: str) -> str: ) ) def creator_campaigns_create_campaign_adjustment( - campaign_id: str, participant_id: str, amount_cents: int, cause: str + campaign_id: str, + participant_id: str, + amount_cents: int, + cause: str, + idempotency_key: str | None = None, ) -> str: """Create campaign adjustment @@ -33288,6 +33448,7 @@ def creator_campaigns_create_campaign_adjustment( Args: campaign_id: Campaign ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. participant_id: (required) amount_cents: Non-zero. Positive credits, negative claws back. (required) cause: (required)""" @@ -33295,6 +33456,7 @@ def creator_campaigns_create_campaign_adjustment( try: response = client.creator_campaigns.create_campaign_adjustment( campaign_id=campaign_id, + idempotency_key=idempotency_key, participant_id=participant_id, amount_cents=amount_cents, cause=cause, @@ -33446,6 +33608,7 @@ def creator_campaigns_launch_campaign_ads( account_id: str, ad_account_id: str, identity: Literal["brand", "creator"], + idempotency_key: str | None = None, ad_set_id: str | None = None, existing_campaign_id: str | None = None, daily_budget: float | None = None, @@ -33471,6 +33634,7 @@ def creator_campaigns_launch_campaign_ads( Args: campaign_id: Campaign ID. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. submission_ids: Approved submissions to run as ads. (required) network: Meta runs Instagram and Facebook posts; TikTok runs TikTok posts. (required) account_id: The brand's connected ads account (Facebook or TikTok) the ads run from, as in `/v1/accounts`. (required) @@ -33488,6 +33652,7 @@ def creator_campaigns_launch_campaign_ads( try: response = client.creator_campaigns.launch_campaign_ads( campaign_id=campaign_id, + idempotency_key=idempotency_key, submission_ids=submission_ids, network=network, account_id=account_id, @@ -35264,6 +35429,7 @@ def email_send_email_message( account_id: str, to: list[dict[str, Any]] | None, subject: str, + idempotency_key: str | None = None, cc: list[dict[str, Any]] | None = None, bcc: list[dict[str, Any]] | None = None, reply_to: list[dict[str, Any]] | None = None, @@ -35297,6 +35463,7 @@ def email_send_email_message( - A spam signal starts the count over and returns the cap to its base. Signals: a same-body burst, a send refused over the mailbox's ... Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: (required) to: Each item is an object with keys: email (string, required); name (string) (required) cc: Each item is an object with keys: email (string, required); name (string) @@ -35320,6 +35487,7 @@ def email_send_email_message( client = _get_client() try: response = client.email.send_email_message( + idempotency_key=idempotency_key, account_id=account_id, to=to, cc=cc, @@ -35542,6 +35710,7 @@ def email_reply_email_message( account_id: str, to: list[dict[str, Any]] | None, subject: str, + idempotency_key: str | None = None, cc: list[dict[str, Any]] | None = None, bcc: list[dict[str, Any]] | None = None, reply_to: list[dict[str, Any]] | None = None, @@ -35568,6 +35737,7 @@ def email_reply_email_message( `scheduledFor` schedules the reply (202) and `trackOpens`, `trackLinks` and `trackReplies` track it, as on send; `holdAsDraft` holds it as a reply draft in the thread until then. Same protection, caps and headers as sending. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. message_id: (required) account_id: (required) to: Each item is an object with keys: email (string, required); name (string) (required) @@ -35593,6 +35763,7 @@ def email_reply_email_message( client = _get_client() try: response = client.email.reply_email_message( + idempotency_key=idempotency_key, message_id=message_id, account_id=account_id, to=to, @@ -35632,6 +35803,7 @@ def email_forward_email_message( message_id: str, account_id: str, to: list[dict[str, Any]] | None, + idempotency_key: str | None = None, cc: list[dict[str, Any]] | None = None, bcc: list[dict[str, Any]] | None = None, reply_to: list[dict[str, Any]] | None = None, @@ -35659,6 +35831,7 @@ def email_forward_email_message( `trackOpens`, `trackLinks` and `trackReplies` work as on send. Same protection, caps and headers as sending. The response carries `forwardedFrom`, and `email.sent` fires with `source: forward`. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. message_id: (required) account_id: (required) to: Each item is an object with keys: email (string, required); name (string) (required) @@ -35682,6 +35855,7 @@ def email_forward_email_message( client = _get_client() try: response = client.email.forward_email_message( + idempotency_key=idempotency_key, message_id=message_id, account_id=account_id, to=to, @@ -35745,6 +35919,7 @@ def email_list_email_drafts( ) def email_create_email_draft( account_id: str, + idempotency_key: str | None = None, to: list[dict[str, Any]] | None = None, cc: list[dict[str, Any]] | None = None, bcc: list[dict[str, Any]] | None = None, @@ -35775,6 +35950,7 @@ def email_create_email_draft( Send it with `POST /v1/email/drafts/{draftId}/send`. Edits the user makes in their mail client are what goes out. Store the draft `id`, and pass its `version` as `If-Match` so an update or send applies only to the version you saw. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: (required) to: Optional on a draft; needed before it is sent. Each item is an object with keys: email (string, required); name (string) cc: Each item is an object with keys: email (string, required); name (string) @@ -35801,6 +35977,7 @@ def email_create_email_draft( client = _get_client() try: response = client.email.create_email_draft( + idempotency_key=idempotency_key, account_id=account_id, to=to, cc=cc, @@ -35942,7 +36119,10 @@ def email_delete_email_draft(draft_id: str, account_id: str) -> str: ) ) def email_send_email_draft( - draft_id: str, account_id: str, send_at: str | None = None + draft_id: str, + account_id: str, + idempotency_key: str | None = None, + send_at: str | None = None, ) -> str: """Send a draft @@ -35953,13 +36133,17 @@ def email_send_email_draft( Tracking set when the draft was created applies, and its `metadata` comes back on the sent message. Same protection, caps and headers as sending. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. draft_id: (required) account_id: (required) send_at: Send later, 1 minute to 30 days ahead: answers 202 with a `ScheduledEmail`. The draft stays editable in the mailbox and goes out as it stands then. Cancelling with `DELETE /v1/email/messages/scheduled/{scheduleId}` keeps the draft.""" client = _get_client() try: response = client.email.send_email_draft( - draft_id=draft_id, account_id=account_id, send_at=send_at + idempotency_key=idempotency_key, + draft_id=draft_id, + account_id=account_id, + send_at=send_at, ) return _format_response(response) except Exception as e: @@ -39823,6 +40007,7 @@ def messages_get_inbox_conversation_messages( def messages_send_inbox_message( conversation_id: str, account_id: str, + idempotency_key: str | None = None, message: str | None = None, attachment_url: str | None = None, category: Literal["utility"] | None = None, @@ -39892,6 +40077,7 @@ def messages_send_inbox_message( Args: conversation_id: Opaque conversation identifier, accepted verbatim from the list endpoint or from the conversationId on inbox webhooks. Format not to be assumed. (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: Account ID (required) message: Message text attachment_url: URL of the attachment to send (image, video, audio, or file). Must be publicly accessible. For binary file uploads, use multipart/form-data instead. @@ -39944,6 +40130,7 @@ def messages_send_inbox_message( try: response = client.messages.send_inbox_message( conversation_id=conversation_id, + idempotency_key=idempotency_key, account_id=account_id, message=message, attachment_url=attachment_url, @@ -40554,6 +40741,7 @@ def messaging_ads_create_messaging_ad( account_id: str, ad_account_id: str, name: str, + idempotency_key: str | None = None, retry_on_server_error: bool = True, creative_features: dict[str, Any] | None = None, tracking: dict[str, Any] | None = None, @@ -40703,6 +40891,7 @@ def messaging_ads_create_messaging_ad( Safe to retry: an identical call within 24 hours returns the first result instead of creating a second one, and answers 409 while the first is still running. To create another on purpose, or if that 409 does not clear, change an argument such as the name. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. retry_on_server_error: When Meta answers a create with a 5xx and reading the parent back by name finds no such object, Zernio sends the create again (at most 3 POSTs per object, never for an object created ACTIVE) and reports it in `recoveredWrites`. `false` never sends it again: the request fails with 502 and `details.unconfirmedWrite`, so you can check the parent yourself. One object found by name is still reused. @@ -41071,7 +41260,8 @@ def messaging_ads_create_messaging_ad( placement_assets=placement_assets, workflow_id=workflow_id, validate_only=validate_only, - idempotency_key=same_arguments_key( + idempotency_key=idempotency_key + or same_arguments_key( "messaging_ads_create_messaging_ad", same_arguments ), ) @@ -41093,6 +41283,7 @@ def messaging_ads_create_call_ad( name: str, phone_number: str, link_url: str, + idempotency_key: str | None = None, retry_on_server_error: bool = True, creative_features: dict[str, Any] | None = None, tracking: dict[str, Any] | None = None, @@ -41230,6 +41421,7 @@ def messaging_ads_create_call_ad( Safe to retry: an identical call within 24 hours returns the first result instead of creating a second one, and answers 409 while the first is still running. To create another on purpose, or if that 409 does not clear, change an argument such as the name. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. retry_on_server_error: When Meta answers a create with a 5xx and reading the parent back by name finds no such object, Zernio sends the create again (at most 3 POSTs per object, never for an object created ACTIVE) and reports it in `recoveredWrites`. `false` never sends it again: the request fails with 502 and `details.unconfirmedWrite`, so you can check the parent yourself. One object found by name is still reused. @@ -41577,9 +41769,8 @@ def messaging_ads_create_call_ad( regional_regulation_identities=regional_regulation_identities, phone_number=phone_number, link_url=link_url, - idempotency_key=same_arguments_key( - "messaging_ads_create_call_ad", same_arguments - ), + idempotency_key=idempotency_key + or same_arguments_key("messaging_ads_create_call_ad", same_arguments), ) return _format_response(response) except Exception as e: @@ -41597,6 +41788,7 @@ def messaging_ads_create_ctwa_ad( account_id: str, ad_account_id: str, name: str, + idempotency_key: str | None = None, retry_on_server_error: bool = True, creative_features: dict[str, Any] | None = None, tracking: dict[str, Any] | None = None, @@ -41730,6 +41922,7 @@ def messaging_ads_create_ctwa_ad( Safe to retry: an identical call within 24 hours returns the first result instead of creating a second one, and answers 409 while the first is still running. To create another on purpose, or if that 409 does not clear, change an argument such as the name. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. retry_on_server_error: When Meta answers a create with a 5xx and reading the parent back by name finds no such object, Zernio sends the create again (at most 3 POSTs per object, never for an object created ACTIVE) and reports it in `recoveredWrites`. `false` never sends it again: the request fails with 502 and `details.unconfirmedWrite`, so you can check the parent yourself. One object found by name is still reused. @@ -42071,9 +42264,8 @@ def messaging_ads_create_ctwa_ad( dsa_payor=dsa_payor, regional_regulated_categories=regional_regulated_categories, regional_regulation_identities=regional_regulation_identities, - idempotency_key=same_arguments_key( - "messaging_ads_create_ctwa_ad", same_arguments - ), + idempotency_key=idempotency_key + or same_arguments_key("messaging_ads_create_ctwa_ad", same_arguments), ) return _format_response(response) except Exception as e: @@ -43438,6 +43630,7 @@ def posts_list_posts( ) ) def posts_create_post( + idempotency_key: str | None = None, title: str | None = None, content: str | None = None, media_items: list[dict[str, Any]] | None = None, @@ -43488,6 +43681,7 @@ def posts_create_post( With none of them and `isDraft` unset, ... Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. title: Stored on the post for reference/display only. This field is NOT used as the video title when publishing. To set a YouTube video title, use platformSpecificData.title on the youtube platform target (falls back to the first line of content when omitted). content: Post caption/text. Optional when media is attached, all platforms have customContent, every platform entry is an X Article (platformSpecificData.article), or every platform entry is a LinkedIn text-free reshare (platformSpecificData.reshareUrl with no text). Required for other text-only posts. media_items: Media attached to every platform in the request (a platform entry can override it with `customMedia`). - Each entry needs a publicly reachable HTTPS `url`. - `type` (image, video, gif, document) is inferred from the URL extension when omitted; a `type` that contradicts the extension is rejected with 400. - Upload files with `POST /v1/media/presign` first. - Per-platform size, duration and format limits are listed on each platform schema. Each item is an object with keys: type (one of: image, video, gif, document) - Optional when the item names a connected file (`fileId`): inferred from the file's MIME type.; url (string) - A media item with a null, missing or empty url is dropped, unless it names a connected file with `fileId` + `accountId`. A Google Drive share link is accepted ...; fileId (string) - A file of a connected Google Drive or OneDrive account (see the Files endpoints). Requires `accountId`. The file is copied into Zernio media storage when the ...; accountId (string) - The connected Google or Microsoft account the `fileId` belongs to (must have the `files` area). Required with `fileId`.; title (string) - Optional title for the media item. Used as the document title for LinkedIn PDF/carousel posts. If omitted, falls back to the post title, then the filename.; altText (string) - Accessibility alternative text for an image. Set once per image; the same value is sent to each selected platform. - Applied on: Instagram (feed images only, ...; filename (string); size (integer) - Optional file size in bytes; mimeType (string) - Optional MIME type (e.g. image/jpeg, video/mp4); thumbnail (string) - Optional custom thumbnail/cover image URL for videos. Supported for Facebook video posts, Facebook Reels, YouTube videos and Shorts, and LinkedIn video posts. ...; instagramThumbnail (string) - Custom cover image URL for Instagram Reels. Can also be set via platformSpecificData.instagramThumbnail or platformSpecificData.reelCover. Resolution order: ...; subtitles (list of objects with keys url, language) - Subtitle (closed caption) files for a video item, in SRT or WebVTT. Each language may appear once per video. Zernio downloads each file when the post is ...; tiktokProcessed (boolean) - Internal flag indicating the image was resized for TikTok @@ -43534,6 +43728,7 @@ def posts_create_post( client = _get_client() try: response = client.posts.create_post( + idempotency_key=idempotency_key, title=title, content=content, media_items=media_items, @@ -45026,6 +45221,7 @@ def profiles_list_profiles( ) def profiles_create_profile( name: str, + idempotency_key: str | None = None, description: str | None = None, color: str | None = None, timezone: str | None = None, @@ -45049,6 +45245,7 @@ def profiles_create_profile( Send an Idempotency-Key header to make retries safe. A retried create with the same key and body replays the original 201 (same _id) instead of conflicting. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. name: (required) description color @@ -45061,6 +45258,7 @@ def profiles_create_profile( client = _get_client() try: response = client.profiles.create_profile( + idempotency_key=idempotency_key, name=name, description=description, color=color, @@ -45453,6 +45651,7 @@ def rcs_create_rcs_agent( display_name: str, use_case: Literal["MULTI_USE", "PROMOTIONAL", "TRANSACTIONAL", "OTP"], profile: dict[str, Any] | None, + idempotency_key: str | None = None, brand_id: str | None = None, brand: dict[str, Any] | None = None, sms_fallback_from: str | None = None, @@ -45467,6 +45666,7 @@ def rcs_create_rcs_agent( - Send an `Idempotency-Key` header to make retries safe. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. profile_id: (required) brand_id brand: Object with keys: displayName (string, required); legalName (string, required) - Exactly as on IRS records.; legalEntityType (one of: LIMITED_LIABILITY_COMPANY, SOLE_PROPRIETORSHIP, PARTNERSHIP, CORPORATION, S_CORPORATION; required); organizationType (one of: PRIVATE_PROFIT, PUBLIC_PROFIT, NON_PROFIT, GOVERNMENT; required); websiteUrl (string, required); taxId (string, required) - US: the EIN, 9 digits, optionally NN-NNNNNNN. Elsewhere: the national tax or company registration id.; stockSymbol (string) - EXCHANGE:SYMBOL. Required for PUBLIC_PROFIT.; address (object with keys line1, line2, city, state, postalCode, country, required); contact (object with keys firstName, lastName, title, email, phone, required) @@ -45477,6 +45677,7 @@ def rcs_create_rcs_agent( client = _get_client() try: response = client.rcs.create_rcs_agent( + idempotency_key=idempotency_key, profile_id=profile_id, brand_id=brand_id, brand=brand, @@ -45729,6 +45930,7 @@ def rcs_upload_rcs_asset() -> str: def rcs_send_rcs_message( agent_id: str, to: str, + idempotency_key: str | None = None, text: str | None = None, content: dict[str, Any] | None = None, fallback_text: str | None = None, @@ -45754,6 +45956,7 @@ def rcs_send_rcs_message( - `message.failed` Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. agent_id: (required) to: Recipient number (E.164; formatting is normalized). (required) text @@ -45763,6 +45966,7 @@ def rcs_send_rcs_message( client = _get_client() try: response = client.rcs.send_rcs_message( + idempotency_key=idempotency_key, agent_id=agent_id, to=to, text=text, @@ -46191,7 +46395,10 @@ def reviews_list_inbox_reviews( ) ) def reviews_reply_to_inbox_review( - review_id: str, account_id: str, message: str + review_id: str, + account_id: str, + message: str, + idempotency_key: str | None = None, ) -> str: """Reply to review @@ -46215,12 +46422,16 @@ def reviews_reply_to_inbox_review( Args: review_id: Review ID (URL-encoded for Google Business Profile) (required) + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: (required) message: (required)""" client = _get_client() try: response = client.reviews.reply_to_inbox_review( - review_id=review_id, account_id=account_id, message=message + review_id=review_id, + idempotency_key=idempotency_key, + account_id=account_id, + message=message, ) return _format_response(response) except Exception as e: @@ -46605,6 +46816,7 @@ def slack_list_slack_members( def sms_send_sms( from_: str, to: str, + idempotency_key: str | None = None, text: str | None = None, media_urls: list[str] | None = None, send_at: str | None = None, @@ -46633,6 +46845,7 @@ def sms_send_sms( second message; same key + different ... Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. from_: One of your SMS-enabled numbers (E.164; formatting is normalized). (required) to: Recipient number (E.164). (required) text: Message body. Required unless `mediaUrls` is set. Max 10 SMS segments (1530 GSM-7 or 670 unicode characters). @@ -46641,7 +46854,12 @@ def sms_send_sms( client = _get_client() try: response = client.sms.send_sms( - from_=from_, to=to, text=text, media_urls=media_urls, send_at=send_at + idempotency_key=idempotency_key, + from_=from_, + to=to, + text=text, + media_urls=media_urls, + send_at=send_at, ) return _format_response(response) except Exception as e: @@ -48727,6 +48945,7 @@ def treasury_update_auto_recharge( def treasury_create_topup( amount_cents: int, method: Literal["card", "bank_transfer"], + idempotency_key: str | None = None, payment_method_id: str | None = None, ) -> str: """Add funds @@ -48743,12 +48962,14 @@ def treasury_create_topup( - `status: ... Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. amount_cents: Amount to credit to your balance, in cents: $5 to $100,000. Tax is charged on top; no card fee. (required) method: Only card is available. bank_transfer returns 400 "Bank transfers are not available yet." (required) payment_method_id: A saved card of the billing owner's (`pm_...`). Defaults to the default payment method.""" client = _get_client() try: response = client.treasury.create_topup( + idempotency_key=idempotency_key, amount_cents=amount_cents, method=method, payment_method_id=payment_method_id, @@ -48997,7 +49218,10 @@ def treasury_create_payee_onboarding_link(payee_id: str) -> str: ) ) def treasury_create_transfer( - payee_id: str, amount_cents: int, reference: dict[str, Any] | None = None + payee_id: str, + amount_cents: int, + idempotency_key: str | None = None, + reference: dict[str, Any] | None = None, ) -> str: """Create a transfer (removed) @@ -49006,13 +49230,17 @@ def treasury_create_transfer( Pay creators with one card payment per payout batch: `POST /v1/creator-campaigns/{campaignId}/payout-batches`. `GET /v1/transfers` still lists the transfers payout batches made. Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. payee_id: 24-character payee id (required) amount_cents: Amount the payee receives, in cents. The fee is added on top. (required) reference: Object with keys: type (string, required); id (string, required)""" client = _get_client() try: response = client.treasury.create_transfer( - payee_id=payee_id, amount_cents=amount_cents, reference=reference + idempotency_key=idempotency_key, + payee_id=payee_id, + amount_cents=amount_cents, + reference=reference, ) return _format_response(response) except Exception as e: @@ -50004,6 +50232,7 @@ def verify_check_verification(verification_id: str, code: str) -> str: ) def voice_create_voice_call( to: str, + idempotency_key: str | None = None, from_number: str | None = None, forward_to: str | None = None, greeting: str | None = None, @@ -50035,6 +50264,7 @@ def voice_create_voice_call( On ... Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. to: Destination to dial, E.164 with leading +. (required) from_number: Which of your voice-enabled numbers to dial from. Optional when you have exactly one. forward_to: Per-call agent override (tel:+E164, sip:..., or wss://...); defaults to the number's stored forward destination. @@ -50048,6 +50278,7 @@ def voice_create_voice_call( client = _get_client() try: response = client.voice.create_voice_call( + idempotency_key=idempotency_key, to=to, from_number=from_number, forward_to=forward_to, @@ -53434,6 +53665,7 @@ def whatsapp_calling_get_whats_app_call_permissions( def whatsapp_calling_initiate_whats_app_call( account_id: str, to: str, + idempotency_key: str | None = None, action: Literal["send_call_permission_request"] | None = None, body_text: str | None = None, forward_to: str | None = None, @@ -53463,6 +53695,7 @@ def whatsapp_calling_initiate_whats_app_call( (never past the number's `maxCallDurationSeconds`). Under one ... Args: + idempotency_key: Optional key you choose (e.g. a UUID), one per logical action, up to 255 characters. Sent as the Idempotency-Key header. If this call times out or the chat stops, retry with the same key: within 24 hours you get the original result instead of a second copy, or 409 while the first call is still processing (retry shortly). Use a new key for a new action. account_id: (required) to: Consumer wa_id (E.164, leading + optional) (required) action: Omit to place a call. Set to send the consent prompt instead. @@ -53476,6 +53709,7 @@ def whatsapp_calling_initiate_whats_app_call( client = _get_client() try: response = client.whatsapp_calling.initiate_whats_app_call( + idempotency_key=idempotency_key, account_id=account_id, to=to, action=action, diff --git a/tests/test_mcp_header_and_binary_params.py b/tests/test_mcp_header_and_binary_params.py index fd7a5fccd..178577292 100644 --- a/tests/test_mcp_header_and_binary_params.py +++ b/tests/test_mcp_header_and_binary_params.py @@ -74,18 +74,20 @@ def test_connect_list_snapchat_profiles_sends_connect_token(client: Late) -> Non assert "profileId=prof_1" in str(request.url) -def test_mcp_generator_exposes_only_required_headers(mcp_generator) -> None: +def test_mcp_generator_exposes_required_headers_and_idempotency_key(mcp_generator) -> None: operation = { "parameters": [ {"name": "X-Connect-Token", "in": "header", "required": True}, {"name": "Idempotency-Key", "in": "header", "required": False}, + {"name": "x-request-id", "in": "header", "required": False}, + {"name": "If-Match", "in": "header", "required": False}, {"name": "profileId", "in": "query", "required": True}, ] } names = [p["name"] for p in mcp_generator.extract_parameters(operation, {})] - assert names == ["x_connect_token", "profile_id"] + assert names == ["x_connect_token", "idempotency_key", "profile_id"] def test_mcp_generator_maps_octet_stream_body_to_base64(mcp_generator) -> None: diff --git a/tests/test_mcp_idempotency_key.py b/tests/test_mcp_idempotency_key.py new file mode 100644 index 000000000..75241d1ef --- /dev/null +++ b/tests/test_mcp_idempotency_key.py @@ -0,0 +1,215 @@ +"""Every MCP tool whose operation declares Idempotency-Key must take it as an +argument and send it on the wire, so an agent can retry a timed-out write +without creating a second copy.""" + +from __future__ import annotations + +import asyncio +import importlib +from pathlib import Path +from typing import Any + +import httpx +import pytest +import respx +import yaml +from fastmcp import Client, FastMCP + +from late import Late +from late.mcp.generated_tools import register_generated_tools +from late.mcp.server import mcp + +ROOT = Path(__file__).resolve().parents[1] +API = "https://api.test.com" +CALLER_KEY = "holo-retry-3f1c9a" +# These derive a key from their arguments when the caller passes none. +DERIVED_KEY_TOOLS = { + "ad_campaigns_create_standalone_ad", + "messaging_ads_create_messaging_ad", + "messaging_ads_create_call_ad", + "messaging_ads_create_ctwa_ad", +} + + +def _generator(): + import sys + + sys.path.insert(0, str(ROOT / "scripts")) + try: + return importlib.import_module("generate_mcp_tools") + finally: + sys.path.remove(str(ROOT / "scripts")) + + +def _idempotency_key_param(operation: dict[str, Any], spec: dict[str, Any]) -> dict[str, Any] | None: + for param in operation.get("parameters", []): + if "$ref" in param: + param = spec["components"]["parameters"][param["$ref"].rsplit("/", 1)[-1]] + if param.get("in") == "header" and param.get("name", "").lower() == "idempotency-key": + return param + return None + + +def _idempotent_tools() -> dict[str, bool]: + """Tool name (derived the way the generator names them) -> whether the spec + marks the key required, for every operation that declares Idempotency-Key.""" + gen = _generator() + spec = yaml.safe_load((ROOT / "openapi.yaml").read_text()) + tools: dict[str, bool] = {} + for path_item in spec["paths"].values(): + for method, operation in path_item.items(): + if method not in ("get", "post", "put", "patch", "delete"): + continue + operation_id = operation.get("operationId") + if not operation_id or operation_id in gen.SKIP_OPERATIONS: + continue + key_param = _idempotency_key_param(operation, spec) + if key_param is None: + continue + tag = operation.get("tags", ["Other"])[0] + resource = gen.TAG_TO_RESOURCE.get(tag, tag.lower().replace(" ", "_")) + tool = f"{resource}_{gen.camel_to_snake(operation_id)}" + tool = tool.replace(f"{resource}_{resource}_", f"{resource}_", 1) + tools[tool] = bool(key_param.get("required", False)) + return tools + + +KEY_REQUIRED_BY_TOOL = _idempotent_tools() +IDEMPOTENT_TOOLS = sorted(KEY_REQUIRED_BY_TOOL) +OPTIONAL_KEY_TOOLS = sorted(t for t, required in KEY_REQUIRED_BY_TOOL.items() if not required) + + +async def _schemas() -> dict[str, dict[str, Any]]: + local = FastMCP("schemas") + register_generated_tools(local, lambda: None) + async with Client(local) as client: + return {t.name: t.inputSchema for t in await client.list_tools()} + + +def _dummy(schema: dict[str, Any]) -> Any: + for option in schema.get("anyOf", []): + if option.get("type") != "null": + return _dummy(option) + if "enum" in schema: + return schema["enum"][0] + return { + "string": "x_1", + "integer": 1, + "number": 1, + "boolean": True, + "array": [], + "object": {}, + }.get(schema.get("type"), "x_1") + + +def _required_arguments(schema: dict[str, Any]) -> dict[str, Any]: + props = schema.get("properties", {}) + return {name: _dummy(props[name]) for name in schema.get("required", [])} + + +@pytest.fixture(autouse=True) +def api_env(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("ZERNIO_API_KEY", "test_api_key") + monkeypatch.setenv("ZERNIO_BASE_URL", API) + + +@pytest.fixture(scope="module") +def schemas() -> dict[str, dict[str, Any]]: + return asyncio.run(_schemas()) + + +def test_the_spec_still_declares_idempotency_key_on_posts() -> None: + # Guards the parametrized checks below against silently running on nothing. + assert "posts_create_post" in IDEMPOTENT_TOOLS + assert len(IDEMPOTENT_TOOLS) > 50 + + +@pytest.mark.parametrize("tool", IDEMPOTENT_TOOLS) +def test_tool_exposes_idempotency_key_as_the_spec_declares_it( + tool: str, schemas: dict[str, dict[str, Any]] +) -> None: + schema = schemas[tool] + + assert "idempotency_key" in schema["properties"] + assert ("idempotency_key" in schema.get("required", [])) is KEY_REQUIRED_BY_TOOL[tool] + + +@pytest.mark.parametrize("tool", IDEMPOTENT_TOOLS) +@respx.mock +async def test_caller_key_reaches_the_api_as_the_header( + tool: str, schemas: dict[str, dict[str, Any]] +) -> None: + route = respx.route(host="api.test.com").mock( + return_value=httpx.Response(201, json={"id": "x_1"}) + ) + arguments = {**_required_arguments(schemas[tool]), "idempotency_key": CALLER_KEY} + + async with Client(mcp) as client: + await client.call_tool(tool, arguments) + + assert route.call_count == 1 + assert route.calls.last.request.headers["Idempotency-Key"] == CALLER_KEY + + +@pytest.mark.parametrize("tool", sorted(set(OPTIONAL_KEY_TOOLS) - DERIVED_KEY_TOOLS)) +@respx.mock +async def test_no_key_is_sent_when_the_caller_passes_none( + tool: str, schemas: dict[str, dict[str, Any]] +) -> None: + # A key turns off the API's content duplicate check, so none is invented. + route = respx.route(host="api.test.com").mock( + return_value=httpx.Response(201, json={"id": "x_1"}) + ) + + async with Client(mcp) as client: + await client.call_tool(tool, _required_arguments(schemas[tool])) + + assert "Idempotency-Key" not in route.calls.last.request.headers + + +@pytest.mark.parametrize("tool", sorted(DERIVED_KEY_TOOLS)) +@respx.mock +async def test_ad_tools_keep_their_derived_key_without_a_caller_key( + tool: str, schemas: dict[str, dict[str, Any]] +) -> None: + route = respx.route(host="api.test.com").mock( + return_value=httpx.Response(201, json={"id": "x_1"}) + ) + + async with Client(mcp) as client: + await client.call_tool(tool, _required_arguments(schemas[tool])) + + assert route.calls.last.request.headers["Idempotency-Key"].startswith(f"mcp-{tool}-") + + +@respx.mock +async def test_create_post_retry_with_the_same_key_sends_the_same_header() -> None: + route = respx.post(f"{API}/v1/posts").mock( + return_value=httpx.Response(201, json={"post": {"_id": "p_1"}}) + ) + arguments = { + "content": "Spring sale", + "scheduled_for": "2026-12-01T10:00:00Z", + "platforms": [{"platform": "facebook", "accountId": "acc_1"}], + "idempotency_key": CALLER_KEY, + } + + async with Client(mcp) as client: + await client.call_tool("posts_create_post", arguments) + await client.call_tool("posts_create_post", arguments) + + keys = [call.request.headers["Idempotency-Key"] for call in route.calls] + assert keys == [CALLER_KEY, CALLER_KEY] + assert route.calls.last.request.read() # body still sent alongside the header + + +def test_sdk_create_post_sends_the_header() -> None: + with respx.mock: + route = respx.post(f"{API}/v1/posts").mock( + return_value=httpx.Response(201, json={}) + ) + Late(api_key="k", base_url=API).posts.create_post( + content="x", idempotency_key=CALLER_KEY + ) + + assert route.calls.last.request.headers["Idempotency-Key"] == CALLER_KEY