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

# Job Status

> Track the status of your Docswrite publishing jobs

## Additional Information

### Usage Examples

#### Polling for Completion

```javascript theme={null}
async function waitForJobCompletion(jobId, token) {
  while (true) {
    const response = await fetch("https://api.docswrite.com/api/job/status", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "x-access-token": token,
      },
      body: JSON.stringify({
        jobId: jobId,
        queueType: "post",
      }),
    });

    const data = await response.json();

    if (data.success && data.data.state === "completed") {
      console.log("Job completed successfully!");
      break;
    } else if (data.success && data.data.state === "failed") {
      console.error("Job failed:", data.data.failedReason);
      break;
    }

    // Wait 5 seconds before checking again
    await new Promise((resolve) => setTimeout(resolve, 5000));
  }
}
```

#### Progress Tracking

```javascript theme={null}
function trackProgress(jobId, token) {
  const interval = setInterval(async () => {
    const response = await fetch("https://api.docswrite.com/api/job/status", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "x-access-token": token,
      },
      body: JSON.stringify({ jobId, queueType: "post" }),
    });

    const data = await response.json();

    if (data.success) {
      console.log(`Progress: ${data.data.progress}%`);

      if (data.data.state === "completed" || data.data.state === "failed") {
        clearInterval(interval);
      }
    }
  }, 2000);
}
```

<Note>
  You can only check the status of jobs that you created. The API will return a
  403 error if you try to check someone else's job.
</Note>

## Get Job Status

Check the status of a publishing job using the job ID returned when creating a post.

```bash theme={null}
POST https://api.docswrite.com/api/job/status
```

### Headers

| Header         | Value              |
| -------------- | ------------------ |
| Content-Type   | `application/json` |
| x-access-token | `YOUR_JWT_TOKEN`   |

### Request Body

```json theme={null}
{
  "jobId": "job-123",
  "queueType": "post"
}
```

### Parameters

| Parameter   | Type   | Required | Description                              |
| ----------- | ------ | -------- | ---------------------------------------- |
| `jobId`     | string | Yes      | The job ID returned when creating a post |
| `queueType` | string | No       | Queue type, defaults to "post"           |

### Response

**Success Response (200 OK)**

```json theme={null}
{
  "success": true,
  "data": {
    "id": "job-123",
    "state": "completed",
    "progress": 100,
    "returnValue": {},
    "failedReason": null,
    "timestamp": 1234567890,
    "processedOn": 1234567890,
    "finishedOn": 1234567890
  }
}
```

### Job States

| State       | Description                                 |
| ----------- | ------------------------------------------- |
| `waiting`   | Job is in the queue waiting to be processed |
| `active`    | Job is currently being processed            |
| `completed` | Job finished successfully                   |
| `failed`    | Job failed with an error                    |
| `delayed`   | Job is scheduled to run later               |

### Response Fields

| Field          | Type   | Description                 |
| -------------- | ------ | --------------------------- |
| `id`           | string | The job ID                  |
| `state`        | string | Current state of the job    |
| `progress`     | number | Progress percentage (0-100) |
| `returnValue`  | object | Result data when completed  |
| `failedReason` | string | Error message if job failed |
| `timestamp`    | number | Job creation timestamp      |
| `processedOn`  | number | When job processing started |
| `finishedOn`   | number | When job finished           |

### cURL Example

```bash theme={null}
curl -X POST 'https://api.docswrite.com/api/job/status' \
  -H 'Content-Type: application/json' \
  -H 'x-access-token: YOUR_JWT_TOKEN' \
  -d '{
    "jobId": "job-123",
    "queueType": "post"
  }'
```

### Error Responses

**Unauthorized (401)**

```json theme={null}
{
  "error": true,
  "message": "Unauthorized",
  "details": "Invalid or missing access token"
}
```

**Forbidden (403)**

```json theme={null}
{
  "error": true,
  "message": "Access denied",
  "details": "You can only check the status of jobs that you created"
}
```

**Not Found (404)**

```json theme={null}
{
  "error": true,
  "message": "Job not found",
  "details": "No job found with the provided ID"
}
```


## OpenAPI

````yaml POST /api/job/status
openapi: 3.1.0
info:
  title: Docswrite API
  description: REST API for publishing Google Docs to WordPress with Docswrite
  version: 1.0.0
  contact:
    name: Docswrite Support
    url: >-
      https://join.slack.com/t/docswritecom/shared_invite/zt-1j0f1wly8-8lEYgDLDGfBFRkh50SRF7Q
    email: support@docswrite.com
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
  - url: https://api.docswrite.com
    description: Production server
security:
  - apiToken: []
paths:
  /api/job/status:
    post:
      summary: Get Job Status
      description: Check the status of a publishing job
      requestBody:
        description: Job status request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/JobStatusRequest'
        required: true
      responses:
        '200':
          description: Job status retrieved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobStatusResponse'
        '401':
          description: Unauthorized - invalid JWT token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden - cannot access this job
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Job not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - jwtToken: []
components:
  schemas:
    JobStatusRequest:
      type: object
      required:
        - jobId
      properties:
        jobId:
          type: string
          description: Job ID returned from post creation
          example: job-abc123
        queueType:
          type: string
          default: post
          description: Type of queue to check
          example: post
    JobStatusResponse:
      type: object
      properties:
        success:
          type: boolean
          example: true
        data:
          type: object
          properties:
            id:
              type: string
              example: job-abc123
            state:
              type: string
              enum:
                - waiting
                - active
                - completed
                - failed
                - delayed
              example: completed
            progress:
              type: integer
              minimum: 0
              maximum: 100
              example: 100
            returnValue:
              type: object
              description: Result data when job is completed
            failedReason:
              type: string
              nullable: true
              description: Error message if job failed
            timestamp:
              type: integer
              description: Job creation timestamp
              example: 1234567890
            processedOn:
              type: integer
              description: When job processing started
              example: 1234567890
            finishedOn:
              type: integer
              description: When job finished
              example: 1234567890
    ErrorResponse:
      type: object
      properties:
        error:
          type: boolean
          example: true
        message:
          type: string
          example: Invalid Google Docs URL
        details:
          type: string
          example: The provided URL is not accessible or not shared properly
  securitySchemes:
    apiToken:
      type: apiKey
      in: query
      name: token
      description: API token obtained from Docswrite dashboard
    jwtToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token for authenticated requests

````