Apply Template to Campaign ========================== +-------------------------------------------------------------------------+-------------------+-----------------+ | URL | Required Values | HTTP Methods | +=========================================================================+===================+=================+ | https://app.tingting.io/api/v1/survey-templates//apply-to-campaign/ | campaign_id | POST | +-------------------------------------------------------------------------+-------------------+-----------------+ Applies a survey template to an existing SURVEY campaign. Replace ```` with the template ID. This action: - Copies ``voice`` and ``length_factor`` from the template to the campaign. - Deletes all existing steps from the campaign's survey. - Creates new ``SurveyStep`` records from the template's ``content``. **Request Body:** +-------------+---------+----------+-------------------------------------------------------------------+ | Field | Type | Required | Description | +=============+=========+==========+===================================================================+ | campaign_id | integer | Yes | ID of the target campaign. Must be a SURVEY campaign owned by the | | | | | user. | +-------------+---------+----------+-------------------------------------------------------------------+ Sample Request: .. code-block:: json { "campaign_id": 42 } Sample Response — Success (201 Created): .. code-block:: json { "message": "Template applied successfully.", "steps": [ { "id": 101, "order": 0, "content_type": "say", "response_type": "dtmf", "input_name": "rating", "audio_file": null, "survey": 15 }, { "id": 102, "order": 1, "content_type": "info", "response_type": "none", "input_name": "outro", "audio_file": null, "survey": 15 } ] } Sample Response — Partial success, some steps failed (207 Multi-Status): .. code-block:: json { "created": [ { "id": 103, "order": 0 } ], "errors": [ { "content_type": ["This field is required."] } ] } **Error Responses (400 Bad Request):** Missing ``campaign_id``: .. code-block:: json { "error": "campaign_id is required." } Campaign is not a SURVEY type: .. code-block:: json { "error": "Template can only be applied to SURVEY campaigns." } Template has no steps: .. code-block:: json { "error": "Template has no steps to apply." } **Error Responses (404 Not Found):** Template not found or not owned by user: .. code-block:: json { "detail": "No SurveyTemplate matches the given query." } Campaign not found: .. code-block:: json { "error": "Campaign not found." }