{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":48492,"path":"servicenow-platform/orchestration/t_CreateARESTWebServiceActivity.md","title":"Create a REST web service activity","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create a REST web service activity\n\nUse this procedure to create a custom REST web service Orchestration activity.\n\n## Before you begin\n\nRole required: web\\_service\\_admin, activity\\_admin, activity\\_creator\n\n## About this task\n\nTo create and use a REST web service workflow activity:\n\n-   Create a [Create a REST message](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/t_ConfiguringARESTMessage.md) if an appropriate one is not already configured.\n-   Assign the web\\_service\\_admin role to any user who must create or edit a custom REST activity.\n-   Determine an application, or [Application scope](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/application-development/c_ApplicationScope.md), for this activity.\n-   Determine the [Create a REST message](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/t_ConfiguringARESTMessage.md) to use for the activity. Use this value to override the endpoint configured in the REST message.\n-   Optionally, create [basic authentication credentials](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/r_BasicAuthCredentialsForm.md). Use this value to override the credentials configured in the SOAP message.\n\n## Procedure\n\n1.  Create a [custom activity](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/integrate-applications/create-custom-activities.md).\n\n    This action creates a custom activity using a template.\n\n2.  After setting up [general properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/General-Flds-Templates.md) and [creating input variables](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/CreateInputVariables.md), configure the REST web service Execution Command.\n\n<table id=\"choicetable_g3y_2sq_vz\"><tbody><tr><td id=\"d358868e146\">\n\n**[Map the input variables](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/CreateInputVariables.md)**\n\n</td><td>\n\nUse the variables you created to configure the command that Orchestration executes.\n\n</td></tr><tr><td id=\"d358868e162\">\n\n**REST message**\n\n</td><td>\n\nName of an existing REST message to use in this activity.\n\n</td></tr><tr><td id=\"d358868e171\">\n\n**REST message function**\n\n</td><td>\n\nREST message function to use for this activity.\n\n</td></tr><tr><td id=\"d358868e180\">\n\n**Endpoint**\n\n</td><td>\n\nEndpoint URL for the REST web service this activity uses. Enter an endpoint in this field to override the endpoint configured in the REST message. Click the lock to open the input field.\n\n</td></tr><tr><td id=\"d358868e189\">\n\n**Variable substitutions**\n\n</td><td>\n\nName-value pairs to pass to the REST endpoint. You can create these parameters manually, or drag input variables into the parameter fields, and then assign a value. Parameters defined in the REST message that use **$\\{\\}** can be assigned data from this activity template. Use the **Additional attribute** column to configure the system to not escape the text. By default the text sent to the REST message is escaped. If the users have provided variables using [Variable substitution in outbound REST messages](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/c_VariableSubstitutionREST.md) in the REST message, then the **Name** column is automatically populated.\n\n</td></tr><tr><td id=\"d358868e212\">\n\n**Additional Headers**\n\n</td><td>\n\nAdditional HTTP header parameters for the REST message selected. You can also use these values to override parameters inherited from the REST message.\n\n</td></tr><tr><td id=\"d358868e221\">\n\n**Additional Query Parameters**\n\n</td><td>\n\nAdditional query parameters for the REST message selected. You can also use these values to override parameters inherited from the REST message.\n\n</td></tr><tr><td id=\"d358868e230\">\n\n**Use MID Server**\n\n</td><td>\n\nCheck box that determines if a MID Server should be used to invoke the REST web service.**Note:** If the REST web service message function defines a MID Server, that MID Server is used instead of the one selected here.\n\n</td></tr><tr><td id=\"d358868e242\">\n\n**Required MID Server capabilities**\n\n</td><td>\n\nMID Server with the appropriate [MID Server capabilities](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown) for connecting to the REST endpoint. By default, the system selects a MID Server with REST capabilities. This field is available when the **Use MID Server** check box is selected.\n\n</td></tr><tr><td id=\"d358868e262\">\n\n**Timeout**\n\n</td><td>\n\nAllowed duration of the REST web service request before it times out, in seconds. The default is **10**.\n\n</td></tr><tr><td id=\"d358868e274\">\n\n**Authentication**\n\n</td><td>\n\nDetermines what type of authentication is required for the endpoint. The options are:-   **Use existing credentials in REST message**: Uses credential definitions from the REST message definition.\n-   **Override with Basic Authentication credentials**: Uses [Enable basic authentication for outbound SOAP](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/t_BasicAuthentication.md) credentials to override the credentials in the REST message definition. Basic authentication credentials must be provisioned before they are available for selection.\n-   **Override with Certificate Authentication credentials**: Uses a certificate, such as a private key, to override the credentials in the REST message definition.\n-   **Override with Both Basic and Certificate Authentication credentials**: Uses both basic authentication and certificate authentication to override the credentials in the REST message definition.\n-   **Override with OAuth Authentication credentials**: Uses [OAuth 2.0](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/c_OAuthApplications.md) credentials to override the credentials in the REST message definition. The REST message selected for this activity must have its [OAuth 2.0 tutorial - create a REST message](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/t_OAuthDemoCreateRESTMessage.md) set to **OAuth 2.0** and its [OAuth profiles and scopes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/c_OAuthProviderAndScope.md) configured appropriately.\n\n\n</td></tr><tr><td id=\"d358868e331\">\n\n**Credentials**\n\n</td><td>\n\nRequired REST endpoint basic authentication credentials. This field is available when **Override with Basic Authentication credentials** is selected in the **Authentication** field. Only basic authentication credentials appear in the selection list, which includes credentials stored on the instance and credential IDs from an external storage system. If you are using credentials stored in a CyberArk safe, you can override the default safe defined in the MID Server configuration file. See [Configure the MID Server for CyberArk](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/c_CyberArkIntegrationConfiguration.md) for details. Add the name of a different safe as a prefix to the credential ID, separated by a colon. For example, **newsafe:orch-test-f5**.\n\n</td></tr><tr><td id=\"d358868e353\">\n\n**Protocol Profile**\n\n</td><td>\n\nCertificate authentication to use. This field is available when the selections in the **Authentication** are either **Override with Certificate Authentication credentials** or **Override with Both Basic and Certificate Authentication credentials**.\n\n</td></tr><tr><td id=\"d358868e371\">\n\n**OAuth profile**\n\n</td><td>\n\nProfile for the OAuth provider for this REST message. See [Specify an OAuth profile](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/t_SpecifyAnOAuthProfile.md) for more information.\n\n</td></tr></tbody>\n</table>    **Note:** You can map parameter values in a test payload to variables in the **Outputs** tab automatically. See [automap output variables](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/automap-output-variable-inputs.md).\n\n\n## What to do next\n\nFinish creating your Rest web service activity by [creating output variables](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/t_CreateAnOutputVariable.md), [creating a parsing rule](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/t_CreateAParsingRule.md), or [Conditions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/integrate-applications/conditions.md). Refer to the [create custom activities](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/create-custom-activities.md) topic to know your template options.\n\n**Parent Topic:**[Orchestration custom activity templates](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/c_ActivityDesignerComponents.md)\n\n## Auto-map REST activity output variables\n\nThe ServiceNow activity designer allows you to map parameter values in a REST test payload to variables in the **Outputs** stage automatically.\n\n### Before you begin\n\nRole required: web\\_service\\_admin, activity\\_admin, activity\\_creator\n\n### About this task\n\n**Note:** You can test input variables from any stage in the activity designer if you have provided enough information for Orchestration to contact the endpoint and return data. Typically, the **Execution Command** stage is the point at which your inputs are ready for testing.\n\n### Procedure\n\n1.  In the activity designer, proceed to the **Execution Command** stage.\n\n2.  Define an appropriate MID Server, if requested.\n\n    The test fails if the MID Server cannot be found or if it cannot connect to the target.\n\n3.  Click **Test Activity** to test the input parameters.\n\n    If you added actual values for the parameters and fields, the system runs those values against the specified target and returns the resulting payload. If you mapped input variables to fields and parameters, the system displays a dialog box for assigning test values to those variables.\n\n4.  Provide test values, if requested, and click **OK** to display the payload.\n\n    The entire payload appears in the **Raw Output** tab of the Response form.\n\n    \\[Omitted image \"AutoMappingButtons.png\"\\] Alt text: Auto-mapping controls\n\n5.  Select one of these auto-mapping options.\n\n    -   **Auto-Map to Local**: Directly maps values to a local variable for use within the activity.\n    -   **Auto-Map to Output**: Directly maps values to the output variable to pass to other activities in the workflow. Auto-mapping to an output variable creates an array of objects, each of which contains the column names from the query result.\n\n## REST template execution parameters\n\nYou use execution parameters to create the input process script in the **Pre Processing** form of the activity designer.\n\nFor descriptions of the REST web service command fields, see [Configure the REST execution command](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/t_CreateARESTWebServiceActivity.md).\n\n**Note:** You must use the `executionParam.` prefix with all variables in this table.\n\n<table id=\"table_oyb_xdb_dr\"><thead><tr><th>\n\nName\n\n</th><th>\n\nVariable\n\n</th><th>\n\nType\n\n</th><th>\n\nUsage\n\n</th></tr></thead><tbody><tr><td>\n\nWeb service message\n\n</td><td>\n\nweb\\_service\\_message\n\n</td><td>\n\nReference\n\n</td><td>\n\nThe sys\\_id of the corresponding web service message.\n\n</td></tr><tr><td>\n\nWeb service message function\n\n</td><td>\n\nweb\\_service\\_message\\_function\n\n</td><td>\n\nReference\n\n</td><td>\n\nThe sys\\_id of the REST message function.\n\n</td></tr><tr><td>\n\nWeb service endpoint\n\n</td><td>\n\nweb\\_service\\_endpoint\n\n</td><td>\n\nString\n\n</td><td>\n\nURL of the REST endpoint.\n\n</td></tr><tr><td>\n\nParameters\n\n</td><td>\n\nparameters\n\n</td><td>\n\nArray of JavaScript objects\n\n</td><td>\n\nArray of JavaScript objects, expressed with the `executionParam.` prefix. For instructions on creating arrays using this parameter see [Create a JavaScript array in a REST template](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/t_CreateARESTWebServiceActivity.md).\n\n</td></tr><tr><td>\n\nUse mid server\n\n</td><td>\n\nuse\\_mid\\_server\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nSelects whether or not to use the MID Server. A value of **true** uses the MID Server, and a value of **false** does not use the MID Server.\n\n</td></tr><tr><td>\n\nMidCapabilities\n\n</td><td>\n\nmidCapabilities\n\n</td><td>\n\nString \\(comma separated\\)\n\n</td><td>\n\nList of references to required MID Server capabilities.\n\n</td></tr><tr><td>\n\nTime out\n\n</td><td>\n\ntime-out\n\n</td><td>\n\nString\n\n</td><td>\n\nAllowable time out duration, expressed in seconds.\n\n</td></tr><tr><td>\n\nValueCapabilities\n\n</td><td>\n\nvalueCapabilities\n\n</td><td>\n\nArray of hashmap\n\n</td><td>\n\nCapability values used to select the MID Server. For more information, see [MID Server capabilities](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown). Use this example to customize the MID Server selection if there are additional capabilities that are assigned by value:```\nvar valueCapability = {'NEW_MID_CAPABIILTY':'NEW_MID_CAPABILITY_VALUE'}; executionParam.valueCapabilities.push(valueCapability);\n```\n\n</td></tr><tr><td>\n\nAuth Type\n\n</td><td>\n\nauth-type\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nType of credentials to use. The choices are:-   basic\\_auth\\_pick\\_credentials\n-   use\\_existing\\_credentials\n\n</td></tr><tr><td>\n\nCredentials\n\n</td><td>\n\ncredentials\n\n</td><td>\n\nReference\n\n</td><td>\n\nContains the credentials to use for this REST message when the **auth\\_type** selected is **basic\\_auth\\_pick\\_credentials**.\n\n</td></tr></tbody>\n</table>## Create a JavaScript array in a REST template\n\nThese are instructions for creating JavaScript arrays using REST execution parameters.\n\n### Before you begin\n\nRole required: web\\_service\\_admin, activity\\_admin, activity\\_creator\n\n### About this task\n\nTo add more name-value pairs to the parameter's array, append the values to the existing array.\n\n### Procedure\n\n1.  Create a JavaScript object with the following syntax, and add it to the `executionParam.parameter` array:\n\n    ```\n    var newParameter = {\"name\":\"parameterName\",\"value\":\"parameterValue\",\"additional_attribute\":\"none\"}; \n    executionParam.parameters.push(newParameter);\n    ```\n\n    By adding the new parameter JavaScript object to the array, you ensure that any elements already available in the array are not impacted.\n\n2.  Make sure to set the value in the **Additional attribute** column in the **REST message parameters** input field to **Do not escape text**.\n\n    In this case, the system does not escape the value specified for the **value** attribute. An example of this is:\n\n    ```\n    var newParameter = {\"name\":\"parameterName\",\"value\":\"parameterValue\",\"additional_attribute\":\"do_not_escape_text\"}; \n    executionParam.parameters.push(newParameter);\n    ```\n\n    **Note:** If the value for the **additional\\_attribute** field is **None**, then the system escapes the value specified by the **value** attribute. In the first example, `parameterValue` is escaped.\n\n\n## REST template post-processing parameters\n\nUse these parameters to create a post-processing script.\n\n|Name|Variable|Type|Usage|\n|----|--------|----|-----|\n|Status code|status\\_code|Integer|Contains the status code returned from the REST web service.|\n|Header|header|Hashmap of JavaScript object|Hashmap of key value pairs associated with the header values passed into the web service. You can access each value with `executionResult.header[keyName]`.|\n|Body|body|String|Contains a string value representing the output from the REST message|\n|Error|error|String|Returns the error string from the REST web service, unless there are no errors, in which case it returns**null**.|\n\n## Configure the REST execution command\n\nUse the input variables you created to configure the command that Orchestration executes on the REST endpoint.\n\n### Before you begin\n\nCreate the input variables you need in the **Inputs** form before you can advance to the **Execution Command** stage.\n\nRole required: web\\_service\\_admin, activity\\_admin, activity\\_creator\n\n**Note:** You can test the REST connection between the MID Server and the endpoint without having to run the acvitity in a workflow context. For details, see [test template outputs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/CreateInputVariables.md).\n\n### Procedure\n\n1.  Drag variables from the list of inputs and drop them into command fields.\n\n    The system formats the variable in the proper syntax for the command.\n\n    \\[Omitted image \"RESTExecutionCommand.png\"\\] Alt text: REST execution command\n\n2.  Complete the fields shown in the table.\n\n<table id=\"table_bmf_m1b_dr\"><thead><tr><th>\n\nField\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nInput\n\n</td><td>\n\nInput variable builder. [Create input variables](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/servicenow-platform/orchestration/CreateInputVariables.md) to map to available fields.\n\n</td></tr><tr><td>\n\nREST message\n\n</td><td>\n\nName of an existing REST message to use in this activity. Users must have the web\\_service\\_admin role to configure this field.\n\n</td></tr><tr><td>\n\nREST message function\n\n</td><td>\n\nREST message function to use for this activity. Users must have the web\\_service\\_admin role to configure this field.\n\n</td></tr><tr><td>\n\nEndpoint\n\n</td><td>\n\nEndpoint URL for the REST web service this activity uses. Enter an endpoint in this field to override the endpoint configured in the REST message. Click the lock to open the input field.\n\n</td></tr><tr><td>\n\nVariable substitutions\n\n</td><td>\n\nName-value pairs to pass to the REST endpoint. You can create these parameters manually, or drag and drop input variables into the parameter fields, and then assign a value. Parameters defined in the REST message that use **$\\{\\}** can be assigned data from this activity template. Use the **Additional attribute** column to configure the system to not escape the text. By default the text sent to the REST message is escaped. The **Name** column is automatically populated if the users have provided variables using [Variable substitution in outbound REST messages](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/c_VariableSubstitutionREST.md) in the REST message.\n\n</td></tr><tr><td>\n\nAdditional Headers\n\n</td><td>\n\nAdditional HTTP header parameters for the REST message selected. You can also use these values to override parameters inherited from the REST message.\n\n</td></tr><tr><td>\n\nAdditional Query Parameters\n\n</td><td>\n\nAdditional query parameters for the REST message selected. You can also use these values to override parameters inherited from the REST message.\n\n</td></tr><tr><td>\n\nUse MID Server\n\n</td><td>\n\nCheck box that determines if a MID Server should be used to invoke the REST web service.**Note:** If the REST web service message function defines a MID Server, that MID Server is used instead of the one selected here.\n\n</td></tr><tr><td>\n\nRequired MID Server capabilities\n\n</td><td>\n\nMID Server with the appropriate [MID Server capabilities](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown) for connecting to the REST endpoint. By default, the system selects a MID Server with REST capabilities. This field is available when the **Use MID Server** check box is selected.\n\n</td></tr><tr><td>\n\nTimeout\n\n</td><td>\n\nAllowed duration of the REST web service request before it times out, in seconds. The default is **10**.\n\n</td></tr><tr><td>\n\nAuthentication\n\n</td><td>\n\nDetermines what type of authentication is required for the endpoint. The options are:-   **Use existing credentials in REST message**: Uses credential definitions from the REST message definition.\n-   **Override with Basic Authentication credentials**: Uses [Enable basic authentication for outbound SOAP](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/t_BasicAuthentication.md) credentials to override the credentials in the REST message definition. Basic authentication credentials must be provisioned before they are available for selection.\n-   **Override with Certificate Authentication credentials**: Uses a certificate, such as a private key, to override the credentials in the REST message definition.\n-   **Override with Both Basic and Certificate Authentication credentials**: Uses both basic authentication and certificate authentication to override the credentials in the REST message definition.\n-   **Override with OAuth Authentication credentials**: Uses [OAuth 2.0](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/c_OAuthApplications.md) credentials to override the credentials in the REST message definition. The REST message selected for this activity must have its [OAuth 2.0 tutorial - create a REST message](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/t_OAuthDemoCreateRESTMessage.md) set to **OAuth 2.0** and its [OAuth profiles and scopes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/c_OAuthProviderAndScope.md) configured appropriately.\n\n\n</td></tr><tr><td>\n\nCredentials\n\n</td><td>\n\nRequired REST endpoint basic authentication credentials. This field is available when **Override with Basic Authentication credentials** is selected in the **Authentication** field. Only basic authentication credentials appear in the selection list, which includes credentials stored on the instance and credential IDs from an external storage system. If you are using credentials stored in a CyberArk safe, you can override the [Configure the MID Server for CyberArk](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/t_ConfigureTheMIDServerForCyberArk.md) defined in the MID Server configuration file by adding the name of a different safe as a prefix to the credential ID, separated by a colon. For example, **newsafe:orch-test-f5**.\n\n</td></tr><tr><td>\n\nProtocol Profile\n\n</td><td>\n\nCertificate authentication to use. This field is available when the selections in the **Authentication** field is either **Override with Certificate Authentication credentials** or **Override with Both Basic and Certificate Authentication credentials**.\n\n</td></tr><tr><td>\n\nOAuth profile\n\n</td><td>\n\nProfile for the OAuth provider for this REST message. See [Specify an OAuth profile](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/web-services/t_SpecifyAnOAuthProfile.md) for more information.\n\n</td></tr></tbody>\n</table>3.  Click **Save**.\n\n4.  Click **Continue** to advance to the **Outputs** stage.\n\n\n"}}