#!/usr/bin/env groovy def call(String apiUrl, String user, String pass, String url) { def response = httpRequest( url: "${apiUrl}/accounts/login", httpMode: 'POST', contentType: 'APPLICATION_JSON', requestBody: writeJSON(json: [ 'user': user, 'password': pass ], returnText: true) ) def login = readJSON text: response.content httpRequest( url: "${apiUrl}/${url}", customHeaders: [[name: 'Authorization', value: login.token]] ) httpRequest( url: "${apiUrl}/accounts/logout", httpMode: 'POST', customHeaders: [[name: 'Authorization', value: login.token]] ) }