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

# Search translation memory

> 
**Overview**
Runs an asynchronous TMX export based on optional wildcard/phrase queries and optional metadata filters.
The job streams filtered translation units into TMX via the downstream `/export_tmx_by_query` endpoint.
Use `downloadExport/{asyncRequestId}` to fetch the finished file.

**Flow**
1. Caller posts `ExportByQueryDto`.
2. Service queues backend export (job metadata marks it asynchronous).
3. Response contains `asyncRequest` + `asyncExport` descriptors so you can poll or receive callbacks.

**`queries` + `queryLangs` — intersection (AND), optional**
- `queries` and `queryLangs` are optional and must align 1-to-1 when provided.
- Each pair applies a search expression to its locale. Multiple pairs are **AND-intersected**: a TU must satisfy every pair (it must have a TUV in each pair's locale that matches the query).
- Query values: unquoted text = contains; quoted text = phrase; `*`/`?` wildcards (max 5/10); no regex/boolean operators.
- `"*"` means match-all **but the locale filter still applies** — the TU must have a TUV in that locale (real AND constraint).
- `""` (empty string) or null means **no constraint** — that pair is ignored entirely and does not participate in the AND. Sending all-empty queries is the same as omitting `queries` altogether.
- When `queries` is omitted or all entries are empty/null, the export falls through to OR-over-`exportTargetLangs` (see below).

**`exportTargetLangs` — disjunction (OR), optional**
- Controls which target TUVs are written to the TMX. A TU is kept if it has at least one TUV matching any of the listed locales.
- `null` / omitted — no locale filter; the **whole TU** is exported with **all** its target TUVs.
- Present but empty (or all entries invalid) — produces an **empty TMX** (not the same as null).
- To export TUs updated in any of N languages (OR semantics), put the N locales in `exportTargetLangs` and leave `queries`/`queryLangs` empty — do NOT put them in `queries`/`queryLangs` (that would AND them).

**Examples**
Export TUs that have an es or de TUV (OR — recommended for multi-language sync):
`{ "exportTargetLangs": ["es_es","de_de"] }`

Export TUs that have BOTH es AND de TUVs (AND):
`{ "queries": ["*","*"], "queryLangs": ["es_es","de_de"], "exportTargetLangs": ["es_es","de_de"] }`

**Filtering**
- Timestamp bounds (`createdAtMin/Max`, `modifiedAtMin/Max`) and author filters (`createdBy`, `modifiedBy`) narrow the TU set before export.

**Output & limits**
- Output is always TMX, streamed in chunks; filenames follow `dto.filename` when provided, otherwise backend defaults.
- Requests with excessive locales or wildcard limit violations reject with `400`.
- If no matches remain after filtering, the job still produces an empty TMX.

**Callbacks & polling**
- Provide `callbackUrl` to receive completion notification from the async mediator; otherwise poll `asyncRequest` via standard async APIs and download through `/downloadExport/{asyncRequestId}` when ready.




## OpenAPI

````yaml /openapi/phrase-tms-v1.json post /api2/v1/transMemories/{transMemoryUid}/exportByQueryAsync
openapi: 3.0.0
info:
  description: |-
    Welcome to Phrase's TMS API documentation. 

     Please visit our [help center](https://support.phrase.com/hc/en-us/sections/5709662083612) for more information about the APIs. 

     If you have any questions, please contact [Support](https://support.phrase.com/hc/requests/new). 

     Please, include the `User-Agent` header with the name of your application or project. It might be a good idea to include some sort of contact information as well, so that we can get in touch if necessary. Examples of excellent `User-Agent` headers:
     > User-Agent: Example mobile app (example@phrase.com) <br/> User-Agent: ACME Inc Java 1.8 Client (http://acmeinc.com/contact)
  version: '1'
  title: Phrase TMS API
servers:
  - url: https://cloud.memsource.com/web
security:
  - ApiToken: []
  - OAuth2: []
tags:
  - name: Additional Workflow Step
  - name: Analysis
  - name: Async Request
  - name: Authentication
  - name: Automations
  - name: Bilingual File
  - name: Business Unit
  - name: Buyer
  - name: Client
  - name: Connector
  - name: Conversations
  - name: Cost Center
  - name: Custom Fields
  - name: Custom File Type
  - name: Domain
  - name: Due Date Scheme
  - name: Email Template
  - name: File
  - name: Glossary
  - name: Import settings
  - name: Job
  - name: Language AI
  - name: Language Assets
  - name: Language Quality Assessment
  - name: Machine Translation
  - name: Machine Translation Settings
  - name: Mapping
  - name: Net Rate Scheme
  - name: Notifications
  - name: Price List
  - name: Project
  - name: Project Template
  - name: Provider
  - name: Quality Assurance
  - name: Quality Profile
  - name: Quote
  - name: Reference File
  - name: SCIM
  - name: Segment
  - name: Segmentation Rules
  - name: Service
  - name: Spell Check
  - name: SubDomain
  - name: Supported Languages
  - name: Term Base
  - name: Translation
  - name: Translation Memory
  - name: User
  - name: Vendor
  - name: Webhook
  - name: Workflow Step
  - name: XML Assistant
paths:
  /api2/v1/transMemories/{transMemoryUid}/exportByQueryAsync:
    post:
      tags:
        - Translation Memory
      summary: Search translation memory
      description: >

        **Overview**

        Runs an asynchronous TMX export based on optional wildcard/phrase
        queries and optional metadata filters.

        The job streams filtered translation units into TMX via the downstream
        `/export_tmx_by_query` endpoint.

        Use `downloadExport/{asyncRequestId}` to fetch the finished file.


        **Flow**

        1. Caller posts `ExportByQueryDto`.

        2. Service queues backend export (job metadata marks it asynchronous).

        3. Response contains `asyncRequest` + `asyncExport` descriptors so you
        can poll or receive callbacks.


        **`queries` + `queryLangs` — intersection (AND), optional**

        - `queries` and `queryLangs` are optional and must align 1-to-1 when
        provided.

        - Each pair applies a search expression to its locale. Multiple pairs
        are **AND-intersected**: a TU must satisfy every pair (it must have a
        TUV in each pair's locale that matches the query).

        - Query values: unquoted text = contains; quoted text = phrase; `*`/`?`
        wildcards (max 5/10); no regex/boolean operators.

        - `"*"` means match-all **but the locale filter still applies** — the TU
        must have a TUV in that locale (real AND constraint).

        - `""` (empty string) or null means **no constraint** — that pair is
        ignored entirely and does not participate in the AND. Sending all-empty
        queries is the same as omitting `queries` altogether.

        - When `queries` is omitted or all entries are empty/null, the export
        falls through to OR-over-`exportTargetLangs` (see below).


        **`exportTargetLangs` — disjunction (OR), optional**

        - Controls which target TUVs are written to the TMX. A TU is kept if it
        has at least one TUV matching any of the listed locales.

        - `null` / omitted — no locale filter; the **whole TU** is exported with
        **all** its target TUVs.

        - Present but empty (or all entries invalid) — produces an **empty TMX**
        (not the same as null).

        - To export TUs updated in any of N languages (OR semantics), put the N
        locales in `exportTargetLangs` and leave `queries`/`queryLangs` empty —
        do NOT put them in `queries`/`queryLangs` (that would AND them).


        **Examples**

        Export TUs that have an es or de TUV (OR — recommended for
        multi-language sync):

        `{ "exportTargetLangs": ["es_es","de_de"] }`


        Export TUs that have BOTH es AND de TUVs (AND):

        `{ "queries": ["*","*"], "queryLangs": ["es_es","de_de"],
        "exportTargetLangs": ["es_es","de_de"] }`


        **Filtering**

        - Timestamp bounds (`createdAtMin/Max`, `modifiedAtMin/Max`) and author
        filters (`createdBy`, `modifiedBy`) narrow the TU set before export.


        **Output & limits**

        - Output is always TMX, streamed in chunks; filenames follow
        `dto.filename` when provided, otherwise backend defaults.

        - Requests with excessive locales or wildcard limit violations reject
        with `400`.

        - If no matches remain after filtering, the job still produces an empty
        TMX.


        **Callbacks & polling**

        - Provide `callbackUrl` to receive completion notification from the
        async mediator; otherwise poll `asyncRequest` via standard async APIs
        and download through `/downloadExport/{asyncRequestId}` when ready.
      operationId: exportByQueryAsync
      parameters:
        - name: transMemoryUid
          in: path
          description: Translation memory UID
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExportByQueryDtoV1'
        description: Export by query request payload
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AsyncExportTMByQueryResponseDtoV1'
        '400':
          description: Bad Request
        '401':
          description: Not authorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '405':
          description: Method not allowed
        '408':
          description: Timeout
        '410':
          description: Gone
        '415':
          description: Unsupported media type
        '429':
          description: Too many requests
        '500':
          description: Internal server error
        '501':
          description: Not implemented
components:
  schemas:
    ExportByQueryDtoV1:
      type: object
      properties:
        callbackUrl:
          type: string
          description: Callback URL to notify when the async export completes
        createdAtMax:
          type: string
          format: date-time
          description: Maximum segment creation timestamp filter
        createdAtMin:
          type: string
          format: date-time
          description: Minimum segment creation timestamp filter
        createdBy:
          $ref: '#/components/schemas/IdReference'
        exportTargetLangs:
          type: array
          description: >-
            Target locale(s) for the exported TMX. Optional — if omitted, all
            target TUVs are exported (OR/disjunction). TUs are kept when they
            have at least one TUV matching any listed locale.
          items:
            type: string
        filename:
          type: string
          description: Custom filename for the exported TMX file
        modifiedAtMax:
          type: string
          format: date-time
          description: Maximum segment last-modified timestamp filter
        modifiedAtMin:
          type: string
          format: date-time
          description: Minimum segment last-modified timestamp filter
        modifiedBy:
          $ref: '#/components/schemas/IdReference'
        project:
          $ref: '#/components/schemas/UidReference'
        queries:
          type: array
          description: >-
            Search query strings (one per queryLangs entry). Optional — if
            omitted or empty, exports all TUs matching targetLocales (OR). When
            provided, multiple entries are AND-intersected: a TU must satisfy
            every query. An empty string "" or null entry is ignored (no
            constraint for that locale); use "*" to require a TUV to exist in a
            locale without filtering by text.
          items:
            type: string
        queryLangs:
          type: array
          description: >-
            Locale for each corresponding queries entry (aligned 1-to-1).
            Optional — required only when queries is provided; must have the
            same number of entries.
          items:
            type: string
      description: >-
        Request body for exportByQueryAsync; specifies query expressions,
        locales and optional filters
    AsyncExportTMByQueryResponseDtoV1:
      type: object
      properties:
        asyncExport:
          $ref: '#/components/schemas/AsyncExportTMByQueryDtoV1'
        asyncRequest:
          $ref: '#/components/schemas/AsyncRequestDtoV1'
      description: >-
        Response envelope returned by exportByQueryAsync with async request
        handle and export job details
    IdReference:
      type: object
      required:
        - id
      properties:
        id:
          type: string
    UidReference:
      type: object
      required:
        - uid
      properties:
        uid:
          type: string
          example: 3HYnHHLkTPJfMxBCDbPXFe
          description: Unique identifier of the referenced object
      description: Reference to an object by its unique identifier
    AsyncExportTMByQueryDtoV1:
      type: object
      properties:
        asyncRequest:
          $ref: '#/components/schemas/ObjectReference'
        exportTargetLangs:
          type: array
          description: Target language locales included in this export
          items:
            type: string
        queries:
          type: array
          description: Query expressions with their associated locales
          items:
            $ref: '#/components/schemas/Query'
        transMemory:
          $ref: '#/components/schemas/ObjectReference'
      description: >-
        Export job descriptor containing query expressions, locale selections
        and the source TM reference
    AsyncRequestDtoV1:
      type: object
      properties:
        action:
          type: string
          enum:
            - PRE_ANALYSE
            - POST_ANALYSE
            - CONTINUOUS_PRE_ANALYSE
            - CONTINUOUS_POST_ANALYSE
            - COMPARE_ANALYSE
            - PARENT_ANALYSE
            - PRE_TRANSLATE
            - ASYNC_TRANSLATE
            - IMPORT_JOB
            - IMPORT_FILE
            - ALIGN
            - EXPORT_TMX_BY_QUERY
            - EXPORT_TMX
            - IMPORT_TMX
            - IMPORT_MXLF_INTO_TM
            - IMPORT_TBX
            - IMPORT_TBX_TB3
            - INSERT_INTO_TM
            - DELETE_TM
            - CLEAR_TM
            - QA
            - QA_V3
            - UPDATE_CONTINUOUS_JOB
            - UPDATE_SOURCE
            - UPDATE_TARGET
            - EXTRACT_CLEANED_TMS
            - GLOSSARY_PUT
            - GLOSSARY_DELETE
            - ASYNC_TRANSLATE_VERIFY
            - CREATE_PROJECT
            - EXPORT_COMPLETE_FILE
            - IMPORT_ANNOTATIONS
            - FILE_FLOW_CONVERTER_IMPORT
            - FILE_FLOW_MT_PRETRANSLATE
            - FILE_FLOW_QUALITY_ESTIMATION
            - AUTO_LQA
            - ADOPT_SEGMENT_DATA
            - ADOPT_SEGMENT_SET_DATA
            - QP_EVALUATION
            - QP_EVALUATION_V2
            - QUALITY_EVALUATION
        asyncResponse:
          $ref: '#/components/schemas/AsyncResponseDtoV1'
        createdBy:
          $ref: '#/components/schemas/UserReferenceV1'
        dateCreated:
          type: string
          format: date-time
        id:
          type: string
        parent:
          $ref: '#/components/schemas/AsyncRequestDtoV1'
        project:
          $ref: '#/components/schemas/A_reference_to_a_project'
    ObjectReference:
      type: object
    Query:
      type: object
      properties:
        lang:
          type: string
        query:
          type: string
    AsyncResponseDtoV1:
      type: object
      properties:
        acceptedSegmentsCount:
          type: integer
          format: int64
        dateCreated:
          type: string
          format: date-time
        errorCode:
          type: string
        errorDesc:
          type: string
        errorDetails:
          type: array
          items:
            $ref: '#/components/schemas/ErrorDetailDtoV1'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ErrorDetailDtoV1'
    UserReferenceV1:
      type: object
      properties:
        email:
          type: string
          description: Email address of the user
        firstName:
          type: string
          description: First name of the user
        id:
          type: string
          description: Unique numeric identifier of the user
        lastName:
          type: string
          description: Last name of the user
        role:
          type: string
          description: Role of the user in the organization
          enum:
            - SYS_ADMIN
            - SYS_ADMIN_READ
            - ADMIN
            - PROJECT_MANAGER
            - LINGUIST
            - GUEST
            - SUBMITTER
            - PORTAL_MEMBER
            - BOT
        uid:
          type: string
          description: Unique string identifier of the user
        userName:
          type: string
          description: Username of the user
    A_reference_to_a_project:
      type: object
      properties:
        name:
          type: string
          description: Name of the project
        uid:
          type: string
          description: Unique identifier used in API paths
    ErrorDetailDtoV1:
      type: object
      properties:
        args:
          type: object
          description: Related arguments, e.g. number => "hello world"
          additionalProperties:
            type: object
        code:
          type: string
          description: Code, e.g. NOT_FOUND.
        message:
          type: string
          description: Optional human-readable message.
  securitySchemes:
    ApiToken:
      description: >-
        Get a token from `auth/login` [endpoint](#operation/login) and then pass
        it in the `Authorization` HTTP header in every subsequent API call. For
        more information visit our [help
        center](https://support.phrase.com/hc/en-us/articles/5709662181404-API-Authentication-TMS-#token-0-0).
      type: apiKey
      name: Authorization
      in: header
    OAuth2:
      description: >-
        A standard OAuth 2.0 authorization code flow. For more information visit
        our [help
        center](https://support.phrase.com/hc/en-us/articles/5709662181404-API-Authentication-TMS-#oauth-2-0-0-1).
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://cloud.memsource.com/web/oauth/authorize
          tokenUrl: https://cloud.memsource.com/web/oauth/token
          scopes: {}

````