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:
@@ -13,7 +13,7 @@ variables:
|
|||||||
- name: note_id
|
- name: note_id
|
||||||
value: 7710a602-g29b-61d4-c716-446655440002
|
value: 7710a602-g29b-61d4-c716-446655440002
|
||||||
- name: library_id
|
- name: library_id
|
||||||
value: d2932c11-cd39-4c4a-b940-124b75964099
|
value: dd03d719-76c8-4398-93ec-9258d2becf85
|
||||||
- name: job_id
|
- name: job_id
|
||||||
value: d5554991-1a13-4f60-9a70-82d19ed1abe2
|
value: d5554991-1a13-4f60-9a70-82d19ed1abe2
|
||||||
- name: rating
|
- name: rating
|
||||||
|
|||||||
@@ -2,15 +2,43 @@ info:
|
|||||||
name: Get Libraries (Admin)
|
name: Get Libraries (Admin)
|
||||||
type: http
|
type: http
|
||||||
seq: 1
|
seq: 1
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
url: '{{base_url}}/api/libraries'
|
url: "{{base_url}}/api/libraries"
|
||||||
auth: inherit
|
|
||||||
body:
|
|
||||||
type: none
|
|
||||||
headers:
|
headers:
|
||||||
- key: Content-Type
|
- name: ""
|
||||||
value: application/json
|
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: |-
|
docs: |-
|
||||||
## Get Libraries (Admin)
|
## Get Libraries (Admin)
|
||||||
|
|||||||
Reference in New Issue
Block a user