Add TypeSpec API Operations
Add RESTful operations to an existing TypeSpec API plugin for Microsoft 365 Copilot.
Adding GET Operations
Simple GET - List All Items
GET with Query Parameter - Filter Results
GET with Path Parameter - Get Single Item
GET with Adaptive Card
Create the Adaptive Card (appPackage/item-card.json):
Adding POST Operations
Simple POST - Create Item
POST with Confirmation
Adding PATCH Operations
Simple PATCH - Update Item
PATCH with Confirmation
Adding DELETE Operations
Simple DELETE
DELETE with Confirmation
Complete CRUD Example
Define the Service and Models
Advanced Features
Multiple Query Parameters
Custom Response Models
Error Responses
Testing Prompts
After adding operations, test with these prompts:
GET Operations:
- "List all items and show them in a table"
- "Show me items for user ID 1"
- "Get the details of item 42"
POST Operations:
- "Create a new item with title 'My Task' for user 1"
- "Add an item: title 'New Feature', description 'Add login'"
PATCH Operations:
- "Update item 10 with title 'Updated Title'"
- "Change the status of item 5 to completed"
DELETE Operations:
- "Delete item 99"
- "Remove the item with ID 15"
Best Practices
Parameter Naming
- Use descriptive parameter names:
userId not uid
- Be consistent across operations
- Use optional parameters (
?) for filters
Documentation
- Add JSDoc comments to all operations
- Describe what each parameter does
- Document expected responses
Models
- Use
@visibility(Lifecycle.Read) for read-only fields like id
- Use
@format("date-time") for date fields
- Use union types for enums:
"active" | "completed"
- Make optional fields explicit with
?
Confirmations
- Always add confirmations to destructive operations (DELETE, PATCH)
- Show key details in confirmation body
- Use warning emoji (⚠️) for irreversible actions
Adaptive Cards
- Keep cards simple and focused
- Use conditional rendering with
${if(..., ..., 'N/A')}
- Include action buttons for common next steps
- Test data binding with actual API responses
Routing
- Use RESTful conventions:
GET /items - List
GET /items/{id} - Get one
POST /items - Create
PATCH /items/{id} - Update
DELETE /items/{id} - Delete
- Group related operations in the same namespace
- Use nested routes for hierarchical resources
Common Issues
Issue: Parameter not showing in Copilot
Solution: Check parameter is properly decorated with @query, @path, or @body
Issue: Adaptive card not rendering
Solution: Verify file path in @card decorator and check JSON syntax
Issue: Confirmation not appearing
Solution: Ensure @capabilities decorator is properly formatted with confirmation object
Issue: Model property not appearing in response
Solution: Check if property needs @visibility(Lifecycle.Read) or remove it if it should be writable