8 Replies Latest reply on Apr 8, 2020 12:38 AM by Andre Kirsten

    How to configure a token in a Rest Web Service Consumer ?

    Falilou WAIDI Active Member

      Hi,

       

      I have an application that is using a Rest web consumer transformation.

      Before calling the base URL with the Rest web service, I generate a token that will be used for authentication.

      How do you configure the token in Informatica developer ?

      Do you create two Rest web consumer transformation ? (one for token and second for the call)

      or you can define the token when calling the Rest service ?

       

      Thanks,

      Falilou

        • 1. Re: How to configure a token in a Rest Web Service Consumer ?
          Andre Kirsten Guru

          Hi,

           

          If it is a short-lived token (e.g. valid for a couple of minutes / hours), then you should make 2 REST WSC calls.

           

          If it is a long-lived one - e.g. API key (that practically never changes) then you can add them to the header for the REST WSC directly.

           

          Kind regards,
          Andre.

          • 2. Re: How to configure a token in a Rest Web Service Consumer ?
            Falilou WAIDI Active Member

            Hi Andre,

            Thanks for the precision.

             

            The token will be valid for 2 hours.

            So I understood that I have to create 2 WSC calls.

            The first WSC is for the token. It will use the parameters "id,secret and type" and  return the "authorization id"  that I will  pass to the second WSC to get the output.

             

            But my requirement is to run it multiple time ( around 12.000 calls with differents parameters ). So can you help regarding the following questions ? :

            1. How to pass parameters to the token WSC ?

            2. How to pass the the "authorization id" to the second WSC within the same mapping ?

            3. How to do when the token has expired and no longer valid during the calls ?

             

            Thanks,

            Falilou

            • 3. Re: How to configure a token in a Rest Web Service Consumer ?
              Andre Kirsten Guru

              Hi Falilou

               

              the 2 hour lifetime might become a problem if you cannot make all the calls in that time.

               

              There is no way to "loop" inside a mapping itself.

               

              Imho, the most convenient option would be to move the authentication and actual call logic into a java transformation.

               

              There you can check for the validity of the token and to a "re-auth" (however that is provisioned by the ReST API) before proceeding with sending the requests to the endpoint.

               

              You would need to code your own client to make the calls and process the responses though.

               

              Kind regards,

               

              Andre.

              • 4. Re: How to configure a token in a Rest Web Service Consumer ?
                Falilou WAIDI Active Member

                Hi Andre,

                 

                Regarding the validity of the token, I found a way to keep it valid during the time the Rest request will be done.

                But can you help on how to pass the token value to the second WSC withing the same mapping ?

                Suppose I have a Post WSC1 that is returing the "access_token".

                How can I pass it to the second WSC that is calling the service ?

                 

                Thanks and happy new new

                Falilou

                 

                • 5. Re: How to configure a token in a Rest Web Service Consumer ?
                  Andre Kirsten Guru

                  Hi Falilou,

                   

                  Assuming that you use this as a bearer token in the 2nd call...

                   

                  - send the token to an Expression transformation (in this example, the port is called retrivievedTokenField)

                  - create a new output port
                  - set the output to 'Bearer ' || retrievedTokenField

                  (there is a space between Bearer and the first vertical bar!)

                   

                  - go to the Ports tab of the 2nd WSC
                  - make sure the Ports radio button is selected
                  - highlight the RequestInput field
                  - on the right-hand side, click on the down triangle next to the New field and select HTTP Header
                  - the header name should be Authentication, the port Name can be anything; e.g. Auth

                  In the Input mapping for the request, you can now link the generated field to the Auth port.

                   

                  This should set the Authentication Header to Bearer + the token you have retrieved.

                   

                  Kind regards,

                   

                  Andre.

                  • 6. Re: How to configure a token in a Rest Web Service Consumer ?
                    Vinita Mehta New Member

                    Hi Andre,

                     

                    I also have a requirement to read the data from the base url using API_KEY. This key is non expirable. Could you please let me know how i can do the api call in informatica. Can i use http transformation to authenticate using API_KEY. If not what is the other option i can use. I tried using web service consumer tranformation but it ask for user name and password and i dont have that , i just have api key.

                     

                    Thanks!

                    Vinita

                    • 7. Re: How to configure a token in a Rest Web Service Consumer ?
                      Akanksha Rani New Member

                      Hi Vinita,

                       

                      Depending on the implementation of the API, the key can be

                       

                      (1) sent in the query string:

                           GET /something?api_key=abcdef12345

                      (2) or as a request header:

                           GET /something HTTP/1.1

                           X-API-Key: abcdef12345

                      (3) or as a cookie:

                           GET /something HTTP/1.1

                           Cookie: X-API-KEY=abcdef12345

                       

                      For implementations (2) and (3), you can add headers to your request using Header Ports in the REST WSC Tx. Refer documentation: HTTP Header Ports.

                       

                      For implementation (1), you can pass the key with the URL.

                       

                      Kind Regards,

                      Akanksha

                      • 8. Re: How to configure a token in a Rest Web Service Consumer ?
                        Andre Kirsten Guru

                        Hi Vinita,

                        how do you send the API key in a different tool (e.g Postman / SoapUI)?
                        Is that via a HTTP header?
                        If yes, you can add custom headers to the Request.


                        In the RWSC, select Properties -> Ports -> select the Ports radiobutton

                        • Click on the RequestInput label (it should be in grey)
                        • On the right hand side, use the New dropdown and select HTTP HEADER
                        • Give it the appropriate name and hook up a port that holds the API Key.

                         

                        Kind regards,
                        Andre.