> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/graphql-api/mutations/deleteinventoryitemmovement.md).

# Delete Inventory Item Movement

Delete Inventory Item Movement Mutation

Deletes an existing ItemMovement object from the system, removing a planned or pending movement of inventory items between repositories.

## Arguments

| Name | Type  | Description                                          |
| ---- | ----- | ---------------------------------------------------- |
| `id` | `ID!` | The unique identifier of the item movement to delete |

## Return Type

`InventoryItemMovementDeletePayload!` - Contains information about the deleted movement and related workflows.

## Return Fields

`InventoryItemMovementDeletePayload`:

| Field       | Type                 | Description                                            |
| ----------- | -------------------- | ------------------------------------------------------ |
| `deletedID` | `ID`                 | The ID of the deleted item movement                    |
| `workflows` | `[TemporalWorkflow]` | Workflow instances that were triggered by the deletion |

## Usage Example

```graphql
mutation {
  deleteInventoryItemMovement(id: "movement_123") {
    deletedID
    workflows {
      id
      type
      status
      runID
    }
  }
}
```

## JavaScript Example

```javascript
const DELETE_INVENTORY_ITEM_MOVEMENT = gql`
  mutation DeleteInventoryItemMovement($id: ID!) {
    deleteInventoryItemMovement(id: $id) {
      deletedID
      workflows {
        id
        name
        status
        workflowID
        runID
      }
    }
  }
`;

const { data } = await client.mutate({
  mutation: DELETE_INVENTORY_ITEM_MOVEMENT,
  variables: {
    id: "movement_123"
  }
});

console.log(`Deleted item movement with ID: ${data.deleteInventoryItemMovement.deletedID}`);

// Check for any triggered workflows
if (data.deleteInventoryItemMovement.workflows.length > 0) {
  console.log('Triggered workflows:', data.deleteInventoryItemMovement.workflows);
}
```

## Important Notes

* **Movement State**: Only non-executed movements can be deleted. Executed movements become part of the audit trail and cannot be removed
* **Workflow Triggers**: The deletion may trigger cleanup workflows or notification workflows
* **Authorization**: Ensure you have proper permissions before deleting item movements
* **Data Integrity**: The system will prevent deletion if the movement is part of an active collection or order
* **Stock Impact**: Deleting a movement does not affect current stock levels, as the movement was never executed
* **Audit Trail**: Deletion events are logged for compliance and audit purposes
* **Recovery**: Once deleted, the item movement cannot be recovered through the API

## Related Operations

After deleting an item movement, you may need to:

* Update related collection movements if this was part of a batch
* Reassign responsibilities to other handlers
* Notify stakeholders about the canceled movement
* Create replacement movements if the transfer is still needed

## Common Deletion Scenarios

1. **Cancel Planned Movement**: Remove a movement that is no longer needed
2. **Correct Errors**: Delete movements created with incorrect parameters
3. **Workflow Cleanup**: Remove movements that were part of a canceled workflow
4. **Resource Optimization**: Delete redundant or duplicate movements
5. **Order Cancellation**: Remove movements associated with canceled orders

## Error Handling

Common scenarios that may prevent deletion:

* **Executed Movement**: Cannot delete a movement that has already been executed. The system will return the error: "cannot delete an executed movement"
  * **Reason**: Executed movements have already transferred physical stock and are part of the permanent audit trail
  * **Solution**: Only pending (non-executed) movements can be deleted. For executed movements, consider creating a reverse movement instead
* **Insufficient Permissions**: User lacks permission to delete the movement
* **Active References**: The movement is referenced in active workflows or collections
* **System Constraints**: Business rules prevent deletion due to operational requirements

When attempting to delete an executed movement, handle the error appropriately:

```javascript
try {
  const { data } = await client.mutate({
    mutation: DELETE_INVENTORY_ITEM_MOVEMENT,
    variables: { id: movementId }
  });
  console.log('Movement deleted successfully');
} catch (error) {
  if (error.message.includes('cannot delete an executed movement')) {
    console.error('This movement has already been executed and cannot be deleted');
    // Consider creating a reverse movement instead
  } else {
    console.error('Failed to delete movement:', error.message);
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/graphql-api/mutations/deleteinventoryitemmovement.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
