# Create and run profile export

- Operation ID: `runProfileExport`
- HTTP method: `POST`
- Path: `/morph/exports/clients/segmentation`
- [Human-readable API reference](https://hub.synerise.com/api-reference/data-management#tag/Profile-management/operation/runProfileExport)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /morph/exports/clients/segmentation:
    post:
      tags:
        - Profile management
      operationId: runProfileExport
      summary: Create and run profile export
      description: |
        Request an export of profiles. The group of profiles to export is selected by pointing to a segmentation. After the export is completed, you can access the data with [GET /exports/clients/{taskId}/data](#operation/getExportedProfileData) or from [https://app.synerise.com/assets/exports](https://app.synerise.com/assets/exports).

        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>

        **API key permission required:** `CLIENT_EXPORTER_REPORT_CREATE`

        **User role permission required:** `settings_export: create`
      security:
        - JWT: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - fields
                - agreementFilter
                - segmentationHash
                - excludedIds
              properties:
                name:
                  type: string
                  description: Name of the export, visible at [https://app.synerise.com/assets/](https://app.synerise.com/assets/exports)
                fields:
                  type: array
                  example:
                    - id
                    - attr1
                    - attr2
                  minItems: 1
                  items:
                    type: string
                  description: |
                    Profile attributes to export.

                    **The first attribute in this array MUST BE `id`**
                agreementFilter:
                  type: string
                  enum:
                    - NONE
                    - EMAIL
                    - WEB_PUSH
                    - PUSH
                    - SMS
                    - RECOGNIZED
                    - ANONYMOUS
                  description: You can filter the profiles by their marketing agreement. `NONE` means no filter.
                segmentationHash:
                  type: string
                  format: uuid
                  description: UUID of the segmentation which defines the profiles to export. The segmentation conditions are checked at the time of sending the "create and run export" request.
                tags:
                  type: array
                  description: Profile tags to check for an exported profile. In the results, the tag name is the key and the value is "true" (string) if the tag is assigned to a given profile, otherwise it's "false".
                  items:
                    type: string
                expressions:
                  type: array
                  description: UUIDs of expressions to check for an exported profile. In the results, the name of the expression is the key and the value is the result of the expression.
                  items:
                    type: string
                    format: uuid
                aggregates:
                  type: array
                  description: UUIDs of aggregates to check for an exported profile. In the results, the name of the aggregate is the key and the value is the result of the aggregate.
                  items:
                    type: string
                    format: uuid
                segmentations:
                  type: array
                  description: UUIDs of segmentations to check for an exported profile. In the results, the name of the segmentation is the key and the value is "true" (string) if the profile belongs to the segmentation, otherwise it's "false".
                  items:
                    type: string
                    format: uuid
                excludedIds:
                  type: array
                  minItems: 0
                  items:
                    type: number
                  description: List of clientIds to exclude from the exported data
      responses:
        "200":
          description: Export task created and queued
          content:
            application/json:
              schema:
                type: object
                required:
                  - taskId
                  - columnOrder
                  - estimatedCount
                properties:
                  taskId:
                    type: string
                    format: uuid
                    description: ID of the submitted task. Save this ID to be able to retrieve the data.
                  columnOrder:
                    type: array
                    description: Fields included in the export
                    items:
                      type: string
                      description: Name of an exported attribute/tag/analysis
                  estimatedCount:
                    type: number
                    description: Estimated number of profiles in the exported segment
        "400":
          description: Invalid request
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                  - status
                properties:
                  error:
                    type: string
                    description: Summary of the error
                  status:
                    type: integer
                    format: int32
                    description: Status code
                  timestamp:
                    type: string
                    description: Time when the error occurred
                  message:
                    type: string
                    description: Description of the problem. If an error code is included, check the [API Error Reference](https://developers.synerise.com/errors.html) for details.
              example:
                error: Bad Request
                status: 400
                timestamp: 2021-01-04T16:15:51.703Z
                message: Message describing issue with provided request
      x-snr-doc-urls:
        - /api-reference/data-management#tag/Profile-management/operation/runProfileExport
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/morph/exports/clients/segmentation \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"name":"string","fields":["id","attr1","attr2"],"agreementFilter":"NONE","segmentationHash":"e7cff342-b484-4fcb-aa34-4735122bc9e7","tags":["string"],"expressions":["497f6eca-6276-4993-bfeb-53cbbbba6f08"],"aggregates":["497f6eca-6276-4993-bfeb-53cbbbba6f08"],"segmentations":["497f6eca-6276-4993-bfeb-53cbbbba6f08"],"excludedIds":[0]}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"name\":\"string\",\"fields\":[\"id\",\"attr1\",\"attr2\"],\"agreementFilter\":\"NONE\",\"segmentationHash\":\"e7cff342-b484-4fcb-aa34-4735122bc9e7\",\"tags\":[\"string\"],\"expressions\":[\"497f6eca-6276-4993-bfeb-53cbbbba6f08\"],\"aggregates\":[\"497f6eca-6276-4993-bfeb-53cbbbba6f08\"],\"segmentations\":[\"497f6eca-6276-4993-bfeb-53cbbbba6f08\"],\"excludedIds\":[0]}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/morph/exports/clients/segmentation", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "name": "string",
              "fields": [
                "id",
                "attr1",
                "attr2"
              ],
              "agreementFilter": "NONE",
              "segmentationHash": "e7cff342-b484-4fcb-aa34-4735122bc9e7",
              "tags": [
                "string"
              ],
              "expressions": [
                "497f6eca-6276-4993-bfeb-53cbbbba6f08"
              ],
              "aggregates": [
                "497f6eca-6276-4993-bfeb-53cbbbba6f08"
              ],
              "segmentations": [
                "497f6eca-6276-4993-bfeb-53cbbbba6f08"
              ],
              "excludedIds": [
                0
              ]
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/morph/exports/clients/segmentation");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/morph/exports/clients/segmentation",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              name: 'string',
              fields: ['id', 'attr1', 'attr2'],
              agreementFilter: 'NONE',
              segmentationHash: 'e7cff342-b484-4fcb-aa34-4735122bc9e7',
              tags: ['string'],
              expressions: ['497f6eca-6276-4993-bfeb-53cbbbba6f08'],
              aggregates: ['497f6eca-6276-4993-bfeb-53cbbbba6f08'],
              segmentations: ['497f6eca-6276-4993-bfeb-53cbbbba6f08'],
              excludedIds: [0]
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/morph/exports/clients/segmentation');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"name":"string","fields":["id","attr1","attr2"],"agreementFilter":"NONE","segmentationHash":"e7cff342-b484-4fcb-aa34-4735122bc9e7","tags":["string"],"expressions":["497f6eca-6276-4993-bfeb-53cbbbba6f08"],"aggregates":["497f6eca-6276-4993-bfeb-53cbbbba6f08"],"segmentations":["497f6eca-6276-4993-bfeb-53cbbbba6f08"],"excludedIds":[0]}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/morph/exports/clients/segmentation")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"name\":\"string\",\"fields\":[\"id\",\"attr1\",\"attr2\"],\"agreementFilter\":\"NONE\",\"segmentationHash\":\"e7cff342-b484-4fcb-aa34-4735122bc9e7\",\"tags\":[\"string\"],\"expressions\":[\"497f6eca-6276-4993-bfeb-53cbbbba6f08\"],\"aggregates\":[\"497f6eca-6276-4993-bfeb-53cbbbba6f08\"],\"segmentations\":[\"497f6eca-6276-4993-bfeb-53cbbbba6f08\"],\"excludedIds\":[0]}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Profile management
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
