> ## 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 DELETE method for files

> Add a DELETE method to your Pega Service REST and a DeleteFiles activity that removes file attachments from a case by matching file name and case ID.

In Pega, you can create a Service REST containing both POST and DELETE methods. To create a DELETE method:

1. Open the previously created [POST method](/flexi-capture/connectors/pega/pega-create-app-web-api) by clicking **Records → Integration-Services → Service REST → cases/\{id}/files/\{name}** and then open the **Methods** tab.
2. Expand the DELETE method and open the **Response** tab.
3. Create three conditions identical to the conditions you created on the **Response conditions** tab of the [POST method](/flexi-capture/connectors/pega/pega-create-app-web-api#response).

Next, you need to create an activity named *DeleteFiles*:

1. In the **Activity name** field, type *DeteleFiles*, and then click the target icon on the right, and then click **Create and open** on the **Create Property** form.
2. On the **Pages & Classes** tab, create a new page named *pyWorkPage* of the *Work-* class.
3. On the **Parameters** tab, create three variables:
   * currentLinkedRefTo of type *String*
   * IsConverted of type *Boolean*
   * currentFileId of type *String*
4. On the **Steps** tab, complete the following steps:
   1. Open and load your case into the **pyWorkPage** page using the *Obj-Open-By-Handle* method. Use *Param.CaseId* parameter as the case identifier (this parameter can be taken from the */cases/****\{id}**\*\*/files/\{name}* request).
   2. Delete all files from the case attachment. To do this, type *Property-Set* in the **Method** field, and then open **Loop**, select **For each element in value list**, and type *pyWorkPage.pyAttachments* in the **Value List Property** field. Add the following two new parameters to the method:\
      *Local.currentLinkedRefTo – pyWorkPage.pyAttachments(\<CURRENT>).pxLinkedRefTo;*\
      *Local.currentFileId – pyWorkPage.pyAttachments(\<CURRENT>).pzInsKey;*
   3. Create a *Call DeleteAttachment* activity call and in the **Target** field and specify *pyWorkPage*. Set the *WorkPageName* parameter to *Local.currentLinkedRefTo* and the *LinkHandle* parameter to *Local.currentFileId*.
   4. In the **When** field, specify the following condition: if *Param.FileName = pyWorkPage.pyAttachments(\<CURRENT>).pyFileName*, delete the files; otherwise, skip this step.
