Skip to main content

Surveys - Create Survey

Enterprise

This endpoint is part of Countly Enterprise. To get access, contact sales or compare versions. Existing customers can reach the support portal with questions.

Endpoint

/i/surveys/survey/create

Overview

Creates a Survey widget.

Authentication

Pass api_key or auth_token as a query parameter, or send countly-token as a header. See Authentication.

Permissions

  • Surveys: Create permission.

Request Parameters

ParameterTypeRequiredDescription
api_keyStringYes (or auth_token)API key authentication
auth_tokenStringYes (or api_key)Auth token authentication
app_idStringYesApp ID
nameStringYesWidget display name
internalNameStringYesInternal widget name
statusBoolean/StringYesInitial active status
msgString (JSON Object)YesMessage text object
questionsString (JSON Array)YesSurvey questions
appearanceString (JSON Object)NoAppearance configuration
targetingString (JSON Object)NoTargeting rules/cohort source

Examples

/i/surveys/survey/create?api_key=YOUR_API_KEY&app_id=YOUR_APP_ID&name=Product Feedback&internalName=product_feedback_v1&status=true&msg={"thanks":"Thank you"}&questions=[{"id":"q1","type":"text","question":"How can we improve?","required":false}]

Response

Success Response

{
"result": {
"_id": "67b9db56f67aab0012cd8899",
"text": "Successfully created 67b9db56f67aab0012cd8899"
}
}

Response Fields

FieldTypeDescription
resultObjectCreate result wrapper
result._idStringCreated widget ID
result.textStringSuccess message

Error Responses

  • HTTP 400 - Invalid params:
{
"result": "Invalid params: ..."
}
  • HTTP 400 - Missing questions:
{
"result": "Missing params: 'questions'"
}
  • HTTP 400 - DB create failure:
{
"result": "Failed to create widget(DB error)"
}

Behavior

  • Parses and preprocesses widget properties such as msg, appearance, targeting, and questions.
  • Validates Survey payload with Survey form property rules.
  • Requires non-empty questions and validates each question definition before insert.
  • Creates a feedback_widgets record with type=survey, creator, created, responded=0, shown=0, and wv=1.
  • Uploads logo when provided and records it in appearance.logo; if upload fails, the widget can still be created and the response includes the new widgetId with an error.
  • Creates a linked cohort when targeting is provided, stores its ID as cohortID, and emits surveys_widget_created.

Limitations

  • Requires valid non-empty questions array.
Implementation details

Database Collections

CollectionUsed forData touched by this endpoint
countly.feedback_widgetsEndpoint data sourceStores endpoint-related records this endpoint reads or modifies.
countly.cohortsEndpoint data sourceStores endpoint-related records this endpoint reads or modifies.