Outbound HTTP requests (Scripted)
Servicely provides a comprehensive API for performing outbound HTTP communications from the Scripting Environment.
There are four classes that make up the support for outbound HTTP requests: HTTP, GetRequest, HttpRequestWithBody and HttpResponse. Requests are initiated by the HTTP class.
HTTP
Method | Description |
---|---|
get(url: string): GetRequest | Return a GET request for a specific URL |
head(url: string): GetRequest | Return a HEAD request for a specific URL |
post(url: string): HttpRequestWithBody | Return a POST request for a specific URL |
put(url: string): HttpRequestWithBody | Return a PUT request for a specific URL |
patch(url: string): HttpRequestWithBody | Return a PATCH request for a specific URL |
options(url: string): GetRequest | Return an OPTIONS request for a specific URL |
delete(url: string): HttpRequestWithBody | Return a DELETE request for a specific URL |
GetRequest
Method | Description |
---|---|
basicAuth(username: string, password: string) | Set basic auth credentials |
socketTimeout(socketTimeout: number) | Set the socket timeout of the connection |
connectTimeout(connectTimeout: number) | Set the connect timeout of the connection |
header(name: string, value: string) | Set a request header |
getUrl(): string | Get the request URL |
routeParam(name: string, value: string) | Set a placeholder in the URL with a value. E.g. |
disableSSLValidation() | To use this functionality, you need to be on Version 1.10 or later. This allows you to disable the validation of SSL certificates (common for self signed certificates). This will only work if you also have a boolean application property set to true called HTTP.disableSSLValidation()
.get('https://example.com')
.execute()
.getBody() |
queryString(name: string, value: string) | Set a query string parameter |
execute(): HttpResponse | Execute the request |
executeBinary(): HttpResponseBinary | Execute the request to get http response in bytes |
apiTokenAuth(token: string) | Set an outbound auth token |
HttpRequestWithBody
All the methods of GetRequest along with the following
Method | Description |
---|---|
contentType(type: string) | Set the Content-Type header for the request |
accept(type: string) | Set the Accept header for the request |
body(body: string) | Set the body of the request |
bodyJson(bodyJson: any) | Set the body of the request as JSON |
bodyBytes(bodyBytes: any) | Set the body of the request as a byte array |
field(name: string, value: string) | Set a field parameter and its value |
fieldAttachment(“file”, record_id:string) | This allows you to send an attachment via “binary”/multipart form data to systems and can be used to send multiple attachments in one request. |
HttpResponse
Method | Description |
---|---|
isError(): boolean | If the status not is not 2xx Success code |
getBody(): string? | Return the body |
body(): string? | Return the body |
getJsonBody(): any? | Return the body as JSON |
jsonBody(): any? | Return the body as JSON |
getStatus(): number | Return the status code |
status(): number | Return the status code |
getStatusText(): string | Return the status text |
statusText(): string | return the status text |
HttpResponseBinary
Method | Description |
---|---|
toAttachment(): TableRecord | Storing a HTTPResponseBinary into Attachment table. E.g. let responseObj = HTTP.get(url).executeBinary();
responseObj.toAttachment({
RelatedField: "Attachments",
ExternalKey: url,
ParentRecord: current,
FileName: fileName
}); |
Related content
Servicely Documentation