LinkedIn
Copied!

Table of Contents

Creating a response for Service REST methods by using an activity implementation

Version:

Only available versions of this content are shown in the dropdown

For the GET, PUT, POST, PATCH, and DELETE methods, specify how the service rule constructs the response that Pega Platform sends in reply to the request. You can set up more than one response, based on conditions. You can also specify additional HTTP response codes to send with the response.

Create the request for your service. For more information, see Service REST methods.

If you do not configure any responses, at run time, Pega Platform returns one of the following HTTP response codes by default:

  • 200 – The request was processed without any errors.
  • 500 – An error occurred during processing.
  • 401 – An authentication problem occurred.
  1. In your Service REST rule, click the Methods tab, and then click the method for which you want to construct a response.

  2. Click the Response tab.

  3. In the Condition field, select one of the following conditions:

    • Default – Send this response when there are no errors to report. If you plan to set up more than one condition, configure the Default condition as the last one in the list. To send an HTTP response code other than 200, specify a different code for the Default condition in the HTTP status code field.
    • When – The system evaluates the when condition specified by the When field. If the condition is true, the system returns the response message data. If the condition is false, the system evaluates the next when condition rule in the list. If all of the listed when condition rules are false, the system returns the default response data. Use this feature to extend the normal set of fatal error conditions that result in exceptions returned to the client, such as inappropriate inputs to the service activity, or other tests that you define.
    • Queue when – The system evaluates the when condition rule specified by the When field. If the condition evaluates to true, the system queues the service request and returns the queue item ID of the service request. If you configure a Queue When condition, you must specify a request processor in the Request Processor field on the Service tab. For more information, see Defining resource and processing details for a Service REST rule.
    • Mapping error – If an error occurs while mapping incoming data from a request message to the clipboard, the service returns the specified response message data. If the list of response conditions does not include an entry for mapping errors, Pega Platform returns the HTTP status code 500.
    • Security error – If an error occurs while authenticating the client credentials, Pega Platform returns the specified response message data. If the list of response conditions does not include an entry for security errors, Pega Platform returns the HTTP status code 401.
    • Service error – If a service error occurs, the system sends the specified response message data. If the list of response conditions does not include an entry for service errors, Pega Platform returns a standard error message.
  4. If you set the conditional value to When or Queue when in step 3, in the When field, specify the name (the second key part) of a when condition rule to evaluate for this condition.

    The system uses the first key part (the Applies To class) of the service activity as the first key part of the when condition rule.
  5. In the Response type field, select the type of response that you want to return to the external application.

    The default response is application/json.
  6. Optional:

    In the HTTP status code field, enter an HTTP status code to return to the external application with the response.

  7. If the response is to include a header other than the default headers, complete the following fields in the Headers section:

    Pega Platform provides the content-type default response header. Pega Platform accepts all standard, valid HTTP headers.
    1. In the Name field, enter the external name of the header field.

    2. In the Description field, enter a short description of the header field.

    3. In the Map from field, specify the source or the type of source of the value in Pega Platform:

      • Clipboard – Map from the page name or property on the clipboard specified by the Map from key field, or map from a parameter by specifying param.<some param name>.
      • Constant – The data is a fixed value.
    4. In the Map from key field, specify the key to locating the property or rule in the source specified in the Map from field:

      • If the Map from value is Clipboard, enter the property name to which the data is mapped at run time.
      • If the Map from value is Constant, enter the value of the constant, surrounded by double quotation marks.
  8. In the Message data section, complete the following steps:

    1. In the Description field, enter a short description for the incoming string.

    2. In the Map from field, specify the source or the type of source of the value in Pega Platform:

      • Clipboard – The source is a property or a page on the clipboard.
      • Constant – The source is a fixed value that does not change.
      • JSON – The source is a stream of JSON data formatted by a Page or Page List property.
      • XML stream – The source is a stream of XML data formatted by an XML Stream rule.
      • HTML stream – The source is a stream of HTML data formatted by an HTML rule.
      • HTML frame – The source is a stream of HTML data generated by the service activity.
    3. In the Map from key field, specify the key to locating the property or rule in the source specified in the Map from field.

  9. If you selected JSON in the Map to field, in the Mapping method field, choose the method to filter the response.

    • To automatically map all properties with the clipboard, select Use fast processing. If you selected Use fast processing in an earlier version of Pega Platform, this option is selected by default.
    • To customize the mapping of properties with the clipboard, select Use JSON data transformation. Then, in the JSON data transform field, press the Down Arrow key to select an existing JSON data transform, or enter a new JSON data transform.
    • To refer to a property qualifier to generate the JSON, select Use legacy method.
  10. Click Save.

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.