How to make an api call where dynamically pass access token in (Get verb)

once we generate an access token using client credentials grant type (In post verb) something like this

10795-screenshot-136.png

after this in Get verb whenever client hit on another api then user got response and internally dynamically allocated to access token in header

10796-screenshot-137.png

for this this i created a proxy called as PC-Demo-1 with the verify access token(OAuth2.0) and in this proxy i passed basepath https://mocktarget.apigee.net/json

10793-screenshot-134.png

and in another api proxy i set as no target point and inside this i generated access token

10794-screenshot-135.png

and now i want i don't type access token i want whenever i hit on pc-demo-2-oauth2 api with grant type etc . and its verify and then if i hit on pc-demo-1 i got response

0 8 292
8 REPLIES 8

Not applicable

Ok, it seems you want to automate in postman.

What you can do is select one environment.

In the first api request in postman, under tests write

var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("access_token_ad", data.access_token);

this will set the access_token's value in body to environment.

In the second api

in the Authorization value place write

Basic {{access_token_ad}}

this will automatically take the value. You need not to enter manually in second api request in postman.

sir but i want like my access token is stored in a variable after this somehow in first api's header is attached with access token in header may be we can do this thing using assign message policy and Extract variable

That is a bad practice. Oauth 2.0 is know for its two legged and 3 legged nature.

If still you want then just store in cache of your app and use until it expires. This is something we have implemented.

If you want to set inside proxy, I would suggest to store in Apigee cache and use.

But if you want to do a service callout and get the token from its response and send to the backend it can be done but not a a good practice.

"But if you want to do a service callout and get the token from its response and send to the backend it can be done but not a a good practice." exactly i want this i knew it's bad practice i am exploring thing how it is work so can you suggest me how can i do this

could you please drop your mail-id

or you can reach me out there rohanjangid099@gmail.com thanks,

You need to use a service callout in proxy endpoint request. Set the required information need to be send to the token generation api. Then next to that add an extract variable policy and get the access token from the response of service callout. Next to that set an assign message policy and configure the token as Bearer token in Authorization header. Next to that oauth token validation policy will be there. All these will happen in the second proxy which gives you the service response.

sir i tried this thing but i am unable to do that if you can please email me so we can connect remotely and if it is it mean alot and thanks from heart

i am stuck in this problem last 2 days

Hi Rohan, I'm going to make a suggestion, I hope you'll accept it in the spirit it is offered. I think you need to spend a little more time learning the platform. Ask questions, sure, that's what the community is here for. But many of your questions are covered in the foundational training and learning guide for Apigee. Follow the courses, follow the training. You will be able to understand more completely and you'll make more progress. It will be more enjoyable for you and you won't have to wait for answers.

Learning Guide.