Add environment variable persistence for library and folder IDs in Bruno API collection scripts. Create Library and Add Library Folder endpoints now automatically save their respective IDs to the environment for use in subsequent requests.
54 lines
1.1 KiB
YAML
54 lines
1.1 KiB
YAML
info:
|
|
name: Add Library Folder
|
|
type: http
|
|
seq: 1
|
|
|
|
http:
|
|
method: POST
|
|
url: "{{base_url}}/api/libraries/{{library_id}}/folders"
|
|
body:
|
|
type: json
|
|
data: |-
|
|
{
|
|
"folder_path": "{{library_folder}}"
|
|
}
|
|
auth: inherit
|
|
|
|
runtime:
|
|
scripts:
|
|
- type: after-response
|
|
code: |-
|
|
function onResponse(res) {
|
|
try {
|
|
const responseBody = res.getBody();
|
|
const id = responseBody.id;
|
|
|
|
if (id) {
|
|
bru.setEnvVar("library_folder_id", id, { persist: true });
|
|
console.log("Library Folder ID saved:", id);
|
|
}
|
|
|
|
if (!id) {
|
|
console.log("No id found in response.");
|
|
}
|
|
} catch (error) {
|
|
console.error("Error in post-response script:", error.message);
|
|
}
|
|
}
|
|
onResponse(res);
|
|
|
|
settings:
|
|
encodeUrl: true
|
|
timeout: 0
|
|
followRedirects: true
|
|
maxRedirects: 5
|
|
|
|
docs: |-
|
|
## Add Library Folder
|
|
|
|
Adds a new folder path to a library for media scanning and indexing.
|
|
|
|
**Method:** POST
|
|
|
|
**Endpoint:** /api/libraries/{id
|