Unable to call the API

Hi,

Below is our code and we are unable to call the API, issue lies with the headers.

// Define the URL
var url = "https://fqdn:13443/SM/7/IncidentManagement.wsdl";

 

// Define the headers array and add the "Cookie" header
var headers = [
    ["Cookie", "sails.sid=s%3AjrjtzQhAlmZX319NMKj4qQh2f5N8FO5n.1bKW9%2FSQ6Be6y3DgnYxJtVZ9SopZSzDpjyxWmNU%2FHKk"]
];

 

var WSDLrequest;
var reply;
var respHeaders = new Object();

 

try {
    // Make the HTTP GET request
    WSDLrequest = doHTTPRequest("GET", url, headers, null, 10, 10, null, respHeaders);

 

    // Print response headers
    print("The response headers of the doHTTPRequest are:");
    for (var name in respHeaders) {
        print(name + "=" + respHeaders[name]);
    }

 

    // Print the result of the doHTTPRequest
    print("The result of the doHTTPRequest is:\n" + WSDLrequest);

 

    // Write the response body to a file
    reply = writeFile("C:\\IncidentManagement.wsdl", "text", WSDLrequest);
} catch (e) {
    // Handle exceptions
    print("WSDL request failed with exception:\n" + e);
}

BR,

Haniyya Rehan

Parents
  • 0  

    Hi Haniyya

    Would you please to try this http header?

    //Content-Type
    var contentHeader = new Header();
    contentHeader.name = "Content-Type";
    contentHeader.value = "application/json";
    headers.push(contentHeader);
    //Auth
    var authHeader = new Header();
    authHeader.name = "Authorization";
    authHeader.value = "Basic " + lib.smis_CommonLib.encode64("falcon" + ":" + "*********?");
    //Construct Header
    headers.push(authHeader);

    I t hink the headers is not correct.

    Thanks

  • 0 in reply to   

    Hi Simon,

    Thank you for your reply.

    But I am still experiencing the  "ReferenceError: headers is not defined".

    BR,

    Haniyya Rehan 

  • 0   in reply to 

    Hi Haniyya

    Would you please to post you last JS code here?

    Thanks

  • 0 in reply to   

    Hi Simon,

    Below is my code:

    var url = "">https://postman-echo.com/get";
    //var headers = [
    // ["Cookie", "sails.sid=s%3AjrjtzQhAlmZX319NMKj4qQh2f5N8FO5n.1bKW9%2FSQ6Be6y3DgnYxJtVZ9SopZSzDpjyxWmNU%2FHKk"]
    //];

    //Content-Type

    var contentHeader = new Header();
    var headers = new Array();
    contentHeader.name = "Content-Type";
    contentHeader.value = "application/json";
    headers.push(contentHeader);

    var WSDLrequest;
    var respHeaders = new Object();

    try {
    WSDLrequest = doHTTPRequest("GET", url, headers, null, 10, 10, respHeaders);
    print("The response headers of the doHTTPRequest is:");
    for (var name in respHeaders) {
    print(name + "=" + respHeaders[name]);
    }
    print("The result of the doHTTPRequest is \n" + WSDLrequest);
    } catch (e) {
    print("WSDL request failed with exception \n" + e);
    }

    Following is error that I am experiencing:

  • 0   in reply to 

    Hi

    Here is my working code:

    // Define the URL
    var url = "">SM_FQDN:13080/.../IncidentManagement.wsdl";

    var contentHeader = new Header();
    var headers = new Array();
    contentHeader.name = "Content-Type";
    contentHeader.value = "application/json";
    headers.push(contentHeader);

    var authHeader = new Header();
    authHeader.name = "Authorization";
    authHeader.value = "Basic " + lib.smis_CommonLib.encode64("falcon" + ":" + "<My Password>");
    headers.push(authHeader);

    var WSDLrequest;
    var respHeaders = new Object();

    try {
    WSDLrequest = doHTTPRequest("GET", url, headers, null, 10, 10, respHeaders);
    print("The response headers of the doHTTPRequest is:");
    for (var name in respHeaders) {
    print(name + "=" + respHeaders[name]);
    }
    print("The result of the doHTTPRequest is \n" + WSDLrequest);
    } catch (e) {
    print("WSDL request failed with exception \n" + e);
    }

Reply
  • 0   in reply to 

    Hi

    Here is my working code:

    // Define the URL
    var url = "">SM_FQDN:13080/.../IncidentManagement.wsdl";

    var contentHeader = new Header();
    var headers = new Array();
    contentHeader.name = "Content-Type";
    contentHeader.value = "application/json";
    headers.push(contentHeader);

    var authHeader = new Header();
    authHeader.name = "Authorization";
    authHeader.value = "Basic " + lib.smis_CommonLib.encode64("falcon" + ":" + "<My Password>");
    headers.push(authHeader);

    var WSDLrequest;
    var respHeaders = new Object();

    try {
    WSDLrequest = doHTTPRequest("GET", url, headers, null, 10, 10, respHeaders);
    print("The response headers of the doHTTPRequest is:");
    for (var name in respHeaders) {
    print(name + "=" + respHeaders[name]);
    }
    print("The result of the doHTTPRequest is \n" + WSDLrequest);
    } catch (e) {
    print("WSDL request failed with exception \n" + e);
    }

Children