Make HTTP(s) requests
Maestro comes with its own JavaScript HTTP API
// script.js
var response = http.get('https://example.com')
output.script.result = response.body
Use
json()
function to parse JSON responses. For example, assume that
https://example.com/jsonEndpoint
returns the following result:{
"myField": {
"mySubField": "Test value"
}
}
mySubField
could then be accessed in the following way:// script.js
var response = http.get('https://example.com/jsonEndpoint')
output.script.result = json(response.body).myField.mySubField
To send body to a given endpoint, specify a
body
parameter:// script.js
var response = http.post('https://example.com/myEndpoint', {
body: JSON.stringify(
{
myField: "Payload"
}
)
})
Headers can be provided in a
headers
parameter// script.js
var response = http.get('https://example.com', {
headers: {
Authorization: 'Bearer MyToken'
}
})
The following request methods are provided out of the box:
http.get
http.post
http.put
http.delete
To send a request of any other HTTP method, use
http.request
// script.js
var response = http.request('https://example.com`, {
method: "GET" // or specify any other method, i.e. OPTION
})
Field Name | Value |
---|---|
ok | true if request was successful, false otherwise |
status | HTTP status code (i.e. 200 ) |
body | String body of the response |
Last modified 3mo ago