Implement Verified Lightdash API Client
Description
This skill implements a new Lightdash API operation in the internal/lightdash/api directory, along with necessary models in internal/lightdash/models. It relies on the research-lightdash-api skill for researching and verifying the API schema before implementation.
Input
The user should provide:
- HTTP Method: (GET, POST, PUT, DELETE, PATCH)
- API Endpoint: (e.g.,
/api/v1/projects/:projectUuid/spaces)
- Function Name: (e.g.,
GetSpaceV1, CreateDashboardV1)
- Documentation URL: (Optional) Link to the official Lightdash API docs.
Workflow
1. Research & Verification
- Invoke Research: Use the research-lightdash-api skill to research the endpoint and verify its schema against the live API (if
LIGHTDASH_API_KEY is available).
- Outcome: Ensure you have a verified JSON response or documentation-based schema before proceeding to model generation.
2. Model Analysis & Generation
- Check existing models: Look in
internal/lightdash/models for existing structs that match the resource.
- Generate/Update models: If no suitable model exists, create/update the file
internal/lightdash/models/<resource>.go.
- Use strict typing based on the verified JSON.
- Add
json tags.
- Handle nullable fields with pointers where appropriate.
- Follow Go naming conventions (PascalCase for exported fields).
3. API Client Implementation
- Create File: Create a new file
internal/lightdash/api/<verb>_<resource>_v1.go (snake_case).
- Implement Method: Add the method to the
Client struct: func (c *Client) <FunctionName>(...) (*<ReturnType>, error).
- Request Construction:
- Use
http.NewRequest.
- Construct the path using
fmt.Sprintf and c.HostUrl.
- Validate input parameters (check for empty strings for UUIDs).
- Execution:
- Call
c.doRequest(req).
- Unmarshal the response body into the typed model.
- Return the
Results field if the API wraps the response in a Results envelope.
4. Verification
- Compilation Check: Ensure the code compiles.
- Unit Tests: Create/Update
internal/lightdash/api/<verb>_<resource>_v1_test.go to test unmarshaling logic with sample JSON.
Example Pattern
Ref: internal/lightdash/api/get_space_v1.go
package api
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/ubie-oss/terraform-provider-lightdash/internal/lightdash/models"
)
type GetResourceV1Response struct {
Results models.Resource `json:"results"`
Status string `json:"status"`
}
func (c *Client) GetResourceV1(id string) (*models.Resource, error) {
if len(strings.TrimSpace(id)) == 0 {
return nil, fmt.Errorf("id is empty")
}
path := fmt.Sprintf("%s/api/v1/resource/%s", c.HostUrl, id)
req, err := http.NewRequest("GET", path, nil)
if err != nil {
return nil, fmt.Errorf("error creating request: %w", err)
}
body, err := c.doRequest(req)
if err != nil {
return nil, fmt.Errorf("error performing request: %w", err)
}
var response GetResourceV1Response
if err := json.Unmarshal(body, &response); err != nil {
return nil, fmt.Errorf("error unmarshaling response: %w", err)
}
return &response.Results, nil
}
Reference
Assets
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: implement-verified-lightdash-api-client3description: Implement verified Lightdash API clients with documentation research and live schema verification. Use when this capability is needed.4---56# Implement Verified Lightdash API Client78## Description910This skill implements a new Lightdash API operation in the `internal/lightdash/api` directory, along with necessary models in `internal/lightdash/models`. It relies on the [research-lightdash-api](../research-lightdash-api/SKILL.md) skill for researching and verifying the API schema before implementation.1112## Input1314The user should provide:15161. **HTTP Method**: (GET, POST, PUT, DELETE, PATCH)172. **API Endpoint**: (e.g., `/api/v1/projects/:projectUuid/spaces`)183. **Function Name**: (e.g., `GetSpaceV1`, `CreateDashboardV1`)194. **Documentation URL**: (Optional) Link to the official Lightdash API docs.2021## Workflow2223### 1. Research & Verification2425- **Invoke Research**: Use the [research-lightdash-api](../research-lightdash-api/SKILL.md) skill to research the endpoint and verify its schema against the live API (if `LIGHTDASH_API_KEY` is available).26- **Outcome**: Ensure you have a **verified** JSON response or documentation-based schema before proceeding to model generation.2728### 2. Model Analysis & Generation2930- **Check existing models**: Look in `internal/lightdash/models` for existing structs that match the resource.31- **Generate/Update models**: If no suitable model exists, create/update the file `internal/lightdash/models/<resource>.go`.32 - Use strict typing based on the **verified** JSON.33 - Add `json` tags.34 - Handle nullable fields with pointers where appropriate.35 - Follow Go naming conventions (PascalCase for exported fields).3637### 3. API Client Implementation3839- **Create File**: Create a new file `internal/lightdash/api/<verb>_<resource>_v1.go` (snake_case).40- **Implement Method**: Add the method to the `Client` struct: `func (c *Client) <FunctionName>(...) (*<ReturnType>, error)`.41- **Request Construction**:42 - Use `http.NewRequest`.43 - Construct the path using `fmt.Sprintf` and `c.HostUrl`.44 - Validate input parameters (check for empty strings for UUIDs).45- **Execution**:46 - Call `c.doRequest(req)`.47 - Unmarshal the response body into the typed model.48 - Return the `Results` field if the API wraps the response in a [Results envelope](references/response_envelope.md).4950### 4. Verification5152- **Compilation Check**: Ensure the code compiles.53- **Unit Tests**: Create/Update `internal/lightdash/api/<verb>_<resource>_v1_test.go` to test unmarshaling logic with sample JSON.5455## Example Pattern5657Ref: `internal/lightdash/api/get_space_v1.go`5859```go60package api6162import (63 "encoding/json"64 "fmt"65 "net/http"66 "strings"6768 "github.com/ubie-oss/terraform-provider-lightdash/internal/lightdash/models"69)7071type GetResourceV1Response struct {72 Results models.Resource `json:"results"`73 Status string `json:"status"`74}7576func (c *Client) GetResourceV1(id string) (*models.Resource, error) {77 if len(strings.TrimSpace(id)) == 0 {78 return nil, fmt.Errorf("id is empty")79 }8081 path := fmt.Sprintf("%s/api/v1/resource/%s", c.HostUrl, id)82 req, err := http.NewRequest("GET", path, nil)83 if err != nil {84 return nil, fmt.Errorf("error creating request: %w", err)85 }8687 body, err := c.doRequest(req)88 if err != nil {89 return nil, fmt.Errorf("error performing request: %w", err)90 }9192 var response GetResourceV1Response93 if err := json.Unmarshal(body, &response); err != nil {94 return nil, fmt.Errorf("error unmarshaling response: %w", err)95 }9697 return &response.Results, nil98}99```100101## Reference102103- [Lightdash API Documentation](https://docs.lightdash.com/api-reference/v1/introduction)104- [Lightdash Client Rules](.cursor/rules/lightdash-client.mdc)105- [API Client Structure](references/api_client_structure.md)106- [API Response Envelope](references/response_envelope.md)107108## Assets109110- [API Operation Boilerplate](assets/api_boilerplate.go)111- [Model Boilerplate](assets/model_boilerplate.go)112- [Unit Test Boilerplate](assets/api_test_boilerplate.go)113- [Schema Verification Script](../research-lightdash-api/assets/verify_schema.go)114115---116> Converted and distributed by [TomeVault](https://tomevault.io/claim/ubie-oss) — claim your Tome and manage your conversions.117<!-- tomevault:4.0:skill_md:2026-04-11 -->