openapi: 3.0.0
info:
  title: MoEngage - Custom Segment(filter based) CRUD API's
  description: >-
    This API collection allows to create, update, get, list a custom segment via
    an API call.


    **URL** : [https://api-0X.moengage.com/](https://api-0X.moengage.com/)


    Each customer is hosted on a different data center, you can find your data
    center number (value of X), by checking the data center and API endpoint
    [mapping
    here](https://help.moengage.com/hc/en-us/articles/360057030512-Data-Centers-in-MoEngage#01G5DQVXGT2KZMXTJPF77QPJ25).


    **Where to find DATA API ID and API KEY?**


    - Username(DATA API ID) and password(DATA API KEY) are available at
    _**Settings > APIs > DATA API Settings**_.
        

    Do the following when you are using the API for the first-time
    authentication:


    1. Navigate to _**Settings > APIs > DATA API Settings**_.

    2. Click Generate Key

    3. Save the details on the Data APIs settings page.  
        **User name:** DATA API ID  
        **Password:** DATA API KEY
        

    Click
    [here](https://developers.moengage.com/hc/en-us/articles/4405027805844-Custom-File-Segment-API#authentication-0-1)
    to know more


    Use the Custom Filter Segment API to:


    - Create a new Custom Filter Segment

    - Update filters of existing filter based Custom Segment

    - Get details of existing filter based Custom Segment

    - List all existing Filter based Custom Segment
        

    Not sure on what is the structure of the payload to be used ?  

    Please login to the Moengage Dashboard and navigate to Test & Debug >>
    Segment Payload. Here payload can be generated.
  version: 1.0.0
servers:
  - url: https://api-{{0x}}.moengage.com
components:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
tags:
  - name: CREATE
  - name: UPDATE
  - name: GET
  - name: LIST
paths:
  /v3/custom-segments/:
    post:
      tags:
        - CREATE
      summary: Create Filter Segment
      description: >-
        This API Creates a Custom Segment (Filter based)


        | **Parameters** | **Description** |

        | --- | --- |

        | name (mandatory) | The name of the custom segment. The name should be
        unique across all segments. |

        | included_filters (mandatory) | Filtering criteria used for the
        custom-segment creation. Users who satisfy these filtering conditions
        fall into the custom-segment. |
      requestBody:
        content:
          '*/*':
            schema:
              type: string
              example: >-
                "{\n    \"name\": \"{{unique_custom_segment_name}}\",\n   
                \"included_filters\": {\n        \"filter_operator\":
                \"and\",\n        \"filters\": [\n            {\n               
                \"filter_type\": \"user_attributes\",\n               
                \"category\": \"Tracked Custom Attribute\",\n               
                \"name\": \"Birthday\",\n                \"data_type\":
                \"datetime\",\n                \"value\":
                \"2023-01-02T00:00:00.000Z\",\n                \"value_type\":
                \"absolute\",\n                \"operator\":
                \"on\",\n                \"negate\": false\n           
                },\n            {\n                \"action_name\":
                \"MOE_APP_OPENED\",\n                \"executed\":
                true,\n                \"filter_type\":
                \"actions\",\n                \"execution\":
                {\n                    \"count\": 1,\n                   
                \"type\": \"atleast\"\n                },\n               
                \"primary_time_range\": {\n                    \"type\":
                \"inTheLast\",\n                    \"value\":
                3,\n                    \"value_type\":
                \"relative_past\",\n                    \"period_unit\":
                \"days\"\n                },\n                \"attributes\":
                {\n                    \"filter_operator\":
                \"and\",\n                    \"filters\":
                [\n                        {\n                           
                \"data_type\": \"string\",\n                           
                \"category\": \"default\",\n                           
                \"name\": \"os\",\n                            \"value\":
                \"Android\",\n                            \"filter_type\":
                \"action_attributes\",\n                           
                \"case_sensitive\": false,\n                           
                \"operator\": \"is\",\n                            \"negate\":
                false\n                        }\n                   
                ]\n                }\n            }\n        ]\n    }\n}"
      security:
        - basicAuth: []
      parameters:
        - name: Content-Type
          in: header
          schema:
            type: string
          example: application/json
        - name: MOE-DBNAME
          in: header
          schema:
            type: string
          example: '{{DB_Name}}'
      responses:
        undefined:
          content:
            text/plain:
              schema:
                type: string
              examples:
                example-0:
                  summary: User Attribute-Based Segment
                  value: ''
                example-1:
                  summary: Action-Based Segment
                  value: ''
                example-2:
                  summary: Action Attribute-Based Segment
                  value: ''
                example-3:
                  summary: User Attribute & Actions with Attribute combined
                  value: ''
  /v3/custom-segments/{existing_custom_segment_id}:
    patch:
      tags:
        - UPDATE
      summary: Update Custom Segment
      description: >-
        This API updates the filters used in the provided custom segment


        | **Parameters** | **Description** |

        | --- | --- |

        | name (optional) | Unique Custom Segment name. If name is provided,
        it’ll update the name of the existing custom-segment. |

        | existing_custom_segment_id (mandatory) | Existing custom segment ID
        which need to be updated |

        | included_filters (mandatory) | Filtering criteria used for the
        custom-segment creation. Users who satisfy these filtering conditions
        fall into the custom-segment. |

        | updated_by (optional but recommended) | Any user identifier to track
        update history. |
      requestBody:
        content:
          '*/*':
            schema:
              type: string
              example: >-
                "{\n    \"name\": \"{{custom_segment_name}}\",\n   
                \"included_filters\": {\n        \"filter_operator\":
                \"and\",\n        \"filters\": [\n            {\n               
                \"data_type\": \"string\",\n                \"filter_type\":
                \"user_attributes\",\n                \"name\":
                \"name_seg2\",\n                \"negate\":
                false,\n                \"operator\": \"is\",\n               
                \"value\": \"God\",\n                \"value1\": 0\n           
                },\n            {\n                \"data_type\":
                \"bool\",\n                \"filter_type\":
                \"user_attributes\",\n                \"name\":
                \"bool_seg2\",\n                \"negate\":
                false,\n                \"operator\": \"is\",\n               
                \"value\": \"false\",\n                \"value1\":
                0\n            },\n            {\n                \"data_type\":
                \"double\",\n                \"filter_type\":
                \"user_attributes\",\n                \"name\":
                \"int_seg2\",\n                \"negate\":
                false,\n                \"operator\": \"is\",\n               
                \"value\": 200,\n                \"value1\": null\n           
                },\n            {\n                \"data_type\":
                \"datetime\",\n                \"filter_type\":
                \"user_attributes\",\n                \"name\":
                \"date_seg22\",\n                \"negate\":
                false,\n                \"operator\": \"on\",\n               
                \"value\": \"2023-01-03T00:00:00.000Z\",\n               
                \"value1\": null,\n                \"value_type\":
                \"absolute\"\n            }\n        ]\n    },\n   
                \"updated_by\": \"{{name}}\"\n}"
      security:
        - basicAuth: []
      parameters:
        - name: Content-Type
          in: header
          schema:
            type: string
          example: application/json
        - name: MOE-DBNAME
          in: header
          schema:
            type: string
          example: '{{DB_Name}}'
        - name: existing_custom_segment_id
          in: path
          schema:
            type: string
          required: true
      responses:
        '200':
          description: Successful response
          content:
            application/json: {}
    get:
      tags:
        - GET
      summary: Get custom segment by custom id
      description: >-
        This API gets all the details custom segment name, created date, updated
        date, description, included_filters for the provided custom segment id


        | Parameters | Description |

        | --- | --- |

        | existing_custom_segment_id (mandatory) | Existing custom segment ID |
      security:
        - basicAuth: []
      parameters:
        - name: Content-Type
          in: header
          schema:
            type: string
          example: application/json
        - name: MOE-DBNAME
          in: header
          schema:
            type: string
          example: '{{DB_Name}}'
        - name: existing_custom_segment_id
          in: path
          schema:
            type: string
          required: true
      responses:
        '200':
          description: Successful response
          content:
            application/json: {}
  /v3/custom-segments:
    get:
      tags:
        - LIST
      summary: List all Custom Segments
      description: >-
        This API Lists all the custom segments or the specified
        custom_segment_name in the params


        | **Parameters** | **Description** |

        | --- | --- |

        | path_params (optional) | path_params should be,
        `name={{custom_segment_name}}` |
      security:
        - basicAuth: []
      parameters:
        - name: Content-Type
          in: header
          schema:
            type: string
          example: application/json
        - name: MOE-DBNAME
          in: header
          schema:
            type: string
          example: '{{DB_Name}}'
        - name: '{{path_params}}'
          in: query
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json: {}
