---
phase: 03-workflow-management
type: execute
---

<objective>
Extend WorkflowsResource with complete CRUD methods and utility functions for workflow management.

Purpose: Provide the API foundation that CLI commands will use for all workflow operations (create, update, delete, activate, find by name).
Output: WorkflowsResource with 6 new methods, all type-safe with Pydantic models and retry logic, tested with 100% coverage.
</objective>

<execution_context>
~/.claude/get-shit-done/workflows/execute-phase.md
./summary.md
~/.claude/get-shit-done/references/tdd.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/02-api-client-core-types/02-01-SUMMARY.md
@.planning/phases/02-api-client-core-types/02-02-SUMMARY.md
@.planning/phases/02-api-client-core-types/02-RESEARCH.md
@src/n8n_cli/client/core.py
@src/n8n_cli/client/resources/workflows.py
@src/n8n_cli/client/models/workflow.py
@REQUIREMENTS.md
</context>

<tasks>

<task type="auto" tdd="true">
  <name>Task 1: Add create/update/delete methods to WorkflowsResource</name>
  <files>src/n8n_cli/client/resources/workflows.py, tests/test_workflows_resource.py</files>
  <test-first>
Test: create() returns Workflow with ID, update() modifies and returns Workflow, delete() succeeds with 204
Cases:
- create(workflow_data) → Workflow with id populated
- update(workflow_id, workflow_data) → Workflow with updated fields
- delete(workflow_id) → None (204 status)
- All methods use @retry decorator
  </test-first>
  <action>
Add three methods to WorkflowsResource:
1. create(self, workflow: dict) -> Workflow: POST /api/v1/workflows with json=workflow, validate response with Workflow.model_validate(), return Workflow
2. update(self, workflow_id: str, workflow: dict) -> Workflow: PUT /api/v1/workflows/{workflow_id} with json=workflow, return Workflow
3. delete(self, workflow_id: str) -> None: DELETE /api/v1/workflows/{workflow_id}, expect 204 status, return None

Use @retry decorator from tenacity (same config as existing methods). Use pytest-httpx to mock responses. Don't hand-roll retry logic - use the established pattern from Phase 2.
  </action>
  <verify>pytest tests/test_workflows_resource.py -v passes with new tests for create/update/delete</verify>
  <done>WorkflowsResource has create/update/delete methods, all use retry logic, all return type-safe Pydantic models, tests verify behavior</done>
</task>

<task type="auto" tdd="true">
  <name>Task 2: Add activate/deactivate and find_by_name utility methods</name>
  <files>src/n8n_cli/client/resources/workflows.py, tests/test_workflows_resource.py</files>
  <test-first>
Test: activate() sets active=true, deactivate() sets active=false, find_by_name() finds workflow by name
Cases:
- activate(workflow_id) → Workflow with active=true
- deactivate(workflow_id) → Workflow with active=false
- find_by_name("exact name") → Workflow or None
- find_by_name("partial") → raises error if multiple matches
  </test-first>
  <action>
Add three methods to WorkflowsResource:
1. activate(self, workflow_id: str) -> Workflow: PATCH /api/v1/workflows/{workflow_id} with json={"active": true}, return Workflow
2. deactivate(self, workflow_id: str) -> Workflow: PATCH /api/v1/workflows/{workflow_id} with json={"active": false}, return Workflow
3. find_by_name(self, name: str) -> Workflow | None: Call self.list(), filter by exact name match (case-sensitive), return single match or None. Raise ValueError if multiple workflows have the same name.

Use @retry decorator. Use PATCH not PUT for activate/deactivate (partial update pattern). The find_by_name method is a convenience wrapper around list() to support flexible input resolution in CLI commands.
  </action>
  <verify>pytest tests/test_workflows_resource.py -v passes, mypy passes, ruff passes</verify>
  <done>WorkflowsResource has activate/deactivate/find_by_name methods, all type-safe, tests verify exact name matching and error on duplicates</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] pytest tests/test_workflows_resource.py passes with 100% coverage for new methods
- [ ] mypy src/n8n_cli/client/resources/workflows.py passes
- [ ] ruff check src/n8n_cli/client/resources/workflows.py passes
- [ ] All methods use @retry decorator consistently
- [ ] All methods return type-safe Pydantic models (except delete which returns None)
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- WorkflowsResource has 8 total methods (list, get, create, update, delete, activate, deactivate, find_by_name)
- No errors or warnings introduced
- TDD commits follow RED-GREEN-REFACTOR pattern
  </success_criteria>

<output>
After completion, create `.planning/phases/03-workflow-management/03-01-SUMMARY.md`:

# Phase 3 Plan 1: WorkflowsResource API Methods Summary

**[Substantive one-liner - what shipped]**

## Accomplishments

- [Key outcomes]

## Files Created/Modified

- `src/n8n_cli/client/resources/workflows.py` - Added create/update/delete/activate/deactivate/find_by_name methods
- `tests/test_workflows_resource.py` - Added comprehensive tests for new methods

## Decisions Made

[Key decisions and rationale, or "None"]

## Issues Encountered

[Problems and resolutions, or "None"]

## Next Step

Ready for 03-02-PLAN.md (Basic Workflow CLI Commands)
</output>
