POST · Gérer les macros

Conversations : Gérer les macros. Paramètres, accès et exemples de réponse.

Rédigé par Red Blue

Mis à jour le

Conversations

POST /api/v1/inbox/macros

operationId : inbox_macros_manage

Accès

Permission

Consentements OAuth

OAuth : délégation d’un équipier pour l’API

support.write

api:connect, support:write

KHONY_ORIGIN est l’origine HTTPS de votre application Khony, sans chemin final. Remplacez les identifiants de l’exemple par ceux de vos ressources autorisées. Les données de réponse ci-dessous illustrent le format ; elles ne sont pas le résultat d’un appel à votre organisation.

Champs du corps JSON

Nom

Emplacement

Requis

Type et contraintes

productId

JSON

Oui

string

request

JSON

Oui

object

Variantes de la requête

Sélecteur

Valeur

Autres champs requis dans request

request.operation

"list"

Aucun autre champ imposé

request.operation

"save"

definition

request.operation

"archive"

macroId, expectedRevision

request.operation

"preview"

macroId, expectedRevision, conversationId, mode, values

request.operation

"run_prepare"

conversationId, operationId, macroId, macroRevision, actions

request.operation

"run_get"

conversationId, operationId

request.operation

"run_list"

conversationId

Choisissez une variante et respectez son schéma complet : les contraintes des champs optionnels et les unions imbriquées restent applicables.

Exemple de requête

Shell
curl --request POST "$KHONY_ORIGIN/api/v1/inbox/macros" \
  --header "Authorization: Bearer $KHONY_ACCESS_TOKEN" \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "productId": "product_01k3w8d7vhe008000000000001",
  "request": {
    "operation": "save",
    "definition": {
      "name": "Diagnostic",
      "scope": "personal",
      "document": {
        "type": "doc",
        "content": [
          {
            "type": "paragraph",
            "content": [
              {
                "type": "text",
                "text": "Diagnostic",
                "marks": [
                  {
                    "type": "bold"
                  }
                ]
              }
            ]
          },
          {
            "type": "callout",
            "attrs": {
              "variant": "info"
            },
            "content": [
              {
                "type": "paragraph",
                "content": [
                  {
                    "type": "text",
                    "text": "Keep the original source document."
                  }
                ]
              }
            ]
          },
          {
            "type": "table",
            "content": [
              {
                "type": "tableRow",
                "content": [
                  {
                    "type": "tableHeader",
                    "content": [
                      {
                        "type": "paragraph",
                        "content": [
                          {
                            "type": "text",
                            "text": "Step"
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "type": "tableHeader",
                    "content": [
                      {
                        "type": "paragraph",
                        "content": [
                          {
                            "type": "text",
                            "text": "Result"
                          }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableRow",
                "content": [
                  {
                    "type": "tableCell",
                    "content": [
                      {
                        "type": "paragraph",
                        "content": [
                          {
                            "type": "text",
                            "text": "Read"
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "type": "tableCell",
                    "content": [
                      {
                        "type": "paragraph",
                        "content": [
                          {
                            "type": "text",
                            "text": "Verified"
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "paragraph",
            "content": [
              {
                "type": "text",
                "text": "Documentation",
                "marks": [
                  {
                    "type": "link",
                    "attrs": {
                      "href": "https://example.test/help"
                    }
                  }
                ]
              }
            ]
          }
        ]
      }
    }
  }
}'
Shell

Réponse de succès · HTTP 200

JSON
{
  "data": {
    "id": "saved_reply_01k3w8d7vhe008000000000007",
    "revision": 1
  }
}
JSON
Schéma complet du corps JSON
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "productId": {
      "type": "string",
      "pattern": "^product_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
    },
    "request": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "list"
            },
            "search": {
              "type": "string",
              "maxLength": 150
            },
            "includeArchived": {
              "type": "boolean"
            },
            "scope": {
              "type": "string",
              "enum": [
                "personal",
                "team",
                "product"
              ]
            },
            "channel": {
              "type": "string",
              "enum": [
                "email",
                "widget"
              ]
            },
            "locale": {
              "type": "string",
              "maxLength": 35
            },
            "cursor": {
              "type": "string",
              "pattern": "^saved_reply_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
            },
            "limit": {
              "default": 20,
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            }
          },
          "required": [
            "operation"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "save"
            },
            "macroId": {
              "type": "string",
              "pattern": "^saved_reply_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
            },
            "expectedRevision": {
              "type": "integer",
              "exclusiveMinimum": 0,
              "maximum": 9007199254740991
            },
            "definition": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 150
                },
                "scope": {
                  "type": "string",
                  "enum": [
                    "personal",
                    "team",
                    "product"
                  ]
                },
                "teamId": {
                  "default": null,
                  "anyOf": [
                    {
                      "type": "string",
                      "pattern": "^support_team_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "surface": {
                  "default": "reply",
                  "type": "string",
                  "enum": [
                    "reply",
                    "note",
                    "both"
                  ]
                },
                "channel": {
                  "default": "all",
                  "type": "string",
                  "enum": [
                    "all",
                    "email",
                    "widget"
                  ]
                },
                "locale": {
                  "default": "und",
                  "type": "string",
                  "maxLength": 35
                },
                "document": {
                  "$ref": "#/$defs/__schema0"
                },
                "variables": {
                  "default": [],
                  "maxItems": 30,
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/__schema2"
                  }
                },
                "actions": {
                  "default": [],
                  "maxItems": 12,
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/__schema3"
                  }
                }
              },
              "required": [
                "name",
                "scope",
                "document"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "operation",
            "definition"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "archive"
            },
            "macroId": {
              "$ref": "#/$defs/__schema4"
            },
            "expectedRevision": {
              "$ref": "#/$defs/__schema5"
            }
          },
          "required": [
            "operation",
            "macroId",
            "expectedRevision"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "preview"
            },
            "macroId": {
              "$ref": "#/$defs/__schema4"
            },
            "expectedRevision": {
              "$ref": "#/$defs/__schema5"
            },
            "conversationId": {
              "$ref": "#/$defs/__schema6"
            },
            "mode": {
              "type": "string",
              "enum": [
                "reply",
                "note"
              ]
            },
            "values": {
              "type": "object",
              "propertyNames": {
                "$ref": "#/$defs/__schema7"
              },
              "additionalProperties": {
                "$ref": "#/$defs/__schema8"
              }
            }
          },
          "required": [
            "operation",
            "macroId",
            "expectedRevision",
            "conversationId",
            "mode",
            "values"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "run_prepare"
            },
            "conversationId": {
              "$ref": "#/$defs/__schema6"
            },
            "operationId": {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            },
            "macroId": {
              "type": "string",
              "pattern": "^saved_reply_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
            },
            "macroRevision": {
              "type": "integer",
              "exclusiveMinimum": 0,
              "maximum": 9007199254740991
            },
            "actions": {
              "minItems": 1,
              "maxItems": 12,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema3"
              }
            },
            "document": {
              "$ref": "#/$defs/__schema0"
            }
          },
          "required": [
            "operation",
            "conversationId",
            "operationId",
            "macroId",
            "macroRevision",
            "actions"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "run_get"
            },
            "conversationId": {
              "$ref": "#/$defs/__schema6"
            },
            "operationId": {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            }
          },
          "required": [
            "operation",
            "conversationId",
            "operationId"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "run_list"
            },
            "conversationId": {
              "$ref": "#/$defs/__schema6"
            }
          },
          "required": [
            "operation",
            "conversationId"
          ],
          "additionalProperties": false
        }
      ]
    }
  },
  "required": [
    "productId",
    "request"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "$ref": "#/$defs/__schema1"
    },
    "__schema1": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema1"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema1"
          }
        }
      ]
    },
    "__schema2": {
      "type": "object",
      "properties": {
        "key": {
          "type": "string",
          "pattern": "^[a-z][a-zA-Z0-9_.]{0,63}$"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "type": {
          "type": "string",
          "enum": [
            "text",
            "number",
            "boolean"
          ]
        },
        "required": {
          "type": "boolean"
        },
        "fallback": {
          "default": "",
          "type": "string",
          "maxLength": 2000
        }
      },
      "required": [
        "key",
        "label",
        "type",
        "required"
      ],
      "additionalProperties": false
    },
    "__schema3": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "assign_user"
            },
            "userId": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "uuid",
                  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                },
                {
                  "type": "string",
                  "const": "me"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "type",
            "userId"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "assign_team"
            },
            "teamId": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^support_team_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "type",
            "teamId"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "priority"
            },
            "priority": {
              "type": "string",
              "enum": [
                "low",
                "normal",
                "high",
                "urgent"
              ]
            }
          },
          "required": [
            "type",
            "priority"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "resolve"
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "reopen"
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "snooze"
            },
            "minutes": {
              "type": "integer",
              "minimum": 1,
              "maximum": 43200
            }
          },
          "required": [
            "type",
            "minutes"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema4": {
      "type": "string",
      "pattern": "^saved_reply_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
    },
    "__schema5": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "__schema6": {
      "type": "string",
      "pattern": "^support_conversation_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
    },
    "__schema7": {
      "type": "string",
      "maxLength": 64
    },
    "__schema8": {
      "type": "string",
      "maxLength": 2000
    }
  }
}
JSON
Schéma complet de la réponse
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "data": {
      "$ref": "#/$defs/__schema0"
    },
    "nextCursor": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^saved_reply_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "data"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        }
      ]
    }
  }
}
JSON

Refus et reprise

Les statuts documentés pour cette opération sont 400, 401, 402, 403, 428, 429, 500, 503. Identifiez la cause avec error.code et, lorsqu’il est présent, error.reason. Une réponse 409 peut demander une relecture de révision ou signaler une commande incompatible ; une réponse 428 demande une confirmation humaine. Ne rejouez une écriture que selon son contrat.

Notes du contrat
JSON
{
  "description": "Requires a dedicated API OAuth bearer for audience /api/v1 plus api:connect and the declared support scope, current product/organization consent, native permissions and source policies. No cookie or MCP-audience token fallback. Commercial admission is shared with the public API. Saves and archives use native revisions/ownership; preparation never applies effects or sends. Native immutable run confirmation is available through the verified human MCP confirmation flow. Native full article documents and variables remain canonical. Reduce page size when the response byte budget is exceeded."
}
JSON