Skip to main content

Surveys - Create NPS

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/nps/create

Overview

Creates an NPS 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)YesNPS message object
followUpTypeStringNoFollow-up mode
appearanceString (JSON Object)NoAppearance configuration
targetingString (JSON Object)NoTargeting rules/cohort source

Examples

/i/surveys/nps/create?api_key=YOUR_API_KEY&app_id=YOUR_APP_ID&name=NPS Q1&internalName=nps_q1&status=true&msg={"mainQuestion":"How likely are you to recommend us?"}

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 - DB create failure:
{
"result": "Failed to create widget(DB error)"
}

Behavior

  • Parses and preprocesses widget properties such as msg, appearance, and targeting.
  • Validates NPS payload with NPS form property rules.
  • Creates a feedback_widgets record with type=nps, creator, created, responded=0, shown=0, wv=1, and scores={total,promoter,detractor,passive} initialized to zero.
  • 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.
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.