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

# Upsert group attributions bulk

> Upsert group attributions in bulk.

## Behavior

* **Transaction**: If one group attribution is not parsable, we raise you an
  error and import nothing. You have to fix your payload and send it to us again.
  And if the answer is a success, it means that every group attribution you sent
  us have been upserted
* **Conflict Rule and upsert**: Be careful, each user can only have one group by
  dimension for a given period. Given new attributions dates will override
  conflicting dates already present in Qobra.
  Also, if you send a payload with two groups attributions for the same user over
  the same period we’ll send you back an error.
* **Limit**: you can’t update more than 200 group attributions at a time.
* **Error behavior**: In case of any error, your group attributions wont be upserted


## OpenAPI

````yaml put /v1/users/groups/bulk
openapi: 3.0.2
info:
  version: 1.0.0
  title: Qobra API
  description: API documentation for Qobra
servers:
  - url: https://api.qobra.co
    description: API
security: []
paths:
  /v1/users/groups/bulk:
    put:
      tags:
        - public_api
        - v1
        - users
      summary: Upsert group attributions bulk
      description: Upsert group attributions in bulk.
      operationId: PUT_/v1/users/groups/bulk
      requestBody:
        description: >-
          The body contains the user data necessary to create a new user in
          Qobra
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/PutManyInputModel_GroupAttributionPutBodyModel
            examples:
              group-bulk-body:
                $ref: >-
                  #/components/examples/PutManyInputModel_GroupAttributionPutBodyModelExample
        required: true
      responses:
        '200':
          description: Success operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GroupsBulkPutSuccessModelResponse'
              examples:
                group-bulk-success:
                  $ref: >-
                    #/components/examples/GroupsBulkPutSuccessModelResponseExample
        '400':
          description: ClientError operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GroupsBulkPutClientErrorModelResponse'
              examples:
                group-bulk-errors:
                  $ref: >-
                    #/components/examples/GroupsBulkPutClientErrorModelResponseExample
      security:
        - api_key: []
components:
  schemas:
    PutManyInputModel_GroupAttributionPutBodyModel:
      type: object
      properties:
        data:
          title: Data
          type: array
          items:
            $ref: '#/components/schemas/GroupAttributionPutBodyModel'
      required:
        - data
      title: PutManyInputModel[GroupAttributionPutBodyModel]
    GroupsBulkPutSuccessModelResponse:
      type: object
      properties:
        count:
          description: Upserted groups attribution count
          type: integer
        data:
          description: Array of upserted attributions
          type: array
          items:
            $ref: '#/components/schemas/GroupsBulkSuccessModelResponse'
      required:
        - count
        - data
      title: GroupsBulkPutSuccessModelResponse
    GroupsBulkPutClientErrorModelResponse:
      type: object
      properties:
        count:
          description: Errors count
          type: integer
        errors:
          description: Array of errors
          type: array
          items:
            $ref: '#/components/schemas/GroupsBulkClientErrorModelResponse'
      required:
        - count
        - errors
      title: GroupsBulkPutClientErrorModelResponse
    GroupAttributionPutBodyModel:
      type: object
      properties:
        user:
          title: User
          type: string
          format: email
          description: Unique identifier of the user to be attributed
        group_dimension:
          title: Group Dimension
          type: string
          description: Api key of the group dimension
        group:
          title: Group
          type: string
          description: Api key of the group
        start_date:
          title: Start Date
          type: string
          description: >-
            Date of the start of the group attribution. Will default to the
            start of the month of your api call
          format: date
        end_date:
          title: End Date
          type: string
          description: >-
            Date of the end of the group attribution. Not providing it will will
            create an indeterminate attribution
          format: date
      required:
        - user
        - group_dimension
        - group
      title: GroupAttributionPutBodyModel
    GroupsBulkSuccessModelResponse:
      type: object
      properties:
        user:
          description: Email of the user
          type: string
          format: email
        group_dimension:
          description: Api key of the group dimension
          type: string
        group:
          description: Api key of the group
          type: string
        start_date:
          description: Date of the start of the group attribution
          type: string
          format: date
        end_date:
          description: Date of the end of the group attribution
          type: string
          format: date
      required:
        - user
        - group_dimension
        - group
        - start_date
      title: GroupsBulkSuccessModelResponse
    GroupsBulkClientErrorModelResponse:
      type: object
      properties:
        error:
          description: Type of the error
          type: string
        user:
          description: Email of the user upserted in error
          type: string
          format: email
        resource:
          description: Related resource in error
          type: string
        description:
          description: Description of the error
          type: string
      required:
        - error
        - user
        - resource
        - description
      title: GroupsBulkClientErrorModelResponse
  examples:
    PutManyInputModel_GroupAttributionPutBodyModelExample:
      value:
        data:
          - user: user-1@company.com
            group_dimension: country
            group: france
            start_date: 2023-01
            end_date: 2023-10
          - user: user-2@company.com
            manager: manager-2@company.com
          - ...
    GroupsBulkPutSuccessModelResponseExample:
      value:
        count: <Upserted manager relationships count>
        data:
          - user: user-1@company.com
            group_dimension: country
            group: france
            start_date: 2023-01
            end_date: 2023-10
          - user: user@company.com
            group_dimension: country
            group: belgium
            start_date: 2023-03
            end_date: null
          - ...
    GroupsBulkPutClientErrorModelResponseExample:
      value:
        count: <Errors count>
        errors:
          - error: NotFoundError
            user: user-3@company.com
            resource: group_dimension
            description: Group dimension not found for country
          - error: NotFoundError
            user: user-4@company.com
            resource: group
            description: Group not found for france
          - error: ParsingError
            user: user-test-4@company.com
            resource: <field_name>
            description: >-
              We had issues parsing the <field_name> provided : value
              <value_received>
          - ...
  securitySchemes:
    api_key:
      type: apiKey
      name: X-API-Key
      in: header

````