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

> Rewrites the execution priority of a condition step's branches.

# Reorder Condition Branches

<Note>
  New to condition branches? Start with
  [List Condition Branches](/api-reference/endpoints/sequences/list-condition-branches), which explains
  how a step branches and how a branch is addressed.
</Note>

Order **is** priority: lemlist tests the branches in array order and the first match wins. Reordering
is therefore a behaviour change, not cosmetics — a lead matching two branches follows whichever comes
first.

`order` must list every non-fallback branch of the step **exactly once**, by `sequenceId`. Leave the
Else branch out: it is not orderable and always stays last. A list that repeats a branch, omits one,
or names an id that is not a branch of this step is refused with `SEQUENCE_BRANCH_ORDER_INVALID`.

Sending the order the step already has changes nothing and still returns the branches.

<Warning>
  Reordering is refused with `409` once leads have entered the campaign: leads already sitting in a
  branch were routed there under the old priority. See
  [Editing a running campaign](/api-reference/endpoints/sequences/list-condition-branches#editing-a-running-campaign).
</Warning>

## Why PATCH on the collection

The reorder is a `PATCH` on `…/branches` rather than on a `…/branches/order` sub-path, which would
collide with the `{branchSequenceId}` segment. `PATCH …/branches` reorders; `PATCH …/branches/{id}`
edits one branch.


## OpenAPI

````yaml patch /sequences/{sequenceId}/steps/{stepId}/branches
openapi: 3.0.0
info:
  title: lemlist API
  version: 1.0.0
  description: >-
    Welcome to the lemlist Developer Documentation.


    lemlist is very customizable and open. You'll find on this page all the API
    and integration you can do with lemlist.


    # Rate Limit


    lemlist's API rate limits requests in order to prevent abuse and overload of
    our services.  

    Rate limits are applied on all routes and per API key performing the
    request.  

    The rate limits are **20** requests per **2** seconds.  

    The response provides any information you may need about it:


    | Header | Description |

    | --- | --- |

    | Retry-After | The number of seconds in which you can retry |

    | X-RateLimit-Limit | The maximum requests in that time |

    | X-RateLimit-Remaining | The number of remaining requests you can make |

    | X-RateLimit-Reset | The date when the rate limit will reset |


    _Example of values for the rate limit headers_


    ``` json

    {
        "Retry-After": 2,
        "X-RateLimit-Limit": 20,
        "X-RateLimit-Remaining": 7,
        "X-RateLimit-Reset" : "Tue Feb 16 2021 09:02:42 GMT+0100 (Central European Standard Time)"
    }

     ```

    # Definitions


    ## Team


    A team is the entity of lemlist that can handle users and billing.


    ## Credits


    Credits are the coins a team uses to enrich emails, LinkedIn URLs, etc. via
    the enrich route. Each enrichment feature needs a certain amount of credits
    to run.


    ## User


    You use a user account to connect to lemlist and send messages via the
    connected emails or LinkedIn account.


    ## Campaign


    A campaign is the entity to automate outreach. A campaign has multiple
    sequences composed of steps.


    ## Lead


    A lead is a person that you try to contact via a campaign.


    ## Activity


    An activity is the history of all the steps.


    ## Unsubscribe


    An unsubscribe occurs when a person decides they don't want to receive
    emails from you anymore.


    # Authentication


    All API routes use the dedicated subdomain `api.lemlist.com`.


    lemlist uses API keys to allow access to the API. You can get your lemlist
    API key at our [integration
    page](https://app.lemlist.com/settings/integrations).


    You need to add the `Authorization` header using the `Basic` authentication
    type. `login:password` **where the login is always empty and the password is
    the API key**.


    ⚠️ **Don't forget to add the semicolon (**`:`**) before your API key in curl
    command.**


    > To authorize, use this code: 
      

    ``` shell

    curl https://api.lemlist.com/api/team \
      --user ":YourApiKey"

     ```

    **Make sure to replace** **`YourApiKey`** **with your API key.**


    # Give feedback


    If you want to report a bug, ask for data, or share with us a use case,
    please fill this [form](https://lemlist.typeform.com/to/mfVlkyGf). It will
    help us centralize your needs!
servers:
  - url: https://api.lemlist.com/api
security:
  - basicAuth: []
paths:
  /sequences/{sequenceId}/steps/{stepId}/branches:
    parameters:
      - name: sequenceId
        in: path
        required: true
        description: The unique identifier of the sequence holding the condition step
        example: seq_lkCSKd32qSZZTe5Ru
        schema:
          type: string
      - name: stepId
        in: path
        required: true
        description: >-
          The unique identifier of the condition step, from `GET
          /campaigns/{campaignId}/sequences`
        example: stp_Ae93hiemDkypHLys2
        schema:
          type: string
    patch:
      tags:
        - Sequences
      summary: Reorder Condition Branches
      description: >-
        Rewrites the execution priority of a condition step's branches. Order is
        priority: the first branch whose test matches takes the lead.


        `order` must list every non-fallback branch of the step exactly once.
        The Else branch is not orderable and always stays last, so it is left
        out of the list. Sending the order the step already has is a no-op that
        still returns the branches.
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - order
              properties:
                order:
                  type: array
                  items:
                    type: string
                  description: >-
                    Every branch of the step by `sequenceId`, in the new
                    execution order, excluding the Else branch.
            example:
              order:
                - seq_xzrGLxhZwoo5oxukc
                - seq_jacL5GNH3YpNnuNQ2
      responses:
        '200':
          description: The branches, in their new order.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ConditionBranch'
              example:
                - sequenceId: seq_xzrGLxhZwoo5oxukc
                  index: 0
                  key: customLeadInfo
                  customField: variables.jobTitle
                  customOperator: contains
                  customValues:
                    - CTO
                - sequenceId: seq_jacL5GNH3YpNnuNQ2
                  index: 1
                  key: customLeadInfo
                  name: Decision makers
                  customField: variables.jobTitle
                  customOperator: contains
                  customValues:
                    - CEO
                    - Founder
                - sequenceId: seq_Kd8pQrLm3Nv6Tz0Wy
                  fallback: true
        '400':
          description: >-
            `SEQUENCE_BRANCH_ORDER_INVALID` - `order` is missing, is not an
            array of strings, repeats a branch, omits one, or names an id that
            is not a branch of this step.
          content:
            application/json:
              example:
                error: >-
                  order must list every branch of this step exactly once,
                  excluding the Else branch
                code: SEQUENCE_BRANCH_ORDER_INVALID
        '401':
          description: Unauthorized - invalid or missing API key
          content:
            text/plain:
              example: The authentication you supplied is incorrect
        '402':
          description: >-
            The team's plan is below the Email Pro floor every sequence route
            sits on.
          content:
            text/plain:
              example: route is available starting emailPro plan
        '403':
          description: >-
            `SEQUENCE_BRANCH_BETA_REQUIRED` - branch writes are in closed beta
            and answer `403` unless the beta is enabled for your team. Reading
            branches is not gated.
          content:
            application/json:
              example:
                error: Condition branches are not enabled for this team
                code: SEQUENCE_BRANCH_BETA_REQUIRED
        '404':
          description: >-
            `SEQUENCE_NOT_FOUND` or `SEQUENCE_STEP_NOT_FOUND` - no such sequence
            in this workspace, or no such step on it.
          content:
            application/json:
              example:
                error: Step not found
                code: SEQUENCE_STEP_NOT_FOUND
        '405':
          description: Method not allowed - this path accepts GET, POST and PATCH
        '409':
          description: >-
            `SEQUENCE_BRANCH_CAMPAIGN_RUNNING` - leads have entered the
            campaign, which freezes the branch structure. Renaming a branch
            stays allowed.
          content:
            application/json:
              example:
                error: >-
                  You cannot add, remove or reorder branches once leads have
                  entered the campaign
                code: SEQUENCE_BRANCH_CAMPAIGN_RUNNING
        '429':
          description: Rate limit exceeded - 20 requests per 2 seconds per API key
components:
  schemas:
    ConditionBranch:
      type: object
      description: >-
        One branch of a condition step. Addressed by `sequenceId` - the
        sub-sequence its leads walk - never by position. The fields describing
        what the branch tests depend on the step's condition; the ones that do
        not apply are absent.
      properties:
        sequenceId:
          type: string
          description: >-
            The branch's sub-sequence id, and its address on every branch
            endpoint. Pass it to `POST /sequences/{sequenceId}/steps` to add
            steps inside the branch.
        index:
          type: integer
          description: >-
            Execution rank among the non-fallback branches, starting at 0. The
            first branch whose test matches takes the lead. Absent on the Else
            branch, which always runs last.
        fallback:
          type: boolean
          description: >-
            `true` on the Else branch - the one that catches every lead no other
            branch matched. Absent on the others.
        key:
          type: string
          description: >-
            The condition the step tests. Every branch of a step shares it: a
            branch never carries a condition of its own.
        name:
          type: string
          description: >-
            The branch's display name, present only when someone has set one.
            lemlist labels the unnamed ones "Branch 1", "Branch 2", … and
            "Else"; those defaults are not stored and are not returned here.
        delay:
          type: integer
          description: >-
            Length of the time window the condition waits on the lead's action,
            in days. Only on the lead-action conditions that store one.
        delayType:
          type: string
          enum:
            - within
            - waitUntil
          description: >-
            How the condition waits: `within` branches once the window is over,
            `waitUntil` parks the lead until the action happens, with no time
            bound.
        scoreComparator:
          type: string
          enum:
            - $gte
            - $lt
          description: >-
            `hasScore` only - how the lead's score is compared to
            `scoreThreshold`.
        scoreThreshold:
          type: integer
          description: '`hasScore` only - the score this branch tests against.'
        emailStatusFilter:
          type: array
          items:
            type: string
            enum:
              - deliverable
              - risky
              - undeliverable
              - unverified
          description: '`hasEmailAddress` only - the email statuses this branch matches.'
        callStatusFilter:
          type: array
          items:
            type: string
          description: '`aircallDone` only - the call-status keys this branch matches.'
        customField:
          type: string
          description: >-
            `customLeadInfo` only - the tested field, normalized: a lead
            variable reads back as `variables.<name>`, a contact field as
            `fields.<name>`. Every branch of the step tests the same field.
        customOperator:
          type: string
          enum:
            - equal
            - contains
            - empty
            - notEmpty
          description: >-
            `customLeadInfo` only - how the field is compared to the tested
            values.
        customValues:
          type: array
          items:
            type: string
          description: >-
            `customLeadInfo` only - every value this branch tests; the branch
            matches when any of them does. Empty for the `empty` and `notEmpty`
            operators.
        selector:
          type: string
          description: >-
            The raw stored condition selector, as JSON. Returned only when none
            of the fields above could describe the branch.
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic

````