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

# Update User Group

> Renames a user group, replaces its members, or both.

> [!WARNING]
>
> User groups are in beta. To use these endpoints now, contact your lemlist
> account manager.

> [!NOTE]
>
> Admins only: the API key must have been created by an admin of the team.

A field left out keeps its value; send at least one. `userIds` replaces the whole member list. To add or remove a few members without sending the whole list, use [Edit User Group Members](https://developer.lemlist.com/api-reference/endpoints/user-groups/edit-user-group-members.md).

## Error codes

| Code | Cause |
| - | - |
| `USER_GROUPS_INVALID_REQUEST` | The body sends neither `name` nor `userIds`, `name` is empty once trimmed or longer than 60 characters, or `userIds` is not an array of at most 1,000 user ids. |
| `USER_NOT_IN_TEAM` | A user id is not a member of your team. |
| `USER_GROUPS_PLAN_REQUIRED` | Your team is not on the Enterprise plan, or the user groups beta is not enabled for it. |
| `USER_NOT_AUTHORIZED` | The API key was created by a team member who is not an admin. |
| `USER_GROUPS_NOT_FOUND` | No group with this id in your team. |
| `USER_GROUPS_NAME_TAKEN` | Another group of your team has this name, whatever its case. |


## OpenAPI

````yaml patch /v2/user-groups/{userGroupId}
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: []
tags:
  - name: Enrichment Providers
    description: >-
      The data providers lemlist can call to find an email or a phone.


      Internal providers are paid with lemlist credits and always available.
      External providers run on your own account: connect one by saving its API
      key, and it becomes available to your waterfalls. `GET
      /enrichments/providers` is the catalog of provider ids accepted by the
      waterfall endpoints.
  - name: Enrichment Waterfalls
    description: >-
      Control which data providers lemlist calls when enriching a contact, and
      in which order.


      A waterfall is an ordered list of providers for one enrichment `type`
      (`email` or `phone`). Providers are tried one after the other until one
      returns a result.


      Every team has exactly one default waterfall per type (`isDefault: true`).
      While its `editor` is `lemlist` it follows the lemlist behaviour:
      providers you connected with your own API key are tried first, then
      internal providers in a random order. Once a team member edits its
      provider list, `editor` becomes that user's id and the list is followed as
      is; resetting it hands it back to `lemlist`.


      Custom waterfalls (`isDefault: false`) carry `conditions` on the contact
      being enriched, keyed by contact property; every key present must match.
      When a contact is enriched, lemlist runs a single waterfall: the custom
      waterfall of the requested type whose conditions match the contact, or the
      default waterfall when none does. If several match, the one with the most
      condition keys wins, then the most recently updated. Only that waterfall
      runs; when it finds nothing, the enrichment ends without falling back to
      another one.
  - name: User Groups
    description: >-
      Gather your team's users into groups (UK, FR, US…), so a manager filters
      Reports, Tasks and Campaigns by group in one click. Available on the
      Enterprise plan.


      Any member of the team reads the groups; only an admin creates, edits and
      deletes them. An API key acts on behalf of the team member who created it,
      so the write endpoints need a key created by an admin.


      A group name is unique in the team, whatever its case, and holds 1 to 60
      characters. A group holds at most 1,000 members and a team at most 100
      groups. A user can belong to several groups, and a user removed from the
      team leaves every group. Deleting a group also removes it from the
      Reports, Tasks and Campaigns filters saved on it.
paths:
  /v2/user-groups/{userGroupId}:
    parameters:
      - name: userGroupId
        in: path
        required: true
        description: >-
          Id of the group, as returned by the list endpoint. A malformed id
          answers `404`.
        schema:
          type: string
        example: ugr_ExAmPlE123456789a
    patch:
      tags:
        - User Groups
      summary: Update User Group
      description: >-
        **Beta**: to use this endpoint now, contact your lemlist account
        manager.


        Renames a group, replaces its whole member list, or both. Admins only.


        A field left out keeps its value; send at least one. To add or remove a
        few members without sending the whole list, use the members endpoint.
        The group is returned as stored.
      operationId: updateUserGroup
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UserGroupUpdateRequest'
            example:
              name: United Kingdom
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserGroupResponse'
              example:
                data:
                  id: ugr_ExAmPlE123456789a
                  name: United Kingdom
                  userIds:
                    - usr_ExAmPlE123456789a
                    - usr_ExAmPlE123456789b
        '400':
          description: >-
            Validation error. `code` is one of `USER_GROUPS_INVALID_REQUEST`,
            `USER_NOT_IN_TEAM` (a user id is not a member of the team).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserGroupError'
              example:
                error: >-
                  Invalid request: name holds 1 to 60 characters once trimmed,
                  userIds is an array of at most 1,000 user ids, a PATCH sends
                  name or userIds, and no user is both added and removed
                code: USER_GROUPS_INVALID_REQUEST
        '401':
          $ref: '#/components/responses/UserGroupUnauthorized'
        '403':
          $ref: '#/components/responses/UserGroupForbidden'
        '404':
          $ref: '#/components/responses/UserGroupNotFound'
        '409':
          description: >-
            Another group of the team holds this name, whatever its case. `code`
            is `USER_GROUPS_NAME_TAKEN`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserGroupError'
              example:
                error: A user group already has this name
                code: USER_GROUPS_NAME_TAKEN
        '500':
          $ref: '#/components/responses/UserGroupInternalError'
components:
  schemas:
    UserGroupUpdateRequest:
      type: object
      description: At least one of `name` and `userIds`. A field left out keeps its value.
      minProperties: 1
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 60
          description: >-
            Unique in the team, whatever its case. Trimmed, with its inner
            spaces collapsed.
        userIds:
          type: array
          items:
            type: string
          maxItems: 1000
          description: >-
            The whole member list, replacing the previous one; `[]` empties the
            group.
    UserGroupResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/UserGroup'
    UserGroupError:
      type: object
      description: Error envelope returned by the user group endpoints.
      properties:
        error:
          type: string
          description: Human-readable explanation of the failure
        code:
          type: string
          description: Machine-readable error code, stable across releases
    UserGroup:
      type: object
      description: A group of team members.
      required:
        - id
        - name
        - userIds
      properties:
        id:
          type: string
          description: Id of the group, starting with `ugr_`.
          example: ugr_ExAmPlE123456789a
        name:
          type: string
          description: Name of the group, unique in the team whatever its case.
          example: UK
        userIds:
          type: array
          items:
            type: string
          description: Ids of the team members in the group, each once.
          example:
            - usr_ExAmPlE123456789a
            - usr_ExAmPlE123456789b
  responses:
    UserGroupUnauthorized:
      description: Unauthorized - invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserGroupError'
          example:
            error: Route unauthorized
            code: ROUTE_UNAUTHORIZED
    UserGroupForbidden:
      description: >-
        Forbidden. `code` is `USER_GROUPS_PLAN_REQUIRED` when the team is not on
        the Enterprise plan or the user groups beta is not enabled for it,
        `USER_NOT_AUTHORIZED` when the API key was created by a team member who
        is not an admin.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserGroupError'
          example:
            error: User not authorized
            code: USER_NOT_AUTHORIZED
    UserGroupNotFound:
      description: No group with this id in your team. `code` is `USER_GROUPS_NOT_FOUND`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserGroupError'
          example:
            error: This user group no longer exists
            code: USER_GROUPS_NOT_FOUND
    UserGroupInternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserGroupError'
          example:
            error: Internal error
            code: INTERNAL_ERROR
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.