Function: Login to OpsView via REST – Part 1

by Simon Sparks · 1 November 2025

To use this function add it to the class library file named OpsViewService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: OpsViewService.ts

Description: Orchestrator Function to login to OpsView – Part 1

Function OpsViewLogon1

private OpsViewLogon1(objRESTOperation:RESTOperation, strOpsViewServerName: string, strUsername: string, strPassword: string): void {

    let objJson: { username: string, password: string } = {
        username: strUsername,
        password: strPassword
    };

    let objRESTRequest: RESTRequest = objRESTOperation.createRequest([], objJson);
    objRESTRequest.contentType = "application/json";
    objRESTRequest.setHeader("Accept", "application/json");

    let objRESTResponse: RESTResponse = objRESTRequest.execute();

    let strContentAsString: string = objRESTResponse.contentAsString;

    let objJSON: any = JSON.parse(strContentAsString);

    if (objRESTResponse.statusCode == 200) {
        this.objLogger.info("===== Successfully Logged into OpsView '" + strOpsViewServerName + "'");

        let strToken: string = objJSON.token;
    }
    else {
        this.objLogger.info("===== Failed to Login to OpsView '" + strOpsViewServerName + "'");

        let strMessage: string = objJSON.message;

        let strDetail: string = objJSON.detailmessage;
    }
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like