> ## 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.

> Removes a branch and the sub-tree behind it.

# Delete Condition Branch

<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>

<Warning>
  This deletes the branch's whole sub-tree — its sub-sequence, its steps, and every sequence only
  reachable through it, however deep. It cannot be undone.
</Warning>

`removedSequenceIds` lists exactly what was deleted alongside the branch entry. A sequence another
step still points at is left alone, so the list can be shorter than the sub-tree you walked, and it
is empty when the branch held no steps of its own.

## What is refused

| Case                                           | Response                                                                         |
| ---------------------------------------------- | -------------------------------------------------------------------------------- |
| The Else branch                                | `400` `SEQUENCE_BRANCH_IS_FALLBACK` — a condition step always keeps its fallback |
| The step's last branch besides Else            | `400` `SEQUENCE_BRANCH_LAST_NOT_REMOVABLE` — delete the whole step instead       |
| Leads have entered the campaign                | `409` `SEQUENCE_BRANCH_CAMPAIGN_RUNNING`                                         |
| A lead is sitting anywhere inside the sub-tree | `409` `SEQUENCE_BRANCH_CAMPAIGN_RUNNING`                                         |

The last check is run before anything is written, so a refusal leaves the step untouched.


## OpenAPI

````yaml delete /sequences/{sequenceId}/steps/{stepId}/branches/{branchSequenceId}
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/{branchSequenceId}:
    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
      - name: branchSequenceId
        in: path
        required: true
        description: >-
          The branch's own sub-sequence id, from `GET
          /sequences/{sequenceId}/steps/{stepId}/branches`. A branch is never
          addressed by its position.
        example: seq_jacL5GNH3YpNnuNQ2
        schema:
          type: string
    delete:
      tags:
        - Sequences
      summary: Delete Condition Branch
      description: >-
        Removes a branch and the whole sub-tree behind it - the branch's own
        sub-sequence, and every sequence only reachable through it.
        `removedSequenceIds` lists what was deleted alongside the branch entry;
        a sequence another step still points at is left alone.


        A step keeps at least one branch besides Else, and the Else branch
        itself is never removable. Removal is refused once leads have entered
        the campaign, and again while any lead sits anywhere inside the
        sub-tree.
      parameters: []
      responses:
        '200':
          description: The branch is gone.
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  removedSequenceIds:
                    type: array
                    items:
                      type: string
                    description: >-
                      The sub-tree sequences deleted with the branch. Empty when
                      the branch held no steps of its own.
              example:
                ok: true
                removedSequenceIds:
                  - seq_xzrGLxhZwoo5oxukc
        '400':
          description: >-
            `SEQUENCE_BRANCH_LAST_NOT_REMOVABLE` - this is the step's only
            branch besides Else. `SEQUENCE_BRANCH_IS_FALLBACK` - the Else branch
            cannot be removed. `SEQUENCE_BRANCH_INVALID_PARAM` - a path
            identifier is malformed.
          content:
            application/json:
              example:
                error: A condition step must keep at least one branch
                code: SEQUENCE_BRANCH_LAST_NOT_REMOVABLE
        '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`, `SEQUENCE_STEP_NOT_FOUND` or
            `SEQUENCE_BRANCH_NOT_FOUND` - no such sequence, step, or branch on
            that step.
          content:
            application/json:
              example:
                error: No branch with this sequenceId on this step
                code: SEQUENCE_BRANCH_NOT_FOUND
        '405':
          description: Method not allowed - this path accepts PATCH and DELETE
        '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:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic

````