Rest API Wrapper Around OOTB Rest API Including Current User

Roger1
Tera Contributor

I have a Rest API that wraps an OOTB Rest API.  I wish to include the authorization when calling the OOTB Rest API.  I have a prototype using Basic Auth, but I get a 401 when calling the OOTB Rest API.  Here is my code

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    var body = request.body.dataString;

    var authHeader = request.getHeader('Authorization');
    var url = 'https://hidden/api/sn_sc/v1/servicecatalog/items/hidden/order_now';
    var apiRequest = new sn_ws.RESTMessageV2();
    var apiResponse;
    var apiResponseBody;
            
    apiRequest.setRequestHeader("Authorization", authHeader);
    
    apiRequest.setEndpoint(url);
    apiRequest.setHttpMethod('POST');
    apiRequest.setRequestBody(body);
    apiResponse = apiRequest.execute();
    apiResponse.waitForResponse(80);
    var responseStatusCode = apiResponse.getStatusCode();
    if ((responseStatusCode < 200) || (responseStatusCode > 299)) {
       response.setError(new sn_ws_err.BadRequestError("Error StatusCode = " + responseStatusCode + " Msg = " + apiResponse.getErrorMessage()));
    }   
})(request, response);

 

When I review what is in, request.getHeader('Authorization'), the bearing token has more data than it should.  Is it possible to use the current authorization when access an OOTB Rest API? And if so how?

1 REPLY 1

Abhinav Duvvuri
Tera Contributor

Did you find a solution for this? I am facing the same issue too. 

 

Is there a better way to write wrappers? I have a file which I need to parse and validate before calling the OOTB API.