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

# Workflows

> SDK methods for tracking async workflow status

Track the status of async operations like collection creation, token minting, and contract deployment.

## Methods

### `getWorkflowStatus()`

Get the status and result of an async workflow.

**Signature:**

```typescript theme={null}
getWorkflowStatus(
  workflowId: string,
  requestOptions?: RequestOptions
): Promise<WorkflowStatusData>
```

**Parameters:**

| Parameter    | Type     | Required | Description |
| ------------ | -------- | -------- | ----------- |
| `workflowId` | `string` | Yes      | Workflow ID |

**Example:**

```typescript theme={null}
const status = await client.workflows.getWorkflowStatus('workflow-id');

console.log('Status:', status.data.status);
console.log('Result:', status.data.result);

if (status.data.status === 'COMPLETED') {
  console.log('Workflow completed successfully!');
  console.log('Result:', status.data.result);
} else if (status.data.status === 'FAILED') {
  console.error('Workflow failed:', status.data.error);
}
```

**Response:**

```typescript theme={null}
{
  data: {
    status: 'RUNNING' | 'COMPLETED' | 'FAILED' | 'TERMINATED',
    result?: any,
    error?: string
  }
}
```

## Workflow Status Values

* **RUNNING**: Operation is in progress
* **COMPLETED**: Operation completed successfully
* **FAILED**: Operation failed (check error details)
* **TERMINATED**: Operation was terminated

## Complete Example

```typescript theme={null}
import { OumlaSdkApiClient, OumlaSdkApiEnvironment } from '@oumla/sdk';

const client = new OumlaSdkApiClient({
  environment: OumlaSdkApiEnvironment.Sandbox,
  apiKey: 'your-api-key'
});

async function waitForWorkflow(workflowId: string) {
  let status;
  let attempts = 0;
  const maxAttempts = 60; // 2 minutes max (60 * 2 seconds)

  do {
    status = await client.workflows.getWorkflowStatus(workflowId);
    console.log(`Attempt ${attempts + 1}: Status = ${status.data.status}`);

    if (status.data.status === 'COMPLETED') {
      console.log('Workflow completed!', status.data.result);
      return status.data.result;
    }

    if (status.data.status === 'FAILED') {
      throw new Error(`Workflow failed: ${status.data.error}`);
    }

    if (status.data.status === 'TERMINATED') {
      throw new Error('Workflow was terminated');
    }

    // Wait 2 seconds before checking again
    await new Promise(resolve => setTimeout(resolve, 2000));
    attempts++;
  } while (attempts < maxAttempts && status.data.status === 'RUNNING');

  if (status.data.status === 'RUNNING') {
    throw new Error('Workflow timeout - still running after max attempts');
  }

  return status.data.result;
}

// Usage
try {
  const result = await waitForWorkflow('workflow-id');
  console.log('Final result:', result);
} catch (error) {
  console.error('Error waiting for workflow:', error);
}
```

<Tip>
  **Polling Strategy**: Implement exponential backoff for production applications to avoid excessive API calls while waiting for workflows to complete.
</Tip>
