Question
· Jul 25, 2023

REST API Request Logging

I am working on my first REST operation to send a API Request to an internal server within our Network. I have finally got past the point of being able to connect using a SSL/TLS Configuration, but I am getting a ERROR <Ens>ErrHTTPStatus: Received non-OK status 403 from remote HTTP server: 'HTTP/1.1 403 Forbidden'.

I have tried using $$$TRACE within my operation to capture the different elements that are being sent to verify the Server, URL, SSL Configuration, and payload. Is there a way that I can see the entire RAW request message that is being sent to see why I might be getting a 403 error in response? What is the best way to go about logging the request message to the trace viewer that has the Header and Data elements?

for example using POSTMAN I can see the following.....

POST xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Host: xxxxxxxxxxxxxxxxxx
Epic-Client-ID: xxxxxxxxxxxxxxxxxxxxxx
Proxy-Connection: keep-alive
Accept: application/json
Content-Type: application/json
Authorization: Basic xxxxxxxxx
Content-Length: 119

{"PatientID":"x","PatientIDType":"xxxxxxx","ContactID":"x","ContactIDType":"xxxx","UserID":"xxxx","UserIDType":"xxxxxxx"}

and it sends a response with the same variables that I am using in the Operation, I just want to verify what is being sent in the RAW request to see if I can track down the 403 error.

I get the following response in postman, which is what I expect because I know I didn't send a correct Identifier.

{"Message":"An error occurred while executing the command: NO-PATIENT-FOUND details: No patient was found with the provided ID and ID type..","ExceptionMessage":"An error occurred while executing the command: NO-PATIENT-FOUND details: No patient was found with the provided ID and ID type..","ExceptionType":"System.Web.HttpException","StackTrace":null}

I would like to see if I can get both the RAW request message and the entire response if it is an error to display in the trace viewer.

Thanks

Product version: IRIS 2023.1
Discussion (16)2
Log in or sign up to continue

I have tried that but still unable to see the Request or Response being sent...

Class User.REST.Epic.EpicOperation Extends (EnsLib.REST.Operation, Ens.Util.JSON)

{

Parameter DEBUG As %Integer = 2;

Parameter INVOCATION = "Queue";

Method getPatientLocationRequest(pRequest As User.REST.Epic.Msg.GetPatientLocationRequest, Output pResponse As EnsLib.HTTP.GenericMessage) As %Status

{

    set tSC = $$$OK

    try{

      set tHTTPRequest = ##class(%Net.HttpRequest).%New()

      do tHTTPRequest.SetHeader("Epic-Client-ID","ed7ca30e-c16a-4053-9233-bff4f5661bb4")

      $$$TRACE("HttpRequest: "_tHTTPRequest) <this returns me just a pointer 8@%Net.HttpRequest>

      set tRequest = ##class(%DynamicObject).%New()

      set tRequest.PatientID = pRequest.PatientID

      set tRequest.PatientIDType = pRequest.PatientIDType

      set tRequest.ContactID = pRequest.ContactID

      set tRequest.ContactIDType = pRequest.ContactIDType

      set tRequest.UserID = pRequest.UserID

      set tRequest.UserIDType = pRequest.UserIDType

      set reqMsg = tHTTPRequest.EntityBody.Write(tRequest)

      $$$TRACE("reqMsg: "_reqMsg)

      set tSC = tHTTPRequest.EntityBody.Write(tRequest.%ToJSON())

      set tURL = ..Adapter.URL

      set tSC = ..Adapter.Post(tURL)

      set stream = "".....

Not sure I follow... I do all the SetHeader lines, then call  Do tHTTPRequest.EntityBody.Write() is that not writting the headers to tHTTPRequest?

    do tHTTPRequest.EntityBody.Write()
    do tHTTPRequest.OutputHeaders()
    set tURL= "/../../../../"  //..Adapter.URL
    set jsonRequest = {"........."}
    SET tSC = tHTTPRequest.EntityBody.Write(jsonRequest.%ToJSON())
    set tHTTPResposne = ##class(%Net.HttpResponse).%New()
    do tHTTPRequest.OutputParams()
    set tSC = ..Adapter.SendFormDataArray(.tHTTPResposne,"POST",,,tHTTPRequest)