This is a brief guide on how you can use Postman with Google Cloud Platform APIs, by connecting your Postman to Google using OAuth 2.0.
Create Access Token in Google Cloud Platform
Login to Google Cloud Console
In API & Services > Credentials > Create OAuth client ID
Add this under Authorized redirect URIs in your Google Console settings (https://console.cloud.google.com/apis/credentials/oauthclient).
Set your Postman with one of the following callback URI/ redirect URI to:
- Postman callback URI/ redirect_uri: https://www.getpostman.com/oauth2/callback
- Postman callback URI/ redirect_uri: https://oauth.pstmn.io/v1/callback
Please take note of the callback URI/s that you have set, as we want to later make sure it matches what we have set in Postman.
Set up Postman to use Google Cloud Platform APIs
Create a new "Authorization" in Postman.
Fill in your Authorization details and click "Get New Access Token" when you are ready.
- Type: OAuth 2.0
- Add auth data to: Request Headers
- Token name : Give the token a name, such as "GCP Token"
- Grant Type: Authorization Code
- Callback URL/ redirect_uri: Set this to one of the redirect URIs you set earlier in Google.
- Auth URL: https://accounts.google.com/o/oauth2/auth
- Access Token URL: https://accounts.google.com/o/oauth2/token
- Scope: https://www.googleapis.com/auth/cloud-platform
If you were using Google Workspace, it would be something like this (changing the scope to the API function you are using): https://www.googleapis.com/auth/apps.groups.settings - Client ID: your-specific-clientid-fromgooglecloud.apps.googleusercontent.com
- Client Secret: your-client-secret
When you click on "Get New Access Token" you will be asked to authorize Postman to interface with Google's APIs.
So it will pop up a popup window and you will be asked to log into your Google account. Log in with your Google account used to access your Google Cloud Platform.
This process will generate a OAuth ID and Google will check that the request came from an authorized redirect URL (which we have set).
You will receive an "Authentication complete" message when it is successful. Click Proceed afterwards.
Select "Use Token" to start using your new Access Token.
This will add the Access Token under "Current Token> Access token> Available Tokens" to your Postman environment.
You're all set. You can now run your Google Cloud Platform API calls.
Have fun using it now!
Example Google Cloud API call
Here is an example, using a Google Cloud Platform API call:
Google Cloud API Method: instances.list
GET https://compute.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances
where
- project = your GCP project name (which you can get from your GCP URL)
- zone = your GCP zone (which you can get from your GCP URL from your instance)
Troubleshooting:
Error 400: redirect_uri_mismatch
Error 400: redirect_uri_mismatch
You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy. \n\nIf you're the app developer, register the redirect URI in the Google Cloud Console.
Solution:
Login to Google Cloud Console
In API & Services -> Credentials create an OAuth 2.0 client ID
Add one of the following redirect URI/ callback URI under "Authorized redirect URIs" in your Google Console settings (https://console.cloud.google.com/apis/credentials/oauthclient).
That is: redirect_uri:(Optional) Google Cloud Platform - Try this API
- project = your GCP project name (which you can get from your GCP URL)
- zone = your GCP zone (which you can get from your GCP URL from your instance). This will be for example, us-central1-a, us-central1-b, etc.
It will be used to populate this Google Cloud API Method: instances.list behind the scenes in your web browser.
Google Cloud API Method: instances.list
GET https://compute.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances
You should get a Status Code: 200 if it is successful.