We have a requirement to use the OAuth2 token generated in a connect-rest and copy it in another header of the same request. The option we thought of currently is to use a data page to generate the token before calling the connect-rest and copy it in the headers. However we would like to know if we have any better solutions for this requirement.
Yes, do it inside the same connector call. Configure an OAuth 2.0 Authentication Profile on your Connect-REST so Pega automatically adds Authorization: Bearer . Then add a request Data Transform (or pre-activity) on the connector and read the already-resolved OAuth token, and set your second header there, e.g., X-Auth-Token = "Bearer " + . This avoids a separate data page call and keeps token reuse/refresh handled by the Authentication Profile cache. If you must fetch it explicitly, call the profile’s token data page/function to get pyAccessToken and map it to both headers. Parameterize the profile name via an Application Setting so test/prod switch cleanly. Finally, test by enabling DEBUG on the connector to confirm both headers are present and that refresh works on token expiry.
I believe the execution of Authentication profile or OAuth 2.0 token is generated after the execution of request data transform in a Connect-REST rule, then I dont think the token can be extracted in the request data transform.