# API Calls

<span style="color: rgb(9,30,66);">For API calls Cookies are handled automatically, only the </span>*<span style="color: rgb(9,30,66);">incognito</span>*<span style="color: rgb(9,30,66);"> call won't add nor set any cookies</span>

<span style="color: rgb(9,30,66);">With the </span>*<span style="color: rgb(9,30,66);">addGlobalHeader</span>*<span style="color: rgb(9,30,66);"> call, you can add a global header automatically for every call, but it won't be added if you process the call with </span>*<span style="color: rgb(9,30,66);">incognito</span>*<span style="color: rgb(9,30,66);"> call.</span>

<span style="color: rgb(9,30,66);">Both calls </span>*<span style="color: rgb(9,30,66);">process</span>*<span style="color: rgb(9,30,66);"> and </span>*<span style="color: rgb(9,30,66);">incognito</span>*<span style="color: rgb(9,30,66);"> will be added to AIQ requests and responses.</span>

#### <span style="color: rgb(9,30,66);">formData()</span> 

<span style="color: rgb(9,30,66);">Creates a map that can be used in body requests (POST, PUT, PATCH, DELETE) as </span>**<span style="color: rgb(77,81,86);">application/x-www-form-</span>*****<span style="color: rgb(9,30,66);">urlencoded </span>**<span style="color: rgb(9,30,66);">content type</span>*<span style="color: rgb(51,51,51);">. Elements can be added to the form similar to the next code </span>

<div class="code panel pdl conf-macro output-block" id="bkmrk-var-myform-%3D-formdat" style="border-width: 1px;"><div class="codeContent panelContent pdl">```
var myForm = formData();
myForm.put("username",$username);
myForm.put("password",$password);

post($url,myForm);
```

 </div> </div>#### <span style="color: rgb(9,30,66);">createGet (String: URL) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic GET call, useful for adding headers before sending it</span>

#### <span style="color: rgb(9,30,66);">createHead (String: URL) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic HEAD call, useful for adding headers before sending it</span>

#### <span style="color: rgb(9,30,66);">createOptions (String: URL) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic OPTIONS call, useful for adding headers before sending it</span>

   
<span style="color: rgb(9,30,66);">createPost(String: URL) → HttpRequest</span>

<span style="color: rgb(9,30,66);">Creates a basic POST call, without body, useful for adding headers before sending it</span>

<div class="code panel pdl conf-macro output-block" id="bkmrk-var-postrequest-%3D-cr" style="border-width: 1px;"><div class="codeContent panelContent pdl">```
var postRequest = createPost("http://demosite.appvance.com/orders/populate");
```

 </div> </div>#### <span style="color: rgb(9,30,66);">createPost(String: URL,Map&lt;String, String&gt;:data) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic POST multipart form data post, useful for adding headers before sending it</span>

<div class="code panel pdl conf-macro output-block" id="bkmrk-var-loginform-%3D-form" style="border-width: 1px;"><div class="codeContent panelContent pdl">```
var logInForm = formData();
logInForm.put("username","appvance");
logInForm.put("password","appvance");

var postData = createPost("http://demosite.appvance.com/orders/populate",logInForm);
process(postData);
```

 </div> </div>#### <span style="color: rgb(9,30,66);">createPost(String: URL,JSONObject: data) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic POST call with an "application/json" for content type and the body is the stringify of the json, useful for adding headers before sending it. Similar</span>

<div class="code panel pdl conf-macro output-block" id="bkmrk-var-jsonobject-%3D-%7B%7D%3B" style="border-width: 1px;"><div class="codeContent panelContent pdl">```
var jsonObject = {};
jsonObject.username= $username;
jsonObject.password = $password
var post = createPost($url,jsonObject);

var jsonArray = [];
jsonArray[0]= $firstEntry;
jsonArray[1]= $firstEntry;
var post = createPost($url,jsonArray);
```

 </div> </div>#### <span style="color: rgb(9,30,66);">createPost(String: URL, String: Content, MimeType:String) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a post with the specific content type</span>

#### createPost(String: URL,ExcelWrapper:ExcelWrapper) → HttpRequest

Creates a post call using multipart/form-data and a excel file. The excel mime is the standard application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

<div class="code panel pdl conf-macro output-block" id="bkmrk-var-postrequest-%3D-cr-1" style="border-width: 1px;"><div class="codeContent panelContent pdl">```
var postRequest = createPost("http://demosite.appvance.com/orders/populate",excelWrapper);
```

 </div> </div><div class="code panel pdl conf-macro output-block" id="bkmrk-%2F%2Fread-template-var-" style="border-width: 1px;"><div class="codeContent panelContent pdl">```
//Read template
var echoTemplate = new java.lang.String(readBytes("{ds}/request.echo.xml")); //SOME TEXT FILE

//Process template
var echoString=echoTemplate.replace("ECHO1","Hello World");
//Create post method
var echoPost = createPost("http://localhost:8080/TMServer/ws/TestNode",echoString,"text/xml"); 

echoPost.addHeader("SOAPAction","");
var result=process(echoPost);
```

 </div> </div>#### <span style="color: rgb(9,30,66);">createPatch(String: URL) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic PATCH call, without body, useful for adding headers before sending it.</span>

#### <span style="color: rgb(9,30,66);">createPatch(String: URL,Map&lt;String, String&gt;:data) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic PATCH multipart form data patch, useful for adding headers before sending it.</span>

#### <span style="color: rgb(9,30,66);">createPatch(String: URL,JSONObject:data) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic PATCH with an "application/json" for content type and the body is the stringify of the json, useful for adding headers before sending it.</span>

#### <span style="color: rgb(9,30,66);">createPut(String:URL) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic PUT call, without body, useful for adding headers before sending it.</span>

#### <span style="color: rgb(9,30,66);">createPut(String:URL,Map&lt;String, String&gt;:data) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic PUT multipart form data put, useful for adding headers before sending it.</span>

#### <span style="color: rgb(9,30,66);">createPut(String: URL,JSONObject: data) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic PUT call with an "application/json" for content type and the body is the stringify of the json, useful for adding headers before sending it.</span>

#### <span style="color: rgb(9,30,66);">createDelete(String: URL) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic DELETE call, without body, useful for adding headers before sending it.</span>

#### <span style="color: rgb(9,30,66);">createDelete(String: URL,Map&lt;String, String&gt;: data) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic delete multipart form data put, useful for adding headers before sending it.</span>

#### <span style="color: rgb(9,30,66);">createDelete(String: URL,JSONObject: data) → HttpRequest</span> 

<span style="color: rgb(9,30,66);">Creates a basic deletewith an "application/json" for content type and the body is the stringify of the json, useful for adding headers before sending it</span>

#### <span style="color: rgb(9,30,66);">get (String: URL) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic get, requires a URL and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">head (String: URL) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic head, requires a URL and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">options(String: URL) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic OPTIONS, requires an URL and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">post(String: URL) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic post without a body, requires a URL and return a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">post(String: URL, Map&lt;String, String: data) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic post with "x-www-form-urlencoded" format, where the entries are the data entries, requires a URL and the map of entries and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">post(String: URL, JSONObject: data) → HttpResponse </span> 

<span style="color: rgb(9,30,66);">This call is a basic post with "application/json format, where the data is the JSON.stringify of the object, requires a URL and the json object and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### post(String: URL, data: ExcelWrapper) → HttpResponse 

This call is makes a post, using a multipart/form data and a excel content. The mime type is application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

#### <span style="color: rgb(9,30,66);">put(String: URL) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic put without a body, requires a URL and return a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">put(String: URL, Map&lt;String, String&gt;: data) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic put with "x-www-form-urlencoded" format, where the entries are the data entries, requires a URL and the map of entries and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error</span>

#### <span style="color: rgb(9,30,66);">put(String: URL, JSONObject :data) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic put with "application/json format, where the data is the JSON.stringify of the object, requires a URL and the JSON object and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">patch(String: URL) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic patch without a body, requires a URL and return a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">patch (String: URL, Map&lt;String, String&gt;: data)→ HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic patch with "x-www-form-urlencoded" format, where the entries are the data entries, requires a URL and the map of entries and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">patch(String: URL,JSONObject :data)→ HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic patch with "application/json format, where the data is the JSON.stringify of the object, requires a URL and the json object and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error.</span>

#### <span style="color: rgb(9,30,66);">\_delete(String: URL)→ HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic delete without a body, requires a URL and return a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error. \_delete is used instead of delete as delete is a reserved keyword in js.</span>

#### <span style="color: rgb(9,30,66);">\_delete(String: URL, Map&lt;String, String&gt;: data)→ HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic HTTP delete method with "x-www-form-urlencoded" format, where the entries are the data entries, requires a URL and the map of entries, and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error. \_delete is used instead of delete as delete is a reserved keyword in js.</span>

#### <span style="color: rgb(9,30,66);">\_delete(String: URL,JSONObject: data) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">This call is a basic HTTP delete method with "application/json” format, where the data is the JSON.stringify of the object, requires a URL and the JSON object, and returns a HttpResponse if the connection succeeds. Otherways it will throw a Server not found or Connection reset, Connection Timeout depending on the error. \_delete is used instead of delete as delete is a reserved keyword in js.</span>

#### <span style="color: rgb(9,30,66);">process(HttpRequest:request) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">Process the request adds automatically the cookies and global headers and returns the response. The response cookies (if any) will be used in subsequent request calls</span>

#### <span style="color: rgb(9,30,66);">incognito(HttpRequest: request) → HttpResponse</span> 

<span style="color: rgb(9,30,66);">Process the request as it is without adding cookies or global headers. The response cookies (if any) will be discarded. Keep in mind incognito may be set over the same socket of request calls. There is no socket-level management in Service Suite yet</span>

#### <span style="color: rgb(9,30,66);">addGlobalHeader(String: key, String: value) </span> 

<span style="color: rgb(9,30,66);">Adds new global header entry used with the </span>***<span style="color: rgb(9,30,66);">process </span>**<span style="color: rgb(9,30,66);">command ,</span>*<span style="color: rgb(9,30,66);"> global headers won't be added with the </span>**<span style="color: rgb(9,30,66);">incognito</span>**<span style="color: rgb(9,30,66);"> call</span>

<div class="code panel pdl conf-macro output-block" id="bkmrk-addglobalheader%28%22hel" style="border-width: 1px;"><div class="codeContent panelContent pdl">```
addGlobalHeader("Hello","World");
var logInForm = formData();
logInForm.put("username","appvance");
logInForm.put("password","appvance");
var postData = createPost("http://demosite.appvance.com/orders/populate",logInForm);
process(postData);
```

 </div> </div>#### <span style="color: rgb(9,30,66);">removeGlobalHeader(String: key)</span> 

<span style="color: rgb(9,30,66);">Removes a global header.</span>

#### <span style="color: rgb(9,30,66);">clearGlobalHeaders()</span> 

<span style="color: rgb(9,30,66);">Removes every global header.</span>

#### <span style="color: rgb(9,30,66);">getGlobalHeaders() → HashMap&lt;String,String&gt;</span> 

Returns list of global headers

#### getCookies(String: url)<span style="color: rgb(9,30,66);">→ List&lt;HttpCookie&gt;</span>

Gets the cookies from a specified URL

#### clearCookies()

Clear every cookie from all domains

#### clearCookies(String:domain)

Clear every cookie from one specific domain

#### getCookie(String: URL,String:name) <span style="color: rgb(9,30,66);">→ HttpCookie</span>

Gets the cookie from a specified URL and the cookie value

#### <span style="color: rgb(23,43,77);">hgetCookieValue(String:URL,String:name)</span><span style="color: rgb(9,30,66);">→ String</span> 

Gets the cookie value from a specified URL and the cookie value

#### readCSV(String: fileName) <span style="color: rgb(9,30,66);">→ String \[ \]\[ \]</span>

<span style="color: rgb(9,30,66);">Gets the file name and parses the data using Excel CSV parser to returns it as a string array</span>

#### writeCSV(String: filepath,String\[\]\[\]: data)

<span style="color: rgb(9,30,66);">Gets a path to creates and writes bytes in a CSV file with data received as a string array</span>

#### writeCSV(String: filepath,Map&lt;Object,Object&gt;: data)

<span style="color: rgb(9,30,66);">Gets a path to creates and writes bytes in a CSV file with data received as a map object</span>

#### writeJSON(String: filepath, JSONObject: obj)

<span style="color: rgb(9,30,66);">Gets a path to creates and writes a JSON and parses the data into a string array</span>

#### writeJSON(String: filepath, JSONArray: array)

<span style="color: rgb(9,30,66);">Gets a path to creates and writes a JSON and parses the data into a string array</span>

#### <span style="color: rgb(9,30,66);">writeJSON(String: filepath,Object: o)</span> 

<span style="color: rgb(9,30,66);">Gets a path to creates and writes a JSON and if gets a native object parses the JSON object into a string or if is a native array parses it to a JSON array</span>

####  readImage(String: <span style="color: rgb(9,30,66);">filepath</span>) <span style="color: rgb(9,30,66);">→ BufferedImage</span>

<span style="color: rgb(9,30,66);">Gets an image path and verifies if the path exists to read an image otherwise reports that the given path was not found</span>

#### <span style="color: rgb(9,30,66);">readText(String: filepath)</span><span style="color: rgb(9,30,66);">→ String</span> 

 Gets a path and verifies the file exists and read the text it has

#### writeText(String: filepath,String: data)

Gets a path and writes it with the data provided on the data variable

<div id="bkmrk-last-updated%3A-june-0">---

Last updated: <span class="mc-variable General.NewDateTimeVariable variable">June 02, 2023</span>

If you have any feedback on this topic, please contact us at <documentation@appvance.ai>

</div>