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

# Update P4 import state

> Initialize or update the state of a continuous Perforce import job after manual initial import. Creates or updates a P4ImportJob record tracking the last imported changelist for incremental syncing.



## OpenAPI

````yaml post /repos/{repo_id}/p4-import-state
openapi: 3.0.3
info:
  title: Diversion Core API
  description: >-
    Definition of the Core API used to access low-level functionality of
    Diversion
  version: 0.2.0
servers:
  - url: https://api.diversion.dev/v0
    description: Base endpoint
security: []
paths:
  /repos/{repo_id}/p4-import-state:
    parameters:
      - $ref: '#/components/parameters/RepoParam'
    post:
      tags:
        - Perforce Repository Import
      summary: Update P4 import state
      description: >-
        Initialize or update the state of a continuous Perforce import job after
        manual initial import. Creates or updates a P4ImportJob record tracking
        the last imported changelist for incremental syncing.
      operationId: src.handlersv2.p4_import.update_import_state
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/P4ImportStateUpdate'
      responses:
        '200':
          description: Import state updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/P4ImportState'
        '400':
          $ref: '#/components/responses/BadRequest'
          description: Invalid request (e.g., branch not found, invalid changelist number)
        '404':
          $ref: '#/components/responses/NotFound'
          description: Repository or branch not found
        default:
          $ref: '#/components/responses/Error'
      security:
        - OAuth2:
            - coreapi/write
components:
  parameters:
    RepoParam:
      in: path
      name: repo_id
      required: true
      schema:
        type: string
        example: example_id
        minLength: 3
        maxLength: 128
      description: >-
        The repo ID of the repository. Repo _name_ can be used instead of the
        ID, but usage of ID for permanent linking and API requests is preferred.
  schemas:
    P4ImportStateUpdate:
      description: >-
        Update the state of a Perforce import job. Used both for manual initial
        setup and for recording progress during continuous import.
      type: object
      properties:
        branch_ref:
          type: string
          description: Ref ID of the branch to import to
          example: dv.branch.1
          minLength: 1
          maxLength: 128
        p4_import_path:
          type: string
          description: Path in Perforce depot to import from
          example: //depot/main/...
          minLength: 1
          maxLength: 1024
        last_changelist:
          type: integer
          description: Last Perforce changelist number that was imported
          minimum: 0
        last_import_unix:
          type: integer
          description: Unix timestamp of the last successful import
          nullable: true
        commit_ref:
          type: string
          description: >-
            Optional commit reference for the commit created from
            last_changelist. When provided, a P4CommitMapping is recorded to
            track the CL-to-commit relationship.
          example: dv.commit.12345
          minLength: 1
          maxLength: 128
          nullable: true
      required:
        - branch_ref
        - p4_import_path
        - last_changelist
    P4ImportState:
      allOf:
        - $ref: '#/components/schemas/P4ImportJobResult'
        - type: object
          description: Current state of the Perforce continuous import job
          properties:
            branch_ref:
              type: string
              description: reference name of the branch being synced
              example: dv.branch.1
            p4_import_path:
              type: string
              description: Perforce depot path being imported (e.g., //depot/main/...)
            started_unix:
              type: integer
              description: Unix timestamp when the current job started running
              nullable: true
          required:
            - branch_ref
            - p4_import_path
            - last_changelist
            - error_count
    P4ImportJobResult:
      type: object
      description: Details of a Perforce continuous import job
      properties:
        last_changelist:
          type: integer
          description: Last Perforce changelist number that was imported
          minimum: 0
        last_import_unix:
          type: integer
          description: Unix timestamp of the last successful import
          nullable: true
        running_job_id:
          type: string
          description: ID of the currently running import job, if any
          nullable: true
        error_count:
          type: integer
          description: Number of consecutive errors encountered
          default: 0
        last_error:
          type: string
          description: Last error message encountered during import
          nullable: true
        last_error_unix:
          type: integer
          description: Unix timestamp of the last error
          nullable: true
    Error:
      type: object
      properties:
        status:
          type: integer
          description: HTTP status code
        detail:
          type: string
        title:
          type: string
        type:
          type: string
      required:
        - status
        - detail
  responses:
    BadRequest:
      description: The request does not meet the required conditions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: The specified resource was not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error:
      description: An error occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    OAuth2:
      type: oauth2
      x-tokenInfoFunc: src.token_info.token_auth
      description: This API uses OAuth 2 with the implicit grant flow
      flows:
        implicit:
          authorizationUrl: https://auth.diversion.dev/oauth2/authorize
          scopes:
            coreapi/read: Operations with no possible side-effects
            coreapi/write: Modifying operations
            coreapi/admin: >-
              Organizational operations like adding a repo or changing repo
              properties

````