{
  "openapi": "3.1.0",
  "info": {
    "title": "segmentation",
    "version": "1.1"
  },
  "servers": [
    {
      "url": "https://api.aimtell.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "apiKey",
        "name": "X-Authorization-Api-Key",
        "in": "header",
        "x-default": ""
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/prod/segments/": {
      "post": {
        "summary": "Create Segment",
        "description": "Create a NEW Segment",
        "operationId": "create-segment",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "idSite"
                ],
                "properties": {
                  "idSite": {
                    "type": "string",
                    "description": "Site ID"
                  },
                  "name": {
                    "type": "string",
                    "description": "Name of Segment",
                    "default": ""
                  },
                  "definition": {
                    "type": "string",
                    "description": "Definition",
                    "default": ""
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "success",
                      "message": "Successfully created",
                      "id": 123
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Error #139."
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Segments"
        ]
      }
    },
    "/prod/segment/{id}": {
      "get": {
        "summary": "Get Segment",
        "description": "Fetches a specific Segment",
        "operationId": "get-segment",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Segment ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "idsegment": 123,
                      "owner": "exampleUid",
                      "name": "Example Segment",
                      "definition": "region==California",
                      "idSite": 456,
                      "createdAt": "2024-01-01 00:00:00",
                      "updatedAt": "2024-01-01 00:00:00",
                      "deleted": 0
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Invalid token.",
                      "error_code": 71831
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Segments"
        ]
      },
      "put": {
        "summary": "Update Segment",
        "description": "Update a Specific Segment",
        "operationId": "update-segment",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Segment ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name of Segment"
                  },
                  "definition": {
                    "type": "string",
                    "description": "Definition"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "success",
                      "idSegment": "24",
                      "message": "Successfully updated segment"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Error #136."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Please specify a valid auth_token."
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Segments"
        ]
      },
      "delete": {
        "summary": "Delete Segment",
        "description": "Delete a specific Segment",
        "operationId": "delete-segment",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Segment ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "success",
                      "idSegment": "5",
                      "message": "Successfully removed segment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Please specify a valid auth_token."
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Segments"
        ]
      }
    },
    "/prod/segments/{idSite}": {
      "get": {
        "summary": "Get All Segments",
        "description": "Fetches all Segments for account",
        "operationId": "get-available-segments",
        "parameters": [
          {
            "name": "idSite",
            "in": "path",
            "description": "Site ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": [
                      {
                        "idsegment": 123,
                        "owner": "exampleUid",
                        "name": "Example Segment",
                        "definition": "region==California",
                        "idSite": 456,
                        "createdAt": "2024-01-01 00:00:00",
                        "updatedAt": "2024-01-01 00:00:00",
                        "deleted": 0
                      },
                      {
                        "idsegment": 456,
                        "owner": "exampleUid",
                        "name": "Example Segment",
                        "definition": "eventCategory==video,eventAction==tutorial",
                        "idSite": 456,
                        "createdAt": "2024-01-01 00:00:00",
                        "updatedAt": "2024-01-01 00:00:00",
                        "deleted": 0
                      },
                      {
                        "idsegment": 789,
                        "owner": "exampleUid",
                        "name": "Example Segment",
                        "definition": "pageUrl==https://example.com/",
                        "idSite": 456,
                        "createdAt": "2024-01-01 00:00:00",
                        "updatedAt": "2024-01-01 00:00:00",
                        "deleted": 0
                      }
                    ]
                  }
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Invalid token.",
                      "error_code": 71831
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Segments"
        ]
      }
    },
    "/prod/segment/{id}/results": {
      "get": {
        "summary": "Get Segment Counts Over Time",
        "description": "Fetches a specific Segment",
        "operationId": "api-get-segment-counts-over-time",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Segment ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "startDate",
            "in": "query",
            "description": "Date as yyyy-mm-dd (i.e. 2019-12-07)",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date",
              "default": ""
            }
          },
          {
            "name": "endDate",
            "in": "query",
            "description": "Date as yyyy-mm-dd (i.e. 2019-12-14)",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date",
              "default": ""
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "01/01/2024": 100,
                      "01/02/2024": 105,
                      "01/03/2024": 110,
                      "01/04/2024": 115,
                      "01/05/2024": 120,
                      "01/06/2024": 125,
                      "01/07/2024": 130
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Invalid token.",
                      "error_code": 71831
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Segments"
        ]
      }
    },
    "/prod/segment/{id}/shared": {
      "get": {
        "summary": "Get Shared Segments",
        "description": "Returns every site this segment is shared with. Returns an empty array if the segment is not shared.",
        "operationId": "get-shared-segments",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Segment ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": [
                      {
                        "idsegment": 123,
                        "idSite": 456,
                        "shared_id": "exampleSharedId"
                      },
                      {
                        "idsegment": 124,
                        "idSite": 457,
                        "shared_id": "exampleSharedId"
                      },
                      {
                        "idsegment": 125,
                        "idSite": 458,
                        "shared_id": "exampleSharedId"
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {}
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Segments"
        ]
      },
      "post": {
        "summary": "Share Segment",
        "description": "Shares this segment with one or more additional sites, creating a matching segment on each. Sharing a segment is a prerequisite for sharing any campaign that targets it. Segments using the following conditions cannot be shared: Exists In Segment, Does Not Exist In Segment, Manual Campaign Clicked, Triggered Campaign Clicked, RSS Campaign Clicked. Returns the full shared group, including sites shared previously.",
        "operationId": "share-segment",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Segment ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "sites"
                ],
                "properties": {
                  "sites": {
                    "type": "array",
                    "description": "Site IDs to share with. Sites the segment already reaches are ignored.",
                    "items": {
                      "type": "integer"
                    }
                  }
                }
              },
              "examples": {
                "Request": {
                  "value": {
                    "sites": [
                      456,
                      457,
                      458
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": [
                      {
                        "idsegment": 123,
                        "idSite": 456,
                        "shared_id": "exampleSharedId"
                      },
                      {
                        "idsegment": 124,
                        "idSite": 457,
                        "shared_id": "exampleSharedId"
                      },
                      {
                        "idsegment": 125,
                        "idSite": 458,
                        "shared_id": "exampleSharedId"
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Must specify sites"
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Segments"
        ]
      }
    },
    "/prod/subscribers/{id}": {
      "get": {
        "summary": "Get Subscribers",
        "description": "Fetches subscribers for a given site. Optionally filter by segment or a specific subscriber.",
        "operationId": "get-subscribers",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Site ID",
            "schema": {
              "type": "integer"
            },
            "required": true
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of results to return per page.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "skip",
            "in": "query",
            "description": "Number of results to skip for pagination (offset).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "include",
            "in": "query",
            "description": "Accepts `attributes`, `notifications`, or both as a comma-separated list (e.g. `attributes,notifications`).\n\nNote: the `read` field on notifications does not indicate impressions or delivery. It is used within the Notification Center (coming soon).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "segmentId",
            "in": "query",
            "description": "The ID of the segment you wish to filter by.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "subscriberId",
            "in": "query",
            "description": "The specific subscriber ID to pull data for.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "count": 1000,
                      "skip": 0,
                      "limit": 2,
                      "segmentId": null,
                      "filter": null,
                      "subscribers": [
                        {
                          "subscriberId": "exampleSubscriberId",
                          "deviceType": "desktop",
                          "browserName": "Chrome",
                          "operatingSystemCode": "Windows",
                          "browserLang": "en-US",
                          "region": "California",
                          "city": "Los Angeles",
                          "ip": "0.0.0.0",
                          "country": "United States",
                          "postal": "",
                          "idSite": "456",
                          "alias": {
                            "user": "example_user",
                            "email_hash": "abc123example"
                          },
                          "attributes": {
                            "username": "example_user",
                            "subscription_url": "https://example.com/landing-page"
                          },
                          "createdAt": "2024-01-01 00:00:00",
                          "notifications": [
                            {
                              "title": "Example Title",
                              "body": "Example body text",
                              "icon": "https://cdn.aimtell.io/example/icon.jpg",
                              "link": "https://example.com/landing-page",
                              "read": "1",
                              "timestamp": 1704067200
                            }
                          ]
                        },
                        {
                          "subscriberId": "exampleSubscriberId2",
                          "deviceType": "desktop",
                          "browserName": "Chrome",
                          "operatingSystemCode": "Mac OS X",
                          "browserLang": "en-US",
                          "region": "California",
                          "city": "Los Angeles",
                          "ip": "0.0.0.0",
                          "country": "United States",
                          "postal": "",
                          "idSite": "456",
                          "alias": {
                            "user": "example_user_2",
                            "email_hash": "abc123example"
                          },
                          "attributes": {
                            "username": "example_user_2",
                            "subscription_url": "https://example.com/landing-page"
                          },
                          "createdAt": "2024-01-01 00:00:00",
                          "notifications": [
                            {
                              "title": "Example Title",
                              "body": "Example body text",
                              "icon": "https://cdn.aimtell.io/example/icon.jpg",
                              "link": "https://example.com/landing-page",
                              "read": "0",
                              "timestamp": 1704067200
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Invalid token.",
                      "error_code": 71831
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "tags": [
          "Subscribers"
        ]
      }
    },
    "/prod/subscriber": {
      "post": {
        "summary": "Track Subscriber Attribute",
        "description": "Track Subscriber Attribute",
        "operationId": "api-track-subscriber-attribute",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "idSite"
                ],
                "properties": {
                  "idSite": {
                    "type": "string",
                    "description": "Website ID"
                  },
                  "subscriber_uid": {
                    "type": "string",
                    "description": "Aimtell Subscriber ID"
                  },
                  "user": {
                    "type": "string",
                    "description": "Subscriber \"User\" Alias"
                  },
                  "email": {
                    "type": "string",
                    "description": "Subscriber \"Email\" Alias"
                  },
                  "attributes": {
                    "type": "string",
                    "description": "JSON",
                    "default": "",
                    "format": "json"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "success"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Error #136."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "result": "error",
                      "message": "Please specify a valid auth_token."
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "x-readme": {
          "code-samples": [
            {
              "language": "curl",
              "code": "curl -XPOST -H 'X-Authorization-Api-Key: API_KEY' -H \"Content-type: application/json\" -d '{\n    \"idSite\": \"1\",\n    \"subscriber_uid\": \"5059b0a2-747d-0f74-73c4-24c8442de237\",\n    \"attributes\": {\n        \"first_name\" : \"jeff\",\n        \"gender\" : \"male\"\n    }\n}' 'https://api.aimtell.com/prod/subscriber/'",
              "name": "CURL (using subscriber_uid)"
            },
            {
              "language": "curl",
              "code": "curl -XPOST -H 'X-Authorization-Api-Key: API_KEY' -H \"Content-type: application/json\" -d '{\n    \"idSite\": \"1\",\n    \"user\": \"jeffdunham12\",\n    \"attributes\": {\n        \"first_name\" : \"jeff\",\n        \"gender\" : \"male\"\n    }\n}' 'https://api.aimtell.com/prod/subscriber/'",
              "name": "CURL (using user alias)"
            },
            {
              "language": "curl",
              "code": "curl -XPOST -H 'X-Authorization-Api-Key: API_KEY' -H \"Content-type: application/json\" -d '{\n    \"idSite\": \"1\",\n    \"email\": \"jeff@dunham.com\",\n    \"attributes\": {\n        \"first_name\" : \"jeff\",\n        \"gender\" : \"male\"\n    }\n}' 'https://api.aimtell.com/prod/subscriber/'",
              "name": "CURL (using email alias)"
            }
          ],
          "samples-languages": [
            "curl"
          ]
        },
        "tags": [
          "Subscribers"
        ]
      }
    }
  },
  "tags": [
    {
      "name": "Segments",
      "description": "Audience segmentation"
    },
    {
      "name": "Subscribers",
      "description": "Subscriber management and tracking"
    }
  ]
}