Visual Builder

Get Involved. Join the Conversation.

Topic

    ninian1927
    2 different response types from REST endpoint, how to...
    Topic posted October 11, 2019 by ninian1927Red Ribbon: 250+ Points, tagged Action Flows 
    24 Views, 10 Comments
    Title:
    2 different response types from REST endpoint, how to account for this?
    Content:

    Hi,

    I am creating a login page which calls a POST REST endpoint. I have create a type from the response when the login is successful, I receive a lot of data back about the user along with a token. However, if the authentication is not successful the response has completely different variables. Currently on my action for a button I have the call REST endpoint linked to the responseType of a call that is successful. However, if the login is not successful then those values aren't available to this responseType as they are stored in a different type. 

    Am I missing something obvious here? 

    Comment

     

    • Shay Shmeltzer

      Can you define a new type manually with the structure of the returned value when the REST call fails?

      Then base a variable on this new type.

      Then in your action chain in the Call REST action you will have an option to specify a flow when the call is not successful - and there you can assign the value in a fail state to the new variable.

      • ninian1927

        Thanks for the reply, I've been going back to this but no luck.

        When the REST call fails, how do I get the values of the REST call that failed back? If the "responseType" of the REST call is created using the successful REST login call, then during the FAIL flow, I have no way to retrieve the failed values as they are different fields than the ones defined in the responeType for the successful login. In VBCS when assiging variables, on the left side I can just see the results that correspond to the succesful login.

        • Shay Shmeltzer

          My guess would be that if the service returns two different formats then you shouldn't specify a responseType - and then just assign the result of the REST call to an object with the right structure.

          • ninian1927

            Ok, thanks.

            This is a JD Edwards tokenrequest response, so the success repsonse will be something like:

            {
               "username": "JDE",
               "environment": "JDV920",
               "role": "*ALL",
               "jasserver": "http://jas_server_url",
               "userInfo":    {
                  "token": "0448Pf+4aytugDOBJsaGdF6iyKpRaWazb9+GC1ubN4qKDw=MDE5MDA4MTg3MDY5MzQxMDcyODQ1MDAzOU15RGV2aWNlMTQ3ODYzODQ2MTQ2Mg==",
                  "langPref": "  ",
                  "locale": "en",
                  "dateFormat": "MDE",
                  "dateSeperator": "/",
                  "simpleDateFormat": "MM/dd/yyyy",
                  "decimalFormat": ".",
                  "addressNumber": 1,
                  "alphaName": "Financial/Distribution Company",
                  "appsRelease": "E920",
                  "country": " ",
                  "username": "JDE"
               },
               "userAuthorized": false,
               "version": null,
               "poStringJSON": null,
               "altPoStringJSON": null,
               "aisSessionCookie": "cDxFuGIaMbAfre8q43mIULN15UNQRMZI3FwwV2GZ4qAsLX20iRh6!541095169!1478638461466",
               "adminAuthorized": true
            }
            

            Whereas a unsuccesfull response will be:
            {
                "type": "HTTP://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1",
                "status": 403,
                "title": "Forbidden",
                "detail": "{\"message\":\"Authorization Failure: Incorrect User ID or Password.\",\"exception\":\"E1LoginException\",\"timeStamp\":\"2019-10-15T15:18:36.608-0600\"}"
            }

             

            I am having a real hard time getting this working. The only way I can succesfully get the values is using a responseType, but then that only works for success. I am new to VBCS so must be doing something wrong. I tried to assign to my "success" type variable upon success in the action flow, and the same for the fail, but it doesnt seem to map the variables doing it this way?

            • Shay Shmeltzer

              ok so in this case, if we keep the success flow going into the strongly typed variable, on the failure flow of the action chain - can you access the status and detail object by referring to them with an EL such as:

              $chain.results.callRestEndpoint1.status

              and $chain.results.callRestEndpoint1.detail

              • ninian1927

                I will give it a shot and report back, thanks.

                Also, I have also defined the type/variables at the application level, in my action flow I am assigning values to the application variables. However, in my flow pages when I try to output an application variable its always blank. Ive tried reviewing the documents, but is there a trick to accessing or assigning application variables? Or is the proper way to just use page variables and pass things as needed?

                • Shay Shmeltzer

                  The question is at what point are you assigning a value to this application flow variable?

                  Are you doing this in the vbEnter event of your page?

    • ninian1927
      In my button action to login in the action flow after calling the rest endpoint I added assign variable to the flow and am assigning the rest output to the application variable.
      
      Then I am moving to a new flow page but the variables aren't there
      
      • Shay Shmeltzer

        Check in the browser console that your login action actually gets to the step of assigning the variable a value - the log should also allow you to see the value that is assigned to the variable.

        • ninian1927
          Yeah, they all seem to be undefined. I'm basically trying to assign that entire response for the token request I posted above to my response type variable. It seems to work for page variables but not application. I will try digging deeper.
          
          Thanks for your responses I really appreciate it. I am really like VBCS and we are hoping to use it to build JD Edwards integrated apps.