feat: automate library_id extraction from Get Libraries API response

- Update library_id in Bookhoard environment configuration
- Add post-response script to Get Libraries (Admin) endpoint
- Script automatically extracts and saves first library_id from response
- Enables seamless API testing without manual variable updates
This commit is contained in:
2026-03-27 21:14:31 -04:00
parent 3f36d99783
commit c9e085c164
2 changed files with 35 additions and 7 deletions
+34 -6
View File
@@ -2,15 +2,43 @@ info:
name: Get Libraries (Admin)
type: http
seq: 1
http:
method: GET
url: '{{base_url}}/api/libraries'
auth: inherit
body:
type: none
url: "{{base_url}}/api/libraries"
headers:
- key: Content-Type
value: application/json
- name: ""
value: application/json
auth: inherit
runtime:
scripts:
- type: after-response
code: |-
function onResponse(res) {
try {
const responseBody = res.getBody();
const id = responseBody.data[0].id;
if (id) {
bru.setEnvVar("library_id", id, { persist: true });
console.log("Library 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: |-
## Get Libraries (Admin)