# OAuth with different key and secret in one collection

**URL:** <https://community.postman.com/t/oauth-with-different-key-and-secret-in-one-collection/48935>\
**Category:** Help Hub\
**Created:** [June 26, 2023, 6:10am UTC](https://community.postman.com/t/oauth-with-different-key-and-secret-in-one-collection/48935 "2023-06-26T06:10:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranistar](https://avatars.discourse-cdn.com/v4/letter/r/eb9ed0/32.png) [@ranistar](https://community.postman.com/u/ranistar)\
**Post date:** [June 26, 2023, 6:10am UTC](https://community.postman.com/t/oauth-with-different-key-and-secret-in-one-collection/48935/1 "2023-06-26T06:10:04Z")

</div>

_My question_:  
I created a collection and several requests in it. I also wrote a script to get OAuth token. My requests are in different domain and used different OAuth credentials, my script can swith credential according the request url(domain).  
I do not want to add this script for each request, is there a way to save the script function in collection level and call it in request level?

_I’ve already tried_:  
Since the collection level pre-script is excuted before request, so I can not get the request url in this level, but I can not access the pre-script in request level…

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [June 26, 2023, 9:22am UTC](https://community.postman.com/t/oauth-with-different-key-and-secret-in-one-collection/48935/2 "2023-06-26T09:22:54Z")

</div>

This sounds like a use case for Environments.
