> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating a Service REST method

> Build a Pega Service REST POST method for exporting files to a case: create the service package, add the PegaAPI role, and define response conditions.

First, you need to create a service package:

1. Click the **Records** tab on the left, expand **Integration Resources**, right-click **Service Package**, and select the **Create** command from the shortcut menu.

2. On the **Create Service Package** form, type *customapi* in the **Service Package Name** field. Provide a description for the package in the **Short description** field and click **Create and open**.

3. On the **Edit Service Package** form, specify an access group in the **Service access group** field (the format of the group is *\<Application\_name>:\<Access group>*).\
   **Note:** To view the list of available access groups, click the **Records** tab on the left and navigate to **Security → Access Group**.

4. Click **Save**.

Next, you need to add a new role to the access group to enable users to access the Web API:

1. Go to the newly created access group by clicking **Records → Security → Access Group → ABBYYFC:Administrators/ABBYYFC:Users**.
2. In the **Available roles** field, add a *PegaRULES:PegaAPI* role.

Now you need to create a new service:

1. Click the **Records** tab on the left, expand **Integration-Services**, right-click **Service REST**, and select the **Create** command from the shortcut menu.
2. On the form that opens, specify the following:
   * Service name: *files*
   * Service package name: *customapi*
   * URI Template: *cases/\{id}/files/\{name}*
   * Service version: *v2*
3. Click **Create and open**.
4. Click the **Service** tab and type *Pega-API-CaseManagement* in the **Pega class** field. In the **URL path parameters** section, type *Param.CaseId* in the **Map to Key** column for the **Id** parameter. Then type *Param.FileName* for the **name** parameter.
5. Click the **Methods** tab. Expand the POST method and on the **Request** tab, specify the following for the **Message data** fields:
   * Description: *Request Data*
   * Map to: *Clipboard*
   * Map to key: *Param.Request*
6. <a id="response" />Click the **Response** tab and create three response conditions:

<table width="100%"><thead><tr><th><p><strong>Process what</strong></p></th><th><p><strong>Parameter values</strong></p></th><th><p><strong>Header fields</strong></p></th><th><p><strong>Message data</strong></p></th></tr></thead><tbody><tr><td><p><strong>pxIsInternalError</strong></p></td><td><ul><li>Condition: <em>When</em></li><li>When name: <em>pxIsInternalError</em></li><li>Content type: <em>application/json</em></li><li>Status code: <em>Param.StatusCode</em></li></ul></td><td> </td><td> </td></tr><tr><td><p><strong>pxIsErrorResponse</strong></p></td><td><ul><li>Condition: <em>When</em></li><li>When name: <em>pxIsErrorResponse</em></li><li>Content type: <em>application/json</em></li><li>Status code: <em>Param.StatusCode</em></li></ul></td><td> </td><td><ul><li>Description: <em>Response</em></li><li>Map from: <em>Clipboard</em></li><li>Map from key: <em>Param.Response</em></li></ul></td></tr><tr><td><p>Success response</p></td><td><ul><li>Condition: <em>Default</em></li><li>Content type: <em>application/json</em></li><li>Status code: <em>Param.StatusCode</em></li></ul></td><td><ul><li>Name: <em>location</em>: Map from: <em>Clipboard</em>; Map from key: <em>Param.Location</em></li><li>Name: <em>etag</em>; Map from: <em>Clipboard</em>; Map from key: <em>Param.eTag</em></li></ul></td><td><ul><li>Description: <em>Response</em></li><li>Map from: <em>Clipboard</em></li><li>Map from key: <em>Param.Response</em></li></ul></td></tr></tbody></table>

<Warning>
  Make sure that the URL of the service method is as follows: *https\://Server\_Name/prweb/PRRestService/customapi/v2/cases/\{id}/files/\{name}.* Otherwise, the connector will return an error when the user attempts to export a file to Pega.
</Warning>
