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

# Upsert segments with the provided information.

> Upsert segments with the provided information.



## OpenAPI

````yaml /openapi.json put /public/v1/segment-service/segments
openapi: 3.1.0
info:
  title: Topsort Endpoints v2 API Reference
  description: >
    In order for a storefront to be able to run auctions in Topsort and report
    auction-related events back to Topsort,

    both the `/v2/auctions` and `/v2/events` endpoints must be integrated.

    Below are the endpoint and model definitions for each.
  contact:
    email: wicha@topsort.com
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  x-logo:
    url: https://assets.topsort.com/Topsort_logo_icon_dark.svg
    backgroundColor: '#fff'
    altText: Topsort
  version: 2.0.0
servers:
  - url: https://api.topsort.com
    description: Base API URL
security: []
tags:
  - name: Auctions
    description: >-
      An auction determines which products should be promoted based on the
      vendors' bids.
  - name: Events
    description: >-
      Events are sent to Topsort as part of the attribution and reporting
      journey.
  - name: Toptimize
    description: >
      An out-of-the-box solution for prediction, ranking, retrieval, and other
      elements of ad selection.
  - name: Toppie API
    description: Toppie management API.
  - name: Campaign API
    description: Full-featured campaign management API for banners and sponsored listings.
  - name: Catalog API
    description: Products catalog management API.
  - name: Billing API
    description: Marketplace and Vendor Billing management API.
  - name: Reporting API
    description: Marketplace, Vendor, Campaign, and product reporting API.
  - name: Invitation API
    description: Vendor invitations management API.
  - name: User API
    description: User management API.
  - name: Webhooks API
    description: Webhooks API that allows event-driven automation.
  - name: Assets API
    description: Assets management API.
  - name: Segments Service
    description: Segments Service.
  - name: Forecasting Service
    description: Toptimize Forecasting Service.
  - name: Offsite Ads API
    description: Offsite Ads API that allows to manage offsite ads campaigns.
  - name: Media API
    description: Ad configuration API.
  - name: Placement API
    description: Placement management API for sponsored brand slots.
paths:
  /public/v1/segment-service/segments:
    put:
      tags:
        - Segments Service
      summary: Upsert segments with the provided information.
      description: Upsert segments with the provided information.
      operationId: upsert_segments
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Advanced_APIs_PublicSegmentsUpsertRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Advanced_APIs_PublicSegmentsResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Advanced_APIs_HTTPValidationError'
      security:
        - Advanced_APIs_HTTPBearer: []
components:
  schemas:
    Advanced_APIs_PublicSegmentsUpsertRequest:
      properties:
        segments:
          items:
            $ref: '#/components/schemas/Advanced_APIs_PublicSegmentUpsert'
          type: array
          title: Segments
          description: List of segments to update.
      type: object
      required:
        - segments
      title: PublicSegmentsUpsertRequest
    Advanced_APIs_PublicSegmentsResponse:
      properties:
        segments:
          items:
            $ref: '#/components/schemas/Advanced_APIs_PublicSegmentResponse'
          type: array
          title: Segments
          description: List of segments.
      type: object
      required:
        - segments
      title: PublicSegmentsResponse
    Advanced_APIs_HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/Advanced_APIs_ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    Advanced_APIs_PublicSegmentUpsert:
      properties:
        name:
          type: string
          maxLength: 64
          title: Name
          description: Name of the segment.
        description:
          title: Description
          description: Description of the segment.
          oneOf:
            - type: string
              maxLength: 400
            - type: 'null'
        id:
          type: string
          maxLength: 64
          minLength: 1
          title: Id
          description: ID of the segment.
        config:
          oneOf:
            - $ref: '#/components/schemas/Advanced_APIs_PublicUserListSegmentConfig'
            - $ref: >-
                #/components/schemas/Advanced_APIs_PublicBehavioralSegmentConfig-Input
          title: Config
          description: User-list or behavioral segment configuration.
          discriminator:
            propertyName: type
            mapping:
              behavioral: >-
                #/components/schemas/Advanced_APIs_PublicBehavioralSegmentConfig-Input
              user-list: '#/components/schemas/Advanced_APIs_PublicUserListSegmentConfig'
      type: object
      required:
        - name
        - description
        - id
      title: PublicSegmentUpsert
    Advanced_APIs_PublicSegmentResponse:
      properties:
        name:
          type: string
          maxLength: 64
          title: Name
          description: Name of the segment.
        description:
          title: Description
          description: Description of the segment.
          oneOf:
            - type: string
              maxLength: 400
            - type: 'null'
        id:
          type: string
          title: Id
          description: ID of the segment.
        total:
          type: integer
          title: Total
          description: User count of the segment.
        config:
          oneOf:
            - $ref: '#/components/schemas/Advanced_APIs_PublicUserListSegmentConfig'
            - $ref: >-
                #/components/schemas/Advanced_APIs_PublicBehavioralSegmentConfig-Output
            - $ref: '#/components/schemas/Advanced_APIs_PublicCombinedSegmentConfig'
          title: Config
          description: Public segment configuration.
          discriminator:
            propertyName: type
            mapping:
              behavioral: >-
                #/components/schemas/Advanced_APIs_PublicBehavioralSegmentConfig-Output
              combined: '#/components/schemas/Advanced_APIs_PublicCombinedSegmentConfig'
              user-list: '#/components/schemas/Advanced_APIs_PublicUserListSegmentConfig'
      type: object
      required:
        - name
        - description
        - id
        - total
        - config
      title: PublicSegmentResponse
    Advanced_APIs_ValidationError:
      properties:
        loc:
          items:
            oneOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    Advanced_APIs_PublicUserListSegmentConfig:
      properties:
        type:
          type: string
          const: user-list
          title: Type
          description: Type of the user-list segment config.
      type: object
      required:
        - type
      title: PublicUserListSegmentConfig
    Advanced_APIs_PublicBehavioralSegmentConfig-Input:
      properties:
        type:
          type: string
          const: behavioral
          title: Type
          description: Type of the behavioral segment config.
        definition:
          $ref: >-
            #/components/schemas/Advanced_APIs_PublicBehavioralSegmentConfigDefinition-Input
          description: Definition of the behavioral segment config.
      type: object
      required:
        - type
        - definition
      title: PublicBehavioralSegmentConfig
    Advanced_APIs_PublicBehavioralSegmentConfig-Output:
      properties:
        type:
          type: string
          const: behavioral
          title: Type
          description: Type of the behavioral segment config.
        definition:
          $ref: >-
            #/components/schemas/Advanced_APIs_PublicBehavioralSegmentConfigDefinition-Output
          description: Definition of the behavioral segment config.
      type: object
      required:
        - type
        - definition
      title: PublicBehavioralSegmentConfig
    Advanced_APIs_PublicCombinedSegmentConfig:
      properties:
        type:
          type: string
          const: combined
          title: Type
          description: Type of the combined segment config.
      type: object
      required:
        - type
      title: PublicCombinedSegmentConfig
    Advanced_APIs_PublicBehavioralSegmentConfigDefinition-Input:
      properties:
        behaviors:
          items:
            $ref: '#/components/schemas/Advanced_APIs_PublicBehavior-Input'
          type: array
          maxItems: 3
          minItems: 1
          title: Behaviors
          description: List of behaviors.
      type: object
      required:
        - behaviors
      title: PublicBehavioralSegmentConfigDefinition
    Advanced_APIs_PublicBehavioralSegmentConfigDefinition-Output:
      properties:
        behaviors:
          items:
            $ref: '#/components/schemas/Advanced_APIs_PublicBehavior-Output'
          type: array
          maxItems: 3
          minItems: 1
          title: Behaviors
          description: List of behaviors.
      type: object
      required:
        - behaviors
      title: PublicBehavioralSegmentConfigDefinition
    Advanced_APIs_PublicBehavior-Input:
      properties:
        logic:
          $ref: '#/components/schemas/Advanced_APIs_Logic'
          description: Logic of the behavior.
          default: and
        actionType:
          $ref: '#/components/schemas/Advanced_APIs_ActionType'
          description: Type of the action.
        timeWindow:
          $ref: '#/components/schemas/Advanced_APIs_PublicTimeWindow'
          description: Time window of the action.
        frequency:
          $ref: '#/components/schemas/Advanced_APIs_PublicFrequencyConfig'
          description: Frequency definition of the action.
        parameters:
          items:
            $ref: '#/components/schemas/Advanced_APIs_PublicBehaviorParameter'
          type: array
          maxItems: 3
          minItems: 1
          title: Parameters
          description: List of behavior parameters.
      type: object
      required:
        - actionType
        - timeWindow
        - parameters
      title: PublicBehavior
    Advanced_APIs_PublicBehavior-Output:
      properties:
        logic:
          $ref: '#/components/schemas/Advanced_APIs_Logic'
          description: Logic of the behavior.
          default: and
        actionType:
          $ref: '#/components/schemas/Advanced_APIs_ActionType'
          description: Type of the action.
        timeWindow:
          $ref: '#/components/schemas/Advanced_APIs_PublicTimeWindow'
          description: Time window of the action.
        frequency:
          $ref: '#/components/schemas/Advanced_APIs_PublicFrequencyConfig'
          description: Frequency definition of the action.
        parameters:
          items:
            $ref: '#/components/schemas/Advanced_APIs_PublicBehaviorParameter'
          type: array
          maxItems: 3
          minItems: 1
          title: Parameters
          description: List of behavior parameters.
      type: object
      required:
        - actionType
        - timeWindow
        - parameters
      title: PublicBehavior
    Advanced_APIs_Logic:
      type: string
      enum:
        - and
        - not
        - or
      title: Logic
    Advanced_APIs_ActionType:
      type: string
      enum:
        - impressions
        - clicks
        - purchases
      title: ActionType
    Advanced_APIs_PublicTimeWindow:
      properties:
        value:
          type: integer
          maximum: 90
          minimum: 1
          title: Value
          description: Amount of days to look back (between 1 and 90 days).
      type: object
      required:
        - value
      title: PublicTimeWindow
    Advanced_APIs_PublicFrequencyConfig:
      properties:
        value:
          type: integer
          const: 1
          title: Value
          description: Number of times the action occurs.
          default: 1
        operator:
          $ref: '#/components/schemas/Advanced_APIs_Operator'
          description: Operator of the frequency.
          default: gte
      type: object
      title: PublicFrequencyConfig
    Advanced_APIs_PublicBehaviorParameter:
      properties:
        entityType:
          $ref: '#/components/schemas/Advanced_APIs_SegmentEntityType'
          description: Type of the entity.
        entityList:
          items:
            type: string
          type: array
          maxItems: 200
          title: Entitylist
          description: List of entity IDs.
      type: object
      required:
        - entityType
        - entityList
      title: PublicBehaviorParameter
    Advanced_APIs_Operator:
      type: string
      enum:
        - eq
        - gt
        - gte
        - lt
        - lte
      title: Operator
    Advanced_APIs_SegmentEntityType:
      type: string
      enum:
        - product
        - category
      title: SegmentEntityType
  securitySchemes:
    Advanced_APIs_HTTPBearer:
      type: http
      description: >-
        A valid API key generated in Topsort's UI. Use the TSE API key if
        calling auctions or events API, otherwise use the TSC API key.
      scheme: bearer

````

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