---
title: "Update P4 import state"
method: POST
path: "/repos/{repo_id}/p4-import-state"
tags: ["Perforce Repository Import"]
---

# Update P4 import state

`POST /repos/{repo_id}/p4-import-state`

## Request

- Base URL: `https://api.diversion.dev/v0`
- URL: `https://api.diversion.dev/v0/repos/{repo_id}/p4-import-state`
- Auth: OAuth 2
  - Implicit: `https://auth.diversion.dev/oauth2/authorize`
  - Scopes: `coreapi/write`
- TypeScript: <https://skmtc.dev/diversion/apis/diversion-core-api/docs/repos/:repo_id/p4-import-state/post.ts> (a function with typed inputs; its response is checked against the schema)

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.

## Request body

- P4ImportStateUpdate: Update the state of a Perforce import job. Used both for manual initial setup and for recording progress during continuous import.
  - `branch_ref` string, required: Ref ID of the branch to import to
  - `p4_import_path` string, required: Path in Perforce depot to import from
  - `last_changelist` integer, required: Last Perforce changelist number that was imported
  - `last_import_unix` integer, nullable: Unix timestamp of the last successful import
  - `commit_ref` string, nullable: Optional commit reference for the commit created from last_changelist. When provided, a P4CommitMapping is recorded to track the CL-to-commit relationship.

## Response `200`

Import state updated successfully

- P4ImportState: Current state of the Perforce continuous import job
  - `last_changelist` integer, required: Last Perforce changelist number that was imported
  - `last_import_unix` integer, nullable: Unix timestamp of the last successful import
  - `running_job_id` string, nullable: ID of the currently running import job, if any
  - `error_count` integer, required: Number of consecutive errors encountered
  - `last_error` string, nullable: Last error message encountered during import
  - `last_error_unix` integer, nullable: Unix timestamp of the last error
  - `branch_ref` string, required: reference name of the branch being synced
  - `p4_import_path` string, required: Perforce depot path being imported (e.g., //depot/main/...)
  - `started_unix` integer, nullable: Unix timestamp when the current job started running

## Other responses

- `400`: The request does not meet the required conditions
- `404`: The specified resource was not found
- `default`: An error occurred

---

[API](https://skmtc.dev/diversion/apis/diversion-core-api.md) - [All operations](https://skmtc.dev/diversion/apis/diversion-core-api/llms.txt) - [OpenAPI document](https://skmtc.dev/diversion/apis/diversion-core-api/revisions/38a18aba804b?raw)
