Created
February 8, 2024 17:04
-
-
Save angeloevangelista/ef82473515b14e00e1647b0ea207a2a2 to your computer and use it in GitHub Desktop.
Pre request script to get bitbucket api auth on postman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const requestData = { | |
grant_type: 'client_credentials', | |
client_id: pm.environment.get('bitbucket_client_id'), | |
client_secret: pm.environment.get('bitbucket_client_secret'), | |
} | |
const payload = Object | |
.entries(requestData) | |
.map(([key, value]) => `${key}=${value}`,) | |
.join('&'); | |
const preRequest = { | |
method: 'POST', | |
url: 'https://bitbucket.org/site/oauth2/access_token', | |
header: 'Content-Type: application/x-www-form-urlencoded', | |
body: { | |
mode: 'raw', | |
raw: payload, | |
} | |
}; | |
pm.sendRequest(preRequest, (err, response) => { | |
if (err) { | |
console.error('Error:', err); | |
throw err; | |
} | |
const { access_token, refresh_token } = response.json(); | |
pm.environment.set("bitbucket_auth_token", access_token); | |
pm.environment.set("bitbucket_refresh_token", refresh_token); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment