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

# Create Actions On Players In Segment Task

> Create an ActionsOnPlayersInSegment task, which iterates through all players in a segment to execute action.

## Error codes

This operation may return the following PlayFab errors:

| Error | Code |
| --- | --- |
| CatalogBadRequest | 4013 |
| CloudScriptAzureFunctionsArgumentSizeExceeded | 1471 |
| InvalidJSONContent | 1200 |
| InvalidParams | 1000 |
| InvalidScheduledTaskName | 1256 |
| InvalidTaskSchedule | 1257 |
| InvalidVirtualCurrencyCode | 1236 |
| OverLimit | 1214 |
| PushNotEnabledForAccount | 1094 |
| PushNotificationTemplateInvalidSyntax | 1419 |
| PushNotificationTemplateNotFound | 1417 |
| ScheduledTaskCreateConflict | 1255 |
| ScheduledTaskNameConflict | 1254 |
| StatisticNotFound | 1195 |




## OpenAPI

````yaml /services/playfab/api-references/rest/admin/admin.openapi.json post /Admin/CreateActionsOnPlayersInSegmentTask
openapi: 3.0.0
info:
  version: '260922'
  title: PlayFab Admin API
  description: >-
    APIs for managing title configurations, uploaded Game Server code
    executables, and user data
  termsOfService: https://playfab.com/terms/
  contact:
    url: https://community.playfab.com/index.html
  license:
    name: Apache 2.0
    url: https://github.com/PlayFab/API_Specs/blob/master/LICENSE
servers:
  - url: https://{titleId}.playfabapi.com
    description: PlayFab title endpoint
    variables:
      titleId:
        default: your_title_id
        description: Your PlayFab title ID (hex).
security: []
tags:
  - name: Account Management
    description: Account Management APIs
  - name: Authentication
    description: Authentication APIs
  - name: Characters
    description: Characters APIs
  - name: Content
    description: Content Service APIs
  - name: Custom Server Management
    description: Custom Server Management APIs
  - name: Matchmaking
    description: Matchmaking APIs
  - name: Player Data Management
    description: Player Data Management APIs
  - name: Player Item Management
    description: Player Item Management APIs
  - name: PlayStream
    description: PlayStream Management APIs
  - name: ScheduledTask
    description: Task management APIs
  - name: Segments
    description: Segment management APIs
  - name: Server-Side Cloud Script
    description: Server-Side Cloud Script APIs
  - name: Shared Group Data
    description: Shared Group Data APIs
  - name: Title-Wide Data Management
    description: Title-Wide Data Management APIs
  - name: Xbox Store
    description: Xbox Store APIs
paths:
  /Admin/CreateActionsOnPlayersInSegmentTask:
    post:
      tags:
        - ScheduledTask
      summary: Create Actions On Players In Segment Task
      description: >
        Create an ActionsOnPlayersInSegment task, which iterates through all
        players in a segment to execute action.


        ## Error codes


        This operation may return the following PlayFab errors:


        | Error | Code |

        | --- | --- |

        | CatalogBadRequest | 4013 |

        | CloudScriptAzureFunctionsArgumentSizeExceeded | 1471 |

        | InvalidJSONContent | 1200 |

        | InvalidParams | 1000 |

        | InvalidScheduledTaskName | 1256 |

        | InvalidTaskSchedule | 1257 |

        | InvalidVirtualCurrencyCode | 1236 |

        | OverLimit | 1214 |

        | PushNotEnabledForAccount | 1094 |

        | PushNotificationTemplateInvalidSyntax | 1419 |

        | PushNotificationTemplateNotFound | 1417 |

        | ScheduledTaskCreateConflict | 1255 |

        | ScheduledTaskNameConflict | 1254 |

        | StatisticNotFound | 1195 |
      operationId: CreateActionsOnPlayersInSegmentTask
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateActionsOnPlayerSegmentTaskRequest'
        description: >-
          Task name is unique within a title. Using a task name that's already
          taken will cause a name conflict error. Too many create-task requests
          within a short time will cause a create conflict error.
      responses:
        '200':
          $ref: '#/components/responses/CreateTaskResult'
        '400':
          $ref: '#/components/responses/ApiErrorWrapper'
      security:
        - SecretKey: []
components:
  schemas:
    CreateActionsOnPlayerSegmentTaskRequest:
      description: >-
        Task name is unique within a title. Using a task name that's already
        taken will cause a name conflict error. Too many create-task requests
        within a short time will cause a create conflict error.
      type: object
      properties:
        CustomTags:
          description: >-
            The optional custom tags associated with the request (e.g. build
            number, external trace identifiers, etc.).
          type: object
        Description:
          description: Description the task
          type: string
        IsActive:
          description: >-
            Whether the schedule is active. Inactive schedule will not trigger
            task execution.
          type: boolean
        Name:
          description: >-
            Name of the task. This is a unique identifier for tasks in the
            title.
          type: string
        Parameter:
          allOf:
            - $ref: '#/components/schemas/ActionsOnPlayersInSegmentTaskParameter'
          description: Task details related to segment and action
        Schedule:
          description: >-
            Cron expression for the run schedule of the task. The expression
            should be in UTC.
          type: string
      required:
        - Name
        - IsActive
        - Parameter
      example:
        Name: PushNotificationVIP_Halloween
        Description: Send push notification to VIP players about Halloween event
        Parameter:
          SegmentId: 274828AF93F13472
          Actions:
            - GrantItemContent:
                CatalogVersion: foo
                ItemId: bar
                ItemQuantity: 1
    ActionsOnPlayersInSegmentTaskParameter:
      type: object
      properties:
        Actions:
          description: >-
            List of actions to perform on each player in a segment. Each action
            object can contain only one action type.
          type: array
          items:
            $ref: '#/components/schemas/Action'
          x-isclass: true
        SegmentId:
          description: ID of the segment to perform actions on.
          type: string
      required:
        - SegmentId
      example:
        SegmentId: 502FD30E8C78F826
        Actions:
          - GrantItemContent:
              CatalogVersion: foo
              ItemId: bar
              ItemQuantity: 1
    CreateTaskResult:
      type: object
      properties:
        TaskId:
          description: ID of the task
          type: string
      example:
        TaskId: 644FA3A39C9714BC
    ApiErrorWrapper:
      description: The basic wrapper around every failed API response
      type: object
      properties:
        code:
          description: Numerical HTTP code
          type: integer
        status:
          description: String HTTP code
          type: string
        error:
          description: Playfab error code
          type: string
        errorCode:
          description: Numerical PlayFab error code
          type: integer
        errorMessage:
          description: Description for the PlayFab errorCode
          type: string
        errorDetails:
          description: Detailed description of individual issues with the request object
          type: object
      required:
        - code
        - errorCode
    Action:
      description: The work to be performed on each entity which can only be of one type.
      type: object
      properties:
        AddInventoryItemV2Content:
          allOf:
            - $ref: '#/components/schemas/AddInventoryItemV2Content'
          description: Action content to add inventory item v2
        BanPlayerContent:
          allOf:
            - $ref: '#/components/schemas/BanPlayerContent'
          description: Action content to ban player
        DeleteInventoryItemV2Content:
          allOf:
            - $ref: '#/components/schemas/DeleteInventoryItemV2Content'
          description: Action content to delete inventory item v2
        DeletePlayerContent:
          allOf:
            - $ref: '#/components/schemas/DeletePlayerContent'
          description: Action content to delete player
        ExecuteCloudScriptContent:
          allOf:
            - $ref: '#/components/schemas/ExecuteCloudScriptContent'
          description: Action content to execute cloud script
        ExecuteFunctionContent:
          allOf:
            - $ref: '#/components/schemas/ExecuteFunctionContent'
          description: Action content to execute azure function
        GrantItemContent:
          allOf:
            - $ref: '#/components/schemas/GrantItemContent'
          description: Action content to grant item
        GrantVirtualCurrencyContent:
          allOf:
            - $ref: '#/components/schemas/GrantVirtualCurrencyContent'
          description: Action content to grant virtual currency
        IncrementPlayerStatisticContent:
          allOf:
            - $ref: '#/components/schemas/IncrementPlayerStatisticContent'
          description: Action content to increment player statistic
        PushNotificationContent:
          allOf:
            - $ref: '#/components/schemas/PushNotificationContent'
          description: Action content to send push notification
        SendEmailContent:
          allOf:
            - $ref: '#/components/schemas/SendEmailContent'
          description: Action content to send email
        SubtractInventoryItemV2Content:
          allOf:
            - $ref: '#/components/schemas/SubtractInventoryItemV2Content'
          description: Action content to subtract inventory item v2
    AddInventoryItemV2Content:
      type: object
      properties:
        Amount:
          description: Amount of the item to be granted to a player
          type: number
          x-actualtype: int32
        CollectionId:
          description: >-
            The collection id for where the item will be granted in the player
            inventory
          type: string
        DurationInSeconds:
          description: >-
            The duration in seconds of the subscription to be granted to a
            player
          type: number
          x-actualtype: int32
        ItemId:
          description: The id of item to be granted to the player
          type: string
        StackId:
          description: >-
            The stack id for where the item will be granted in the player
            inventory
          type: string
    BanPlayerContent:
      type: object
      properties:
        BanDurationHours:
          description: >-
            Duration(in hours) to ban a player. If not provided, the player will
            be banned permanently.
          type: number
          x-actualtype: int32
        BanReason:
          description: Reason to ban a player
          type: string
    DeleteInventoryItemV2Content:
      type: object
      properties:
        CollectionId:
          description: >-
            The collection id for where the item will be removed from the player
            inventory
          type: string
        ItemId:
          description: The id of item to be removed from the player
          type: string
        StackId:
          description: >-
            The stack id for where the item will be removed from the player
            inventory
          type: string
    DeletePlayerContent:
      type: object
      properties: {}
    ExecuteCloudScriptContent:
      type: object
      properties:
        CloudScriptMethodArguments:
          description: Arguments(JSON) to be passed into the cloudscript method
          type: string
        CloudScriptMethodName:
          description: Cloudscript method name
          type: string
        PublishResultsToPlayStream:
          description: Publish cloudscript results as playstream event
          type: boolean
      required:
        - CloudScriptMethodName
        - CloudScriptMethodArguments
        - PublishResultsToPlayStream
    ExecuteFunctionContent:
      type: object
      properties:
        CloudScriptFunctionArguments:
          description: Arguments(JSON) to be passed into the cloudscript azure function
          type: string
        CloudScriptFunctionName:
          description: Cloudscript azure function name
          type: string
        PublishResultsToPlayStream:
          description: >-
            Publish results from executing the azure function as playstream
            event
          type: boolean
      required:
        - CloudScriptFunctionName
        - CloudScriptFunctionArguments
        - PublishResultsToPlayStream
    GrantItemContent:
      type: object
      properties:
        CatalogVersion:
          description: The catalog version of the item to be granted to the player
          type: string
        ItemId:
          description: The id of item to be granted to the player
          type: string
        ItemQuantity:
          description: Quantity of the item to be granted to a player
          type: number
          x-actualtype: int32
      required:
        - ItemQuantity
    GrantVirtualCurrencyContent:
      type: object
      properties:
        CurrencyAmount:
          description: Amount of currency to be granted to a player
          type: number
          x-actualtype: int32
        CurrencyCode:
          description: Code of the currency to be granted to a player
          type: string
      required:
        - CurrencyCode
        - CurrencyAmount
    IncrementPlayerStatisticContent:
      type: object
      properties:
        StatisticChangeBy:
          description: Amount(in whole number) to increase the player statistic by
          type: number
          x-actualtype: int32
        StatisticName:
          description: Name of the player statistic to be incremented
          type: string
      required:
        - StatisticName
        - StatisticChangeBy
    PushNotificationContent:
      type: object
      properties:
        Message:
          description: Text of message to send.
          type: string
        PushNotificationTemplateId:
          description: Id of the push notification template.
          type: string
        Subject:
          description: Subject of message to send (may not be displayed in all platforms)
          type: string
    SendEmailContent:
      type: object
      properties:
        EmailTemplateId:
          description: The email template id of the email template to send.
          type: string
      required:
        - EmailTemplateId
    SubtractInventoryItemV2Content:
      type: object
      properties:
        Amount:
          description: Amount of the item to removed from the player
          type: number
          x-actualtype: int32
        CollectionId:
          description: >-
            The collection id for where the item will be removed from the player
            inventory
          type: string
        DurationInSeconds:
          description: >-
            The duration in seconds to be removed from the subscription in the
            players inventory
          type: number
          x-actualtype: int32
        ItemId:
          description: The id of item to be removed from the player
          type: string
        StackId:
          description: >-
            The stack id for where the item will be removed from the player
            inventory
          type: string
  responses:
    CreateTaskResult:
      description: ''
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: integer
                description: >-
                  The Http status code. If X-ReportErrorAsSuccess header is set
                  to true, this will report the actual http error code.
              status:
                type: string
                description: The Http status code as a string.
              data:
                $ref: '#/components/schemas/CreateTaskResult'
            example:
              code: 200
              status: OK
              data:
                TaskId: 644FA3A39C9714BC
    ApiErrorWrapper:
      description: This is the outer wrapper for all responses with errors
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorWrapper'
  securitySchemes:
    SecretKey:
      type: apiKey
      in: header
      name: X-SecretKey
      description: >-
        This API requires a title secret key, available to title admins, from
        PlayFab Game Manager.

````

## Related topics

- [Create Actions On Players In Segment Task](/services/playfab/api-references/rest/admin/scheduled-task/create-actions-on-players-in-segment-task.md)
- [PlayFab Services SDK Release Notes 2023](/services/playfab/release-notes/2023.md)
- [Bulk Actions for an entire Player Segment](/services/playfab/data-analytics/acting-data/action-rules-bulk-actions-for-an-entire-player-segment.md)
- [Get Actions On Players In Segment Task Instance](/services/playfab/api-references/rest/admin/scheduled-task/get-actions-on-players-in-segment-task-instance.md)
- [Economy V2 Segment Actions](/services/playfab/economy-monetization/economy-v2/player-segmented-monetization/segment-actions.md)
