info:
  name: Add Library Folder
  type: http
  seq: 1

http:
  method: POST
  url: "{{base_url}}/api/libraries/{{library_id}}/folders"
  headers:
    - name: ""
      value: application/json
  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
