Call 2 backend endpoints from a single API proxy in Apigee

Hi Everyone, I want to use a back end REST service(for exampe the service name is SendEmail). Before my API proxy hits the target endpoint SendEmail, it needs to hit another target endpoint (for example the service name is AccessToken) to get an access token string. My API proxy will then add an "Authorization" header to contain the token string and hit the SendEmail endpoint with the original REST payload from the client request.

I'd really appreciate if someone can give me help or guide me on how to do this in a single API proxy. I'm looking for advises on the following key tasks:

- Construct a get access token REST request with JSON payload.

- Call the AccessToken endpoint and capture the token string from the response, store it some where.

- Add the "Authorization" header containing the token string to the original SendEmail request.

- Call the SendEmail endpoint.

Solved Solved
0 5 1,380
1 ACCEPTED SOLUTION

@Chung Pham you can easily achieve this by using the following policies:

  1. Construct a get access token REST request with JSON payload. - For this use an AssignMessage policy
  2. Call the AccessToken endpoint and capture the token string from the response, store it some where. - For this step use the ServiceCallout policy
  3. Add the "Authorization" header containing the token string to the original SendEmail request. - Use the set headers configuration of AssignMessage policy.
  4. Call the SendEmail endpoint. - This can be handled the normal way i.e. let the request hit the SendEmail endpoint via a TargetServer

Depending on your actual usecase you might even find this article to be helpful: https://docs.apigee.com/api-platform/security/oauth/use-third-party-oauth-system

View solution in original post

5 REPLIES 5

@Chung Pham you can easily achieve this by using the following policies:

  1. Construct a get access token REST request with JSON payload. - For this use an AssignMessage policy
  2. Call the AccessToken endpoint and capture the token string from the response, store it some where. - For this step use the ServiceCallout policy
  3. Add the "Authorization" header containing the token string to the original SendEmail request. - Use the set headers configuration of AssignMessage policy.
  4. Call the SendEmail endpoint. - This can be handled the normal way i.e. let the request hit the SendEmail endpoint via a TargetServer

Depending on your actual usecase you might even find this article to be helpful: https://docs.apigee.com/api-platform/security/oauth/use-third-party-oauth-system

Thanks so much for your response, @Cladius Fernando . It helped.

@Chung Pham I'm glad my answer was helpful. Could you please convert your "answer" to a "comment" by clicking on the gear icon next to it and selecting "Convert to Comment"? Also, could you also "accept" my answer so that others with a similar question could easily figure out the correct solution. Thanks.

Thank you, @Cladius Fernando. I've accepted your answer and converted my answer to comment. I also posted another question under the subject "How to build a dynamic target end point based on an API proxy request header value ?". Could you please help if you know the answer for that ? Thanks.

Thanks @Chung Pham. I will take a look at the other question.