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

# Archive Custom Segment

> Archives an existing custom segment (File or Filter). Archiving and unarchiving through APIs makes it easy to retrieve and reuse custom segments whenever required for purposes such as A/B testing, maintaining regulatory compliance, and improving system performance. You can access the archived segments and utilize them to analyze and market campaigns without the need to recreate them from scratch.

<Warning>
  Archived segments will not be shown beyond 180 days.
</Warning>


## OpenAPI

````yaml /api/custom-segments/custom-segments.yaml patch /v2/custom-segments/archive
openapi: 3.0.3
info:
  title: MoEngage Custom Segments API
  description: >
    Use the MoEngage Custom Segments API to create, update, and manage your file
    and filter segments.


    - **v2 API:** Manage File Segments and segment lifecycle
    (Archive/Unarchive).

    - **v3 API:** Create, read, update, and list filter-based Custom Segments.
  version: '3.0'
servers:
  - url: https://api-{dc}.moengage.com
    description: MoEngage API Endpoint
    variables:
      dc:
        description: Your account's Data Center (e.g., 01, 02, 03).
        default: '01'
        enum:
          - '01'
          - '02'
          - '03'
          - '04'
          - '05'
security:
  - basicAuth: []
tags:
  - name: Custom Segments - File
    description: >
      If you need to create segments by importing a large number of users, we
      recommend utilising the File segment API. This API allows you to easily
      generate a file segment by initiating a call to the file segment API
      endpoint. To proceed, you will need to compile a CSV file containing the
      relevant users (ensuring that the users are already present in MoEngage).
      It is essential to provide the public path of the file, which allows for
      downloading and identification of users in order to successfully create
      the file segment.


      Use the Custom File Segment API to:

      * Create a new Custom File Segment

      * Add Users to an existing Custom Segment

      * Remove Users from an existing Custom Segment

      * Replace Users from an existing Custom Segment
  - name: Custom Segments - Lifecycle
    description: >
      Archiving and unarchiving through APIs makes it easy to retrieve and reuse
      custom segments whenever required for purposes such as A/B testing,
      maintaining regulatory compliance, and improving system performance.


      You can access the archived segments and utilize them to analyze and
      market campaigns without the need to recreate them from scratch.
    x-mint:
      content: |

        <Warning>
          Archived segments will not be shown beyond 180 days.
        </Warning>
  - name: Custom Segments - Filters
    description: >
      If you need to create a segment based on the events or actions performed
      by your users on your application or website, the recommended approach is
      to use the filter segment API. With this API, you can create a custom
      segment by specifying the desired filter conditions.


      The filter segment API supports various operations, including create,
      update, get, and list, allowing you to effectively manage your segments
      based on specific criteria.
    x-mint:
      content: >
        ## Authentication

        Authentication is performed using Basic Auth. You must also provide the
        `MOE-APPKEY` header.


        ## Request Headers


        | Key | Required | Description |

        | :--- | :--- | :--- |

        | `Content-Type` | Yes | Set to `application/json`. |

        | `Authorization` | Yes | Basic Auth. `{"Authorization": "Basic
        Base64_ENCODED_WORKSPACEID_APIKEY="}` |

        | `MOE-APPKEY` | Yes | Your MoEngage App ID. Found in Settings ->
        Account -> APIs -> App ID. |


        ## FAQs


        <AccordionGroup>
          <Accordion title="How can I generate the payload for custom segment creation?">
            You can simply generate the payload from the MoEngage dashboard. Log in to the MoEngage dashboard and navigate to the **Test & Debug** -> **Segment Payload section**. Choose your filters and click on **Generate Payload**.
          </Accordion>
          <Accordion title="How do I get the id of a custom segment I created earlier but didn't save?">
            You can use the LIST Custom Segment API with the name query param filter to get the id of the custom segment.
          </Accordion>
          <Accordion title="Why am I getting 409 Conflict even with a different name?">
              Both the name and the definition of a custom segment are unique. If the definition of the custom segment in the request matches an existing segment, we return a conflict 409 error.
          </Accordion>
          <Accordion title="How do I know which existing segment is conflicting?">
            In the case of 409 Conflict, we return a conflicting name/id in the response payload. You can check the payload to get the existing custom segment with the same definition.
          </Accordion>
        </AccordionGroup>
paths:
  /v2/custom-segments/archive:
    patch:
      tags:
        - Custom Segments - Lifecycle
      summary: Archive Custom Segment
      description: >-
        Archives an existing custom segment (File or Filter). Archiving and
        unarchiving through APIs makes it easy to retrieve and reuse custom
        segments whenever required for purposes such as A/B testing, maintaining
        regulatory compliance, and improving system performance. You can access
        the archived segments and utilize them to analyze and market campaigns
        without the need to recreate them from scratch.
      operationId: archiveCustomSegment
      requestBody:
        description: The name of the custom segment to be archived.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SegmentNameRequestV2'
            example:
              name: custom_segment_unique_name
      responses:
        '202':
          description: Custom-segment archive request accepted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseSuccessV2'
              example:
                message: Successfully archived the custom segment
                success: true
                cs_name: custom_segment_unique_name
        '400':
          $ref: '#/components/responses/400_FileSegmentError'
        '401':
          $ref: '#/components/responses/401_FileSegmentError'
        '404':
          $ref: '#/components/responses/404_FileSegmentNotFound'
        '500':
          $ref: '#/components/responses/5XX_FileSegmentError'
components:
  schemas:
    SegmentNameRequestV2:
      description: Schema for requests that only require the segment name.
      type: object
      properties:
        name:
          type: string
          description: The name of the custom segment.
      required:
        - name
    ApiResponseSuccessV2:
      type: object
      properties:
        message:
          type: string
          description: The status message of the request.
        success:
          type: boolean
          example: true
          description: Indicates if the request was accepted.
        cs_name:
          type: string
          description: The unique name of the custom segment being processed.
    ApiErrorV2:
      type: object
      properties:
        title:
          type: string
          description: A short title for the error.
  responses:
    400_FileSegmentError:
      description: Bad Request. Invalid payload format.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorV2'
          example:
            title: Invalid Request
            description: <message>
    401_FileSegmentError:
      description: Unauthorized. Authentication or Authorization Failure.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorV2'
          example:
            title: Authentication required
            description: <message>
    404_FileSegmentNotFound:
      description: Entity Not Found. The custom segment name does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorV2'
          example:
            title: Entity Not Found
            description: >-
              Custom segment not found with the given name:
              <custom_segment_unique_name>
    5XX_FileSegmentError:
      description: Server Errors. Something went wrong on MoEngage.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorV2'
          example:
            title: Internal Server Error
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: >
        Basic Authentication using your **Workspace ID** (as username) and
        **Data API Key** (as password) from the MoEngage Dashboard.

````