Foundation Data & Integrations
Outbound HTTP Requests (Scripted)
6 min
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 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 http get("http //httpbin org/{method}") routeparam("method", "get") querystring("name", "mark") execute(); 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 system http client disable ssl validation allowed 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});