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

# Upsert a User

> Endpoint facilitating the programatic upsertion of a user. Users must be upserted 1 at a time. Events created for this user are for historical tracking purposes. Any event tied to a user through this endpoint will not trigger a study through Sprig's SDK. Attributes and attribute values can be created and tied to a user through this endpoint.



## OpenAPI

````yaml reference/sprig-api.json POST /v2/users
openapi: 3.1.0
info:
  contact:
    email: support@sprig.com
    name: Support
  description: >-
    Sprig is a continuous product research tool that helps you automatically
    capture the user insights you need to consistently improve your product,
    user experience, marketing, and more.


    While traditional studies are slow, difficult to target, and lack context,
    Sprig studies are delivered automatically to specific users at specific
    moments throughout the customer journey — all within the product experience.


    This API provides tools to manage users and studies. User management is used
    if you are segmenting your samples between visitors that will be tracked
    with an ID and unregistered visitors. Study export tools will allow you to
    take results data and send it to another data store or format results for
    presentation in other applications
  title: Sprig API
  version: 2.2.1
servers:
  - url: https://api.sprig.com
security: []
tags:
  - description: Operations allowing export of survey data
    name: V1
  - description: Operations allowing export of survey data
    name: V1
  - description: All operations pertaining to the user object
    name: users
  - description: All operations pertaining to the user events
    name: events
  - description: Operations allowing export of survey data
    name: V1
paths:
  /v2/users:
    parameters: []
    post:
      tags:
        - V2
      summary: Upsert a User
      description: >-
        Endpoint facilitating the programatic upsertion of a user.

        Users must be upserted 1 at a time.

        Events created for this user are for historical tracking purposes. Any
        event tied to a user through this endpoint will not trigger a study
        through Sprig's SDK.

        Attributes and attribute values can be created and tied to a user
        through this endpoint.
      operationId: post-user-v2
      parameters:
        - $ref: '#/components/parameters/Authorization-API-Key'
      requestBody:
        content:
          application/json:
            examples:
              example user:
                value:
                  attributes:
                    customer: 'true'
                  email: user@test.com
                  events:
                    - event: login
                      timestamp: 1626448859836
                  userId: '12347'
            schema:
              properties:
                attributes:
                  description: Key value pairs of attributes
                  properties:
                    attributeName:
                      description: >-
                        Attribute name and value. Attributes limited to total of
                        100 values
                      type: string
                  type: object
                emailAddress:
                  description: Valid Email to track visitor by
                  type: string
                events:
                  items:
                    properties:
                      event:
                        description: Name of event already being tracked in Sprig
                        type: string
                      timestamp:
                        description: Unix timestamp in milliseconds
                        type: integer
                    type: object
                  type: array
                userId:
                  description: Existing or desired id for visitor
                  type: string
              required:
                - userId
              type: object
        description: Post the necessary fields for the API to upsert a new user.
      responses:
        '202':
          $ref: '#/components/responses/202'
        '400':
          $ref: '#/components/responses/400'
        '422':
          $ref: '#/components/responses/422'
        '500':
          $ref: '#/components/responses/500'
components:
  parameters:
    Authorization-API-Key:
      description: API-Key YOUR_API_KEY
      in: header
      name: Authorization
      required: true
      schema:
        type: string
  responses:
    '202':
      description: Accepted
    '400':
      content:
        application/json:
          schema:
            properties:
              error:
                type: string
      description: Bad Request
    '422':
      description: Unprocessable Entity
    '500':
      description: Something went wrong on Sprig's side. These are very rare :)

````