Skip to main content

Metric expression prompts

tip

You can try out this workflow at REST API Playground.

Learn more about MicroStrategy REST API Playground here.

A metric expression element prompt is one of the most commonly used prompt types. It allows the caller to provide an expression to filter the data in a report or dashboard. For example, you define a prompt as "Get data when Avg Revenue per Customer is greater than 10".

Use REST APIs to perform the following actions on metric expression prompts:

Create a new prompt

  1. To create a metric expression prompt, you must enter the required fields with the correct information, using POST /api/model/prompts.

  2. The response can change based on the request parameters provided by the caller. Use the following parameters.

    LocationNameDescription
    headerX-MSTR-authTokenThe authorization token
    headerX-MSTR-ProjectIDThe ID of the project
    headerX-MSTR-MS-ChangesetThe ID of the changeset
    queryshowExpressionAsThe parameter that specifies the format in which the response is returned.
  3. The model for the definition of a metric expression prompt can be represented using the fields below. "objectID", "dateCreated", "dateModified", and "versionId" are automatically generated.

    FieldsNameDescriptionData TypeRequired?
    informationnameThe name of the prompt. This should be a user-friendly name for identifying the prompt.string✔️
    informationsubTypeThe type of prompt. The "subType" for a metric expression prompt is "prompt_expression".string✔️
    informationdestinationFolderIdThe folder ID where the new prompt is saved.string✔️
    expressionTypeDifferentiates between the three expression types for an expression prompt. This field is required when the "subType" in "information" is "prompt_expression". This field should be "metric" for metric expression prompts.string✔️
    titleThe title of the prompt.string
    instructionThe instruction on how to apply the prompt.string
    questionpredefinedObjectsA list of predefined metrics with "objectId", "subType", and "name".string
    questionsearchA standalone search object with "objectId", "subType", and "name". "search" and "predefinedObjects" should have an XOR relationship, since only one of them has a value.string
    defaultAnswerqualificationA qualification set used to define the default answer. It follows the "tree" format of the qualification in the filter request.string
    restrictionrequiredAn indicator that specifies whether a prompt answer is required or not.boolean
    restrictionmaxElementPerSelectionThe maximum number of elements per selectioninteger
    restrictionallowPersonalAnswersAn indicator that specifies whether personal answers are allowed. It can be set to "none", "single", or "multiple".string
    restrictionminThe minimum number of qualifications that can be added.integer
    restrictionmaxThe maximum number of qualifications that can be added.integer

    Sample code for creating a metric expression prompt's definition is provided below.

    {
    "information": {
    "destinationFolderId": "8A1831FF494F528D02A4A8BF5FB73459",
    "subType": "prompt_expression",
    "name": "Metric Prompt with Custom Expression"
    },
    "title": "Metric qualification",
    "instruction": "Choose a metric to begin building a qualification.",
    "expressionType": "metric",
    "question": {
    "predefinedObjects": [
    {
    "objectId": "7FD5B69611D5AC76C000D98A4CC5F24F",
    "subType": "metric",
    "name": "Cost"
    },
    {
    "objectId": "381980B211D40BC8C000C8906B98494F",
    "subType": "metric",
    "name": "Discount"
    }
    ]
    },
    "defaultAnswer": {
    "qualification": {
    "text": "Cost = Discount + 4",
    "tree": {
    "type": "predicate_metric_qualification",
    "predicateId": "8126CF7F22C847AE8A112F3ABA5A27DA",
    "predicateText": "Cost = Discount + 4",
    "predicateTree": {
    "function": "equals",
    "parameters": [
    {
    "parameterType": "expression",
    "expression": {
    "text": "Discount + 4"
    }
    }
    ],
    "levelType": "none",
    "metric": {
    "objectId": "7FD5B69611D5AC76C000D98A4CC5F24F",
    "subType": "metric",
    "name": "Cost"
    },
    "metricFunction": "value",
    "isIndependent": 0,
    "nullInclude": 0
    }
    }
    }
    },
    "restriction": {
    "required": false,
    "allowPersonalAnswers": "none",
    "min": 3,
    "max": 10
    }
    }

Update an existing prompt

  1. Update the definition of a metric expression prompt using PUT /api/model/prompts/{promptId}.

  2. Provide the following headers in the request:

    LocationNameDescription
    headerX-MSTR-authTokenThe authorization token
    headerX-MSTR-ProjectIDThe ID of the project
    headerX-MSTR-MS-ChangesetThe ID of the changeset
  3. In addition to the above header, you should also provide the ID of the prompt you want to update.

  4. You can modify the fields shown below. The "subType" field is not included below since it cannot be modified through this REST API.

    FieldsNameDescriptionData Type
    informationnameThe name of the prompt. This should be a user-friendly name for identifying the prompt.string
    informationdestinationFolderIdThe folder ID where the new prompt is saved.string
    expressionTypeDifferentiates between the three expression types for an expression prompt. This field is required when the "subType" in "information" is "prompt_expression". This field should be "metric" for metric expression prompts.string
    titleThe title of the prompt.string
    instructionThe instruction on how to apply the prompt.string
    questionpredefinedObjectsA list of predefined metrics with "objectId", "subType", and "name".string
    questionsearchA standalone search object with "objectId", "subType", and "name". "search" and "predefinedObjects" should have an XOR relationship, since only one of them has a value.string
    defaultAnswerqualificationA qualification set used to define the default answer. It follows the "tree" format of the qualification in the filter request.string
    restrictionrequiredAn indicator that specifies whether a prompt answer is required or not.boolean
    restrictionmaxElementPerSelectionThe maximum number of elements per selectioninteger
    restrictionallowPersonalAnswersAn indicator that specifies whether personal answers are allowed. It can be set to "none", "single", or "multiple".string
    restrictionminThe minimum number of qualifications that can be added.integer
    restrictionmaxThe maximum number of qualifications that can be added.integer