Initiating and creating a custom API request can be a complex task in an ETL process, since it often involves various configurations and parameters, such as query string parameters, request headers, and request body (if applicable). This becomes especially challenging when the process involves the extraction of authorization tokens from an initial authentication request and injecting them into subsequent HTTP requests. KingswaySoft provides an optimum solution through its SSIS Productivity Pack product, which greatly simplifies and streamlines this process. In this blog post, we will be discussing one such case, where the content of a specific session cookie needs to be drilled down and used in the request headers. Shown below are the components that we will use in this demonstration:
As mentioned, the above components are available as a part of KingswaySoft's SSIS Productivity Pack.
Understanding the Custom Access Token
Custom access tokens are typically used to obtain authorization tokens from a server, which then can be used to access resources on the server after presenting the token to it. Obtaining authorization tokens can be generally achieved by issuing a CURL command that contains the necessary information to send the authentication request to the server. This process is supported by one of the authentication modes offered in the HTTP Connection Manager, in SSIS Productivity Pack, called Custom Token.
Once you have selected the Custom Token option in the HTTP Connection Manager, you can either pull the CURL command from a file or enter it manually, as illustrated below. More details on how to work with this mode can be found in our blog post on Working with Custom Authentication Token in KingswaySoft HTTP Connection Manager.
As illustrated above, we are extracting the "Set-Cookie" header from the received response, which contains some required authentication information that can be used for subsequent requests for authentication purposes. With the configuration shown above, the "Set-Cookie" header received from the response will be saved in a variable called @Connection[AccessToken] for later use. For reference purposes, the content of the "Set-Cookie" might look like this:
AWSALB=XXXXXXXSH03CJX01YxvTp5N5pXXXXXXXXJX01YxvTp5N5p9NHIiSpBCNj6Wne8I457aAz1; Expires=Wed, 27 Sep 2023 21:11:35 GMT; Path=/,AWSALBCORS=XXXXXX010Fu2T70hOUPuXXXXXXCNj6Wne8I457aAz1; Expires=Wed, 27 Sep 2023 21:11:35 GMT; Path=/; SameSite=None; Secure,JSESSIONID=XXXXXX2FA30XXXXXC93F5F; Path=/api; Secure; HttpOnly,model.sessionId=XXXXXD4F53BFXXXXXX71B8; Path=/; Secure; HttpOnly
Our objective here is to pick up a couple of values from the "Set-Cookie" header and place them in the headers of subsequent HTTP requests.
Using the Access Token within JSON components
As mentioned, we will use the above-extracted token in a subsequent component. For this, we will be working with the JSON Source Component. We need to drag and drop a JSON Source Component and choose the Connection Manager that was just configured. In the Request headers section, add the Header name, and then click on the fx button to open the SSIS expressions editor. Switch to Expression mode. Now, here, we can use the below expression that utilizes the GetTokenAtPosition().
As illustrated above, we are extracting the JSESSIONID value from the authentication response header.
Once we have completed the expression for the value extraction, we can save it. We should now be able to find the parameters as shown below. Note that the parsed value will not show the design time but only at runtime.
After everything is ready, we can click on the Preview button, and we shall see that the value for JSESSIONID is assigned to the request header as expected. This is the result of the expression parsing out the value from the Set-Cookie token, which was previously saved in the @Connection[AccessToken].
Similarly, you could add more parameters, using similar expressions to get other headers as needed.
Conclusion
Much like the use case discussed above, the Custom Access Token method can provide a very flexible approach to working with dynamic headers and body values. In this way, the process of building a custom request becomes easier and more intuitive.
We hope this has helped!