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

# Trigger Segment Export

> Used to trigger a background task to export device or profile data for a specific segment.

<br>

<p><strong>Prerequisites:</strong> Ensure you have the following:</p>

<p>- An active Xtremepush project<br>
- Export and File Download scopes enabled for your API Client ID<br>
- A valid OAuth 2.0 access token<br>
- The <code>segment_id</code> or <code>segment_title</code> of the segment you want to export</p>

<br>

## Segment Export Workflow

<p>This API allows you to queue an asynchronous task to export segment data. The segment export process follows these three steps:</p>

<p>1. Call the <code>/segment-export/trigger</code> endpoint to start the export. The response contains a unique <code>task_id</code>.<br>
2. Use the <code>/info/task</code> endpoint with the <code>task_id</code> to monitor the export progress. After the export is complete, a <code>file_id</code> is generated.<br>
3. Call the <code>/file/{fileId}/download</code> endpoint using each <code>file_id</code> from the task result to retrieve your segment data.</p>

<br>

## Export Capabilities and Restrictions

<p>Before you queue an export, review the following:</p>

<p>- You can only trigger one export per hour for any specific segment.<br>
- You must provide either a <code>segment_id</code> or a <code>segment_title</code>. You cannot provide both in the same request.<br>
- There are two types of export options:<br>
&nbsp;&nbsp;- <code>device</code> - exports device-level records.<br>
&nbsp;&nbsp;- <code>profile</code> - exports user profile records. This type allows you to select specific attributes and subscription preferences to include in the generated file.</p>

## OpenAPI

````json POST /segment-export/trigger
{
  "openapi": "3.1.0",
  "info": {
    "title": "external-api",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://api.eu.xtremepush.com/api/external"
    }
  ],
  "paths": {
    "/segment-export/trigger": {
      "post": {
        "summary": "Trigger Segment Export",
        "description": "Used to trigger a background task to export device or profile data for a specific segment.\n\n<br>\n\n<p><strong>Prerequisites:</strong> Ensure you have the following:</p>\n\n<p>- An active Xtremepush project<br>\n- Export and File Download scopes enabled for your API Client ID<br>\n- A valid OAuth 2.0 access token<br>\n- The <code>segment_id</code> or <code>segment_title</code> of the segment you want to export</p>\n\n<br>\n\n## Segment Export Workflow\n\n<p>This API allows you to queue an asynchronous task to export segment data. The segment export process follows these three steps:</p>\n\n<p>1. Call the <code>/segment-export/trigger</code> endpoint to start the export. The response contains a unique <code>task_id</code>.<br>\n2. Use the <code>/info/task</code> endpoint with the <code>task_id</code> to monitor the export progress. After the export is complete, a <code>file_id</code> is generated.<br>\n3. Call the <code>/file/{fileId}/download</code> endpoint using each <code>file_id</code> from the task result to retrieve your segment data.</p>\n\n<br>\n\n## Export Capabilities and Restrictions\n\n<p>Before you queue an export, review the following:</p>\n\n<p>- You can only trigger one export per hour for any specific segment.<br>\n- You must provide either a <code>segment_id</code> or a <code>segment_title</code>. You cannot provide both in the same request.<br>\n- There are two types of export options:<br>\n&nbsp;&nbsp;- <code>device</code> - exports device-level records.<br>\n&nbsp;&nbsp;- <code>profile</code> - exports user profile records. This type allows you to select specific attributes and subscription preferences to include in the generated file.</p>",
        "operationId": "post_segment-export-trigger",
        "parameters": [
          {
            "in": "header",
            "name": "Authorization",
            "schema": {
              "type": "string"
            },
            "required": "true",
            "description": "The OAuth 2.0 bearer token. Example: Bearer {your_token}"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "export_type"
                ],
                "properties": {
                  "segment_id": {
                    "type": "integer",
                    "description": "The unique identifier of the segment you want to export. You must provide this if you do not provide a segment_title."
                  },
                  "segment_title": {
                    "type": "string",
                    "description": "The exact name of the segment you want to export. You must provide this if you do not provide a segment_id."
                  },
                  "export_type": {
                    "type": "string",
                    "description": "Defines the type of data to export. Use \"device\" for device-level records or \"profile\" for profile-level records."
                  },
                  "attributes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "A list of profile attributes to include in profile exports, for example [\"user_id\", \"email\", \"first_name\"]. This field must be null or an empty array for device exports."
                  },
                  "preferences": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "description": "A list of subscription preferences to include in profile exports. This field must be null or an empty array for device exports."
                  }
                }
              },
              "examples": {
                "Profile export": {
                  "value": {
                    "segment_id": "12345",
                    "export_type": "profile",
                    "attributes": [
                      "user_id",
                      "email",
                      "first_name"
                    ],
                    "preferences": []
                  }
                },
                "Device export": {
                  "value": {
                    "segment_id": "12345",
                    "export_type": "device",
                    "attributes": [],
                    "preferences": []
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "default": "true",
                      "description": "Returns true when the request is successful."
                    },
                    "message": {
                      "type": "string",
                      "default": "Segment export queued successfully"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "task_id": {
                          "type": "integer",
                          "description": "The unique identifier for the export task. Use this ID to check the status of your export."
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "Result": {
                    "value": {
                      "success": "true",
                      "message": "Segment export queued successfully"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "default": "Bad Request"
                    },
                    "message": {
                      "type": "string",
                      "default": "Project is inactive or Validation failed"
                    }
                  }
                },
                "examples": {
                  "Result": {
                    "value": {
                      "name": "Bad Request",
                      "message": "Project is inactive or Validation failed"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "default": "Forbidden"
                    },
                    "message": {
                      "type": "string",
                      "default": "Access Denied"
                    }
                  }
                },
                "examples": {
                  "Result": {
                    "value": {
                      "name": "Forbidden",
                      "message": "Access Denied"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "default": "Not Found"
                    },
                    "message": {
                      "type": "string",
                      "default": "Segment not found"
                    }
                  }
                },
                "examples": {
                  "Result": {
                    "value": {
                      "name": "Not Found",
                      "message": "Segment not found"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "default": "Too Many Requests"
                    },
                    "message": {
                      "type": "string",
                      "default": "Rate Limit Exceeded"
                    }
                  }
                },
                "examples": {
                  "Result": {
                    "value": {
                      "name": "Too Many Requests",
                      "message": "Rate Limit Exceeded"
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Segment Export Methods"
        ]
      }
    }
  }
}
````

