### API Request with Method and Body Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md Demonstrates making an API request with a specified HTTP method (POST) and a JSON body. The example shows how to dynamically include frontmatter variables like the filename within the request body. ```markdown ```req url: https://jsonplaceholder.typicode.com/posts method: post body: {"title": {{this.filename}}, "body": "bar", "userId": 1} ``` ``` -------------------------------- ### Get Todos from Todoist API Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/usecase/index.md Retrieves tasks from Todoist using their REST API. Requires an API token for authentication and includes the `headers` parameter for authorization. The response content is formatted as a Markdown checklist item. The response is saved in localStorage under a specified key. ```markdown ```req url: https://api.todoist.com/rest/v2/tasks headers: {"Authorization": "Bearer YOUR_TOKEN"} show: $..content format: - [ ] {} req-id: todos ``` ``` -------------------------------- ### Get Weather Data with API Request Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/usecase/index.md Fetches current weather information for a specified city using the OpenWeatherMap API. Requires a valid API key and the city name to be provided. The `show` parameter can be used to extract specific weather details like temperature. ```markdown ```req url: https://api.openweathermap.org/data/2.5/weather?q=&appid=YOUR_API_KEY show: $.main.temp ``` ``` -------------------------------- ### Basic GET Request Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Executes a simple GET request to fetch data from a specified API endpoint. The 'url' parameter is mandatory for this operation. ```req url: https://jsonplaceholder.typicode.com/users/1 ``` -------------------------------- ### API Request with Headers Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md Illustrates how to set custom headers for an API request, including the use of JSON format. It also shows an advanced example of using a previously stored API response (identified by `req-uuid`) to dynamically populate the Authorization header. ```markdown ```req url: https://jsonplaceholder.typicode.com/posts method: post headers: {"Content-type": "application/json; charset=UTF-8"} ``` ``` ```markdown ```req url: https://api.todoist.com/rest/v2/tasks headers: {"Authorization": "Bearer {{ls.token>$.access_token}}"} show: $..content format: - [ ] {} req-id: todos ``` ``` -------------------------------- ### API Request with JSONPath for Response Display Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md Shows how to use JSONPath expressions with the `show` flag to extract specific data from an API response. Examples include accessing nested values, multiple values, and looping through array elements. ```markdown ```req url: https://api.chess.com/pub/player/hikaru/stats show: $['chess_daily']['last']['rating'] ``` ``` ```markdown ```req url: https://api.chess.com/pub/player/hikaru/stats show: $.chess_daily[last,best].rating ``` ``` ```markdown ```req url: https://api.chess.com/pub/player/hikaru/stats show: $.chess_daily[last,best].rating + $.chess960_daily[last,best].rating ``` ``` ```markdown ```req url: https://jsonplaceholder.typicode.com/users show: $..address.city ``` ``` ```markdown ```req url: https://jsonplaceholder.typicode.com/users show: $..[:3].address.city ``` ``` ```markdown ```req url: https://jsonplaceholder.typicode.com/users show: $..[3,2,6].address.city ``` ``` ```markdown ```req url: https://api.modrinth.com/v2/project/distanthorizons show: $.game_versions[(@.length-1)] ``` ``` ```markdown ```req url: http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=rooyca&api_key=API_KEY&format=json&limit=4 show: $..recenttracks.track[0:][streamable,name,artist] ``` ``` -------------------------------- ### Fetch Cryptocurrency Price with API Request Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/usecase/index.md Retrieves the current price of Bitcoin (or any cryptocurrency) using the coincap.io API. The `show` parameter is used to extract a specific field from the JSON response. This is a simple, direct API call for real-time data. ```markdown ```req url: https://api.coincap.io/v2/rates/bitcoin show: $.data.rateUsd ``` ``` -------------------------------- ### Save API Response to File with save-as Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md The `save-as` flag specifies a file path to save the entire API response. A file extension is required, and the plugin will not create directories automatically. This is useful for persisting API data locally. ```markdown ```req url: https://jsonplaceholder.typicode.com/posts/1 save-as: posts/1.json ``` ``` -------------------------------- ### Use Dataview with Inline API Responses Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/usecase/index.md Demonstrates how to make an API request, store its response using `req-uuid`, and then access that data within DataviewJS for display. This allows dynamic content embedding in Obsidian notes. It requires Dataview plugin and enabling inline JavaScript queries. ```markdown ```req url: https://jsonplaceholder.typicode.com/comments/1 req-uuid: test hidden ``` ``` ```javascript The email is `$=dv.el("span", JSON.parse(localStorage.getItem("req-test")).email)` and the ID is `$=dv.el("span", JSON.parse(localStorage.getItem("req-test")).id, { cls: "mod-warning" })` ``` -------------------------------- ### Format API Response Display with format Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md The `format` flag allows you to specify how the API response should be displayed. You can use placeholders like `{}` to insert data from the response. If multiple outputs are specified in `show`, corresponding format specifiers should be provided. ```markdown ```req url: https://jsonplaceholder.typicode.com/posts/1 show: $.[title,body] format:

{}

{}

``` ``` -------------------------------- ### Render Formatted API Data Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/usecase/index.md Fetches specific data fields (cover picture, name, type) from a Mobile Legends API endpoint and formats the output using HTML. The `format` parameter allows for custom rendering of the retrieved data, creating structured display within Obsidian. ```markdown ```req url: https://mapi.mobilelegends.com/hero/detail?id=1 show: $.data[cover_picture,name,type] format: ![img]({})
Name: {}
Type: {} ``` ``` -------------------------------- ### Comments in Code Blocks Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Allows adding comments within 'req' code blocks using '#' or '//' syntax. This helps in documenting the purpose of specific API requests. ```req # This fetches user data from the API // Another comment style url: https://jsonplaceholder.typicode.com/users/1 show: $.name ``` -------------------------------- ### API Request Configuration Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md This section covers the fundamental flags used to configure an API request, including URL, method, body, and headers. ```APIDOC ## API Request Configuration This section details the primary flags for making API requests within Obsidian. ### Flags Overview | Flag | Default | Description | |---|---|---| | `[url](#url)` | | The endpoint URL for the API request. This is the only required flag. | | `[method](#method)` | `GET` | The HTTP method for the request (GET, POST, PUT, DELETE). | | `[body](#body)` | `{}` | The request body, typically in JSON format. | | `[headers](#headers)` | `{}` | The request headers, typically in JSON format. | | `[show](#show)` | `ALL` | Specifies which parts of the response to display using JSONPath. | | `[req-uuid](#req-uuid)` | `req-general` | A unique identifier for storing and referencing the request response. | | `[hidden](#hidden)` | `FALSE` | If TRUE, the response will not be displayed. | | `[disabled](#disabled)` | | If set, the request will be disabled. | | `[save-as](#save-as)` | | Specifies a filename to save the response content. | | `[auto-update](#auto-update)` | `FALSE` | If TRUE, the request will automatically update when the note is opened. | | `[format](#format)` | | Defines a format string for displaying list-based responses. | | `[properties](#properties)` | | Allows specifying properties to extract from the response. | ### URL Specifies the endpoint of the request. It is the only **required** flag. ```req url: https://jsonplaceholder.typicode.com/users/{{this.id}} ``` * `{{this.id}}` can be a variable defined in the note's frontmatter. ### Method Specifies the request method. Defaults to `GET`. Available methods: `GET`, `POST`, `PUT`, `DELETE`. ```req url: https://jsonplaceholder.typicode.com/posts method: post ``` ### Body Specifies the body of the request. Defaults to an empty object. Data should be in JSON format. ```req url: https://jsonplaceholder.typicode.com/posts method: post body: {"title": {{this.filename}}, "body": "bar", "userId": 1} ``` * `{{this.filename}}` refers to the name of the current note. ### Headers Specifies the headers of the request. Defaults to an empty object. Data should be in JSON format. ```req url: https://jsonplaceholder.typicode.com/posts method: post headers: {"Content-type": "application/json; charset=UTF-8"} ``` Responses from other requests can be used in headers, body, or URL using the `req-uuid` syntax. ```req url: https://api.todoist.com/rest/v2/tasks headers: {"Authorization": "Bearer {{ls.token>$.access_token}}"} show: $..content format: - [ ] {} req-id: todos ``` ``` -------------------------------- ### Response Handling and Display Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md This section explains how to manage API responses, including storing them, accessing specific data, and customizing the display format. ```APIDOC ## Response Handling and Display This section covers how to manage and display data received from API requests. ### LocalStorage & Variables API responses can be stored in `localStorage` using the `req-uuid` flag for later use. Access stored responses with `{{ls.UUID>JSONPath}}`. * `UUID`: The identifier from the `req-uuid` flag. * `JSONPath`: The path to the desired data within the response. **Example:** Storing a user's data with `req-uuid: user` and accessing the name: ``` {{ls.user>$.name}} ``` Reference note frontmatter variables with `{{this.variableName}}`. Reference global variables (defined in plugin settings) with `{{ls.variableName}}`. ### Show Specifies which parts of the response to display using JSONPath. See [JSONPath examples](https://github.com/JSONPath-Plus/JSONPath?tab=readme-ov-file#syntax-through-examples). **Example 1:** Accessing a specific rating: ```req url: https://api.chess.com/pub/player/hikaru/stats show: $['chess_daily']['last']['rating'] ``` **Example 2:** Displaying multiple outputs using `[]`: ```req url: https://api.chess.com/pub/player/hikaru/stats show: $.chess_daily[last,best].rating ``` **Example 3:** Displaying multiple outputs using `+`: ```req url: https://api.chess.com/player/hikaru/stats show: $.chess_daily[last,best].rating + $.chess960_daily[last,best].rating ``` **Example 4:** Looping over an array to get all cities: ```req url: https://jsonplaceholder.typicode.com/users show: $..address.city ``` **Example 5:** Looping over a specified range of array elements: ```req url: https://jsonplaceholder.typicode.com/users show: $..[:3].address.city ``` **Example 6:** Looping over specific array indexes: ```req url: https://jsonplaceholder.typicode.com/users show: $..[3,2,6].address.city ``` **Example 7:** Accessing the last element: ```req url: https://api.modrinth.com/v2/project/distanthorizons show: $.game_versions[(@.length-1)] ``` **Example 8:** Accessing multiple elements and properties within an array: ```req url: http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=rooyca&api_key=API_KEY&format=json&limit=4 show: $..recenttracks.track[0:][streamable,name,artist] ``` ### Format Defines a format string for displaying list-based responses. The `{}` placeholder is replaced by the response data. **Example:** Formatting a list of tasks: ```req url: https://api.todoist.com/rest/v2/tasks show: $..content format: "- [ ] {}" ``` ``` -------------------------------- ### Default Plugin Settings Structure Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Defines the default configuration structure for the API Request plugin. This includes settings for disabled request messages, status bar visibility and colors, and key-value pairs for global variables. ```typescript // Default settings structure const DEFAULT_SETTINGS = { DisabledReq: '>> Disabled <<', Key: '', Value: '', KeyValueCodeblocks: [], enableStatusBar: true, statusBarActiveColor: '#4ade80', statusBarInactiveColor: '#9ca3af', } ``` -------------------------------- ### Custom Output Formatting with format Flag Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Formats the API response output using custom templates, which can include HTML or plain text. Placeholders `{}` are used to insert extracted values. ```req url: https://jsonplaceholder.typicode.com/posts/1 show: $.[title,body] format:

{}

{}

``` -------------------------------- ### Basic API Request with URL Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md Defines a basic API request using the `req` codeblock, specifying the URL as the only required parameter. It also shows how to embed frontmatter variables within the URL. ```markdown ```req # this is just a comment url: https://jsonplaceholder.typicode.com/users/{{this.id}} ``` ``` -------------------------------- ### Search Movies with API Request Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/usecase/index.md Searches for movies using the The Movie Database (TMDb) API. It supports passing front-matter properties like `title` using `{{this.title}}` for dynamic queries. Requires a TMDb API key. The `show` parameter extracts the title of the first search result. ```markdown ```req url: https://api.themoviedb.org/3/search/movie?query={{this.title}}&api_key=YOUR_API_KEY show: $.results[0:].title ``` ``` -------------------------------- ### Making API Requests with 'req' Code Block Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/index.md This code block demonstrates how to use the 'req' language identifier to make an API request. It specifies the URL, HTTP method, request body, headers, a query to display a specific part of the response ('show'), a unique request identifier ('req-uuid'), and an option to disable the request. This functionality is specific to the APIRequest Obsidian plugin. ```markdown ```req url: https://my-json-server.typicode.com/typicode/demo/comments method: post body: {"id":1} headers: {"Accept": "application/json"} show: $.id req-uuid: IDpersona disabled ``` ``` -------------------------------- ### Make API Request with APIRequest Plugin (req) Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/index.md This code block demonstrates how to make an API request using the APIRequest plugin in Obsidian. It specifies the URL, HTTP method, request body, headers, and how to display a specific part of the response using a JSONPath expression. The `req-uuid` can be used to reference this request elsewhere, and the `disabled` flag can be used to temporarily disable the code block. ```req url: https://my-json-server.typicode.com/typicode/demo/comments method: post body: {"id":1} headers: {"Accept": "application/json"} show: $.id req-uuid: IDpersona disabled ``` -------------------------------- ### Update Frontmatter Properties with properties Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md The `properties` flag enables updating frontmatter properties with data from the API response. This requires a JSON response and the `show` flag. Properties are comma-separated, and internal Obsidian links can be created using the `[[..]]` syntax. ```markdown ```req url: https://jsonplaceholder.typicode.com/posts/1 show: $.[id,title] properties: id, title ``` ``` -------------------------------- ### Frontmatter Variable Interpolation Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Uses variables defined in the note's frontmatter YAML within API requests via the `{{this.variableName}}` syntax. This allows for dynamic request parameters based on note content. ```req # Assumes frontmatter contains: id: 5 url: https://jsonplaceholder.typicode.com/users/{{this.id}} show: $.name ``` -------------------------------- ### Save Response to File Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Saves the complete API response to a file within the Obsidian vault using the 'save-as' flag. This allows for persistent storage of API results. ```req url: https://jsonplaceholder.typicode.com/posts/1 save-as: posts/1.json ``` -------------------------------- ### POST Request with Body and Headers Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Sends data to an API endpoint using the POST method. It allows specifying custom headers and a JSON body for the request. ```req url: https://jsonplaceholder.typicode.com/posts method: post headers: {"Content-type": "application/json; charset=UTF-8"} body: {"title": "My Post", "body": "Post content here", "userId": 1} ``` -------------------------------- ### Access Cached Data with Dataview Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Retrieves and displays data stored in localStorage using the 'req-user-data' key. This is useful for accessing cached API responses within Obsidian notes via Dataview for advanced querying and display. ```dataviewjs dv.paragraph(localStorage.getItem("req-user-data")) ``` -------------------------------- ### Global Variables Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Accesses globally defined variables, configured in the plugin settings, directly within API requests. This is useful for sensitive information like API keys. ```req url: https://api.example.com/data headers: {"Authorization": "Bearer {{API_KEY}}"} ``` -------------------------------- ### JSONPath Data Extraction with show Flag Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Extracts specific fields from JSON API responses using JSONPath expressions defined in the 'show' flag. This enables precise data filtering. ```req url: https://api.chess.com/pub/player/hikaru/stats show: $['chess_daily']['last']['rating'] ``` -------------------------------- ### Multiple Values with JSONPath Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Extracts multiple values from a JSON response by specifying multiple JSONPath expressions. This can be done using array notation or the '+' operator to combine paths. ```req url: https://api.chess.com/pub/player/hikaru/stats show: $.chess_daily[last,best].rating + $.chess960_daily[last,best].rating ``` -------------------------------- ### Reuse Cached Data with localStorage Syntax Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Accesses previously cached API responses in other code blocks using the `{{ls.UUID>JSONPath}}` syntax. This enables data reuse and chaining of requests. ```req url: https://api.todoist.com/rest/v2/tasks headers: {"Authorization": "Bearer {{ls.token>$.access_token}}"} show: $..content req-uuid: todos ``` -------------------------------- ### Update Frontmatter Properties Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Automatically updates frontmatter properties in the current note with values extracted from the API response. The 'properties' flag specifies which fields to update. ```req url: https://jsonplaceholder.typicode.com/posts/1 show: $.[id,title] properties: id, title ``` -------------------------------- ### Enable Auto-Update for API Responses with auto-update Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md When the `auto-update` flag is present, the code block will attempt to automatically update the response whenever possible. This is particularly useful when using `req-uuid` to ensure cached responses are refreshed. ```markdown ```req url: https://jsonplaceholder.typicode.com/posts/1 req-uuid: firstPost auto-update save-as: posts/1.json ``` ``` -------------------------------- ### Store and Retrieve API Responses with req-uuid Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md The `req-uuid` flag allows you to assign a unique identifier to an API request. This enables storing the response in `localStorage` for later use in other blocks or notes, preventing redundant requests. Responses can be accessed directly using the `req-uuid` or via Dataview. ```markdown ```req url: https://jsonplaceholder.typicode.com/users/1 show: $.name req-uuid: test-{{this.username}} ``` ``` ```markdown ```req url: https://jsonplaceholder.typicode.com/users/1 req-uuid: name ``` ``` ```javascript ```dataviewjs dv.paragraph(localStorage.getItem("req-UUID")) ``` ``` ```javascript ```dataviewjs localStorage.removeItem("req-name") ``` ``` -------------------------------- ### Slice Array Elements Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Extracts data from a specific range of elements within an array in the API response using slice notation. This allows for selecting subsets of array data. ```req url: https://jsonplaceholder.typicode.com/users show: $..[:3].address.city ``` -------------------------------- ### Loop Over Array Elements Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Iterates over elements within an array in the API response to extract nested values from all array items. This is useful for processing lists of data. ```req url: https://jsonplaceholder.typicode.com/users show: $..address.city ``` -------------------------------- ### Hidden Execution Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Executes API requests silently without displaying any output using the 'hidden' flag. This is useful for background tasks like caching data. ```req url: https://jsonplaceholder.typicode.com/users/1 req-uuid: silent-user hidden ``` -------------------------------- ### Hide API Request Output with hidden Flag Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md The `hidden` flag prevents the output of an API request from being displayed in the note. This is useful for requests that perform actions or fetch data without needing to show the result directly. ```markdown ```req url: https://jsonplaceholder.typicode.com/users/1 req-uuid: name hidden ``` ``` -------------------------------- ### Auto-Update Cached Responses Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Forces a refresh of cached API responses on every load by using the 'auto-update' flag in conjunction with 'req-uuid'. This ensures the cached data is always up-to-date. ```req url: https://jsonplaceholder.typicode.com/posts/1 req-uuid: firstPost auto-update ``` -------------------------------- ### Request Caching with req-uuid Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Caches API responses in localStorage using a unique request identifier ('req-uuid'). Cached responses can be reused across different code blocks and notes until explicitly refreshed. ```req url: https://jsonplaceholder.typicode.com/users/1 show: $.name req-uuid: user-data ``` -------------------------------- ### Disable API Request Execution with disabled Flag Source: https://github.com/rooyca/obsidian-api-request/blob/master/docs/docs/en/codeblocks.md Using the `disabled` flag prevents an API request code block from being executed entirely. This is helpful for temporarily disabling requests without removing the code, perhaps for testing or debugging purposes. ```markdown ```req url: https://jsonplaceholder.typicode.com/users/1 show: $.name req-uuid: name disabled ``` ``` -------------------------------- ### Disabled Requests Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Temporarily disables the execution of a request block by using the 'disabled' flag. This allows for commenting out requests without removing them. ```req url: https://jsonplaceholder.typicode.com/users/1 show: $.name req-uuid: name disabled ``` -------------------------------- ### Remove Cached Response with Dataview Source: https://context7.com/rooyca/obsidian-api-request/llms.txt Removes a specific cached response from localStorage using the 'req-user-data' key. This action can be performed via Dataview or through the plugin's settings UI to clear stored data. ```dataviewjs localStorage.removeItem("req-user-data") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.