npx skills add ...
npx skills add microsoft/semantic-link-labs --skill rest-api-patterns
Guide for implementing REST API wrapper functions. Use this when adding new API wrappers or troubleshooting API calls.
npx skills add microsoft/semantic-link-labs --skill rest-api-patterns
This skill covers the patterns and utilities for implementing REST API wrapper functions in Semantic Link Labs.
Use this skill when you need to:
_base_api helper functionBefore implementing a wrapper, use the API search tool to find the relevant documentation:
search_public_api_doc.pyThe script requires rapidfuzz and requests:
| API | Base URL | Documentation |
|---|---|---|
| Fabric REST API | https://api.fabric.microsoft.com/v1/ | Fabric REST API |
| Power BI REST API | https://api.powerbi.com/v1.0/myorg/ | Power BI REST API |
Semantic Link Labs uses sempy.fabric.FabricRestClient as the underlying HTTP client, wrapped by the _base_api helper function.
| Component | Purpose |
|---|---|
_base_api | Main helper for all API calls |
FabricRestClient | HTTP client from sempy |
pagination | Handles paginated responses |
lro | Handles long-running operations |
_base_api FunctionLocated in src/sempy_labs/_helper_functions.py, this is the standard way to make API calls.
| Client | Use Case | Authentication |
|---|---|---|
fabric | Standard Fabric API | Default notebook credentials |
fabric_sp | Fabric API with SP support | Service Principal or default |
azure | Azure Resource Manager | Service Principal |
graph | Microsoft Graph | Service Principal |
onelake | OneLake storage | Storage token |
The _base_api function returns different types depending on the parameters used:
| Parameters | Return Type | How to Access Data |
|---|---|---|
| Default (no special flags) | Response object | Call .json() to get dict |
uses_pagination=True | list[dict] | Iterate over list, each item has .get("value", []) |
lro_return_json=True | dict | Access directly, already parsed JSON |
lro_return_status_code=True | int | HTTP status code |
lro_return_df=True | DataFrame | Use directly |
⚠️ COMMON MISTAKE: Forgetting to call .json() on the response for simple GET requests.
For APIs that return paginated results:
Some APIs return 202 Accepted and require polling for completion.
Specify expected status codes to avoid exceptions:
When status code doesn't match, FabricHTTPException is raised:
Use the _build_url helper for query parameters:
For non-Fabric clients (Azure, Graph), use _get_headers:
Use _create_dataframe for consistent empty DataFrames:
Add temporary debug prints:
| API | Documentation |
|---|---|
| Fabric Core | https://learn.microsoft.com/rest/api/fabric/core/ |
| Fabric Admin | https://learn.microsoft.com/rest/api/fabric/admin/ |
| Power BI | https://learn.microsoft.com/rest/api/power-bi/ |
| Azure Fabric | https://learn.microsoft.com/rest/api/microsoftfabric/ |
| Graph | https://learn.microsoft.com/graph/api/overview |