GCP - Big Query using Postman

Good afternoon, I'm trying to make this request: "GET https://bigquery.googleapis.com/bigquery/v2/projects/{projectId}/datasets/{datasetId}/tables/{tableI...}" When I include the data, it gives me the following error: "{
"error": {
"code": 400,
"message": "Invalid table ID \"automatic-curve-415113.gcptestidynatracedataset.Tabla_de_prueba\".",
"errors": [
{
"message": "Invalid table ID \"automatic-curve-415113.gcptestidynatracedataset.Tabla_de_prueba\".",
"domain": "global",
"reason": "invalid"
}
],
"status": "INVALID_ARGUMENT"
}
}",

I have already checked the table data but still no response. This is the information of the table.

 

cjch1979_0-1708805042459.png

I would appreciate your help in using Postman for these requests.

1 2 572
2 REPLIES 2

It seems you're encountering a couple of distinct issues with your Google BigQuery requests through Postman. Let's address them step by step to help you resolve these problems.

Issue 1: Invalid Resource Name Error

The error message "Invalid resource name projects/{projectId}; Project id: {projectId}" suggests that there's an issue with how the project ID is being specified in your request. In Google BigQuery API calls, the project ID needs to be correctly identified to access the resources within it.

Solution:

  • Ensure that {projectId} is replaced with your actual Google Cloud project ID in the request URL. The placeholder {projectId} should be substituted with something like automatic-curve-415113 (based on your table ID information).

  • The correct format for the request should look something like https://bigquery.googleapis.com/bigquery/v2/projects/automatic-curve-415113/..., depending on the specific API endpoint you're targeting.

Issue 2: Invalid Table ID Error

The error "Invalid table ID \"automatic-curve-415113.gcptestidynatracedataset.Tabla_de_prueba\"." indicates a problem with the format of the table ID in your request.

Solution:

  • The table ID format in BigQuery is typically project_id:dataset_id.table_id. However, for API requests, this often needs to be specified as projects/projectId/datasets/datasetId/tables/tableId.

  • Ensure there are no spaces in your table ID. The error message shows a space before Tabla_de_prueba, which should not be there.

  • Correct the table ID by removing any spaces and ensuring it follows the proper format. Based on your table info, it should be something like automatic-curve-415113:gcptestidynatracedataset.Tabla_de_prueba for SQL queries, or adapted to the correct format for the specific API call you're making.

General Considerations for Using Postman with Google BigQuery

Given the issues you're facing, here are some tailored suggestions:

  • Authorization Details: Double-check your OAuth 2.0 setup in Postman to ensure it's correctly configured for accessing Google Cloud services.

  • Endpoint URL: Verify you're using the correct endpoint URL for your intended action. The BigQuery REST API documentation can provide specific endpoints for different actions (e.g., querying data, listing datasets).

  • Debugging Tips:

    • Start with a simple GET request to list datasets or tables in your project to ensure your basic setup (including authorization) is correct.

    • Carefully review the format of your table ID and project ID in your requests, as these are common sources of errors.

To use Postman with Google Cloud Platform's BigQuery service, you'll need to authenticate your requests and then interact with the BigQuery API endpoints. Here's a basic guide on how to do it:

1. **Authentication**:
- Google Cloud Platform uses OAuth 2.0 for authentication. You'll need to create a service account and obtain a private key (JSON file) associated with it.
- Go to the Google Cloud Console (https://console.cloud.google.com/) and create a service account with appropriate permissions for accessing BigQuery.
- Download the JSON key file for this service account.

2. **Set up Postman**:
- If you haven't already, download and install Postman (https://www.postman.com/downloads/).
- Launch Postman and create a new request collection for your BigQuery queries.

3. **Set up Environment Variables**:
- In Postman, create a new environment and set variables for:
- `project_id`: Your Google Cloud Platform project ID.
- `private_key`: The content of the private key JSON file.
- `client_email`: The email address associated with the service account.
- `token_url`: This should be `https://oauth2.googleapis.com/token`.
- `scope`: The scope required for accessing BigQuery, which is `https://www.googleapis.com/auth/bigquery`.

4. **Authenticating Requests**:
- Create a new request in your collection and set the HTTP method to POST.
- Set the URL to your `token_url`.
- In the Headers tab, add `Content-Type` as `application/x-www-form-urlencoded`.
- In the Body tab, select `x-www-form-urlencoded` and add the following key-value pairs:
- `grant_type`: `urn:ietf:params:oauth:grant-type:jwt-bearer`
- `assertion`: Here you'll construct a JWT token using your service account credentials. You can do this using the `pm.sendRequest` function in the Pre-request Script tab.

5. **Interacting with BigQuery API**:
- Once you have obtained the access token in the response, you can use it to authenticate your requests to the BigQuery API.
- Set the Authorization header of your subsequent requests to `Bearer {{access_token}}`, where `{{access_token}}` is the access token obtained from the previous step.
- You can now make requests to the BigQuery API endpoints (e.g., querying datasets, executing SQL queries) by sending requests to the appropriate URLs with the necessary parameters.

(URL Removed by Staff) to handle errors and ensure proper error checking in your requests. This is a basic guide to get you started, and you may need to refer to the BigQuery API documentation for specific API endpoints and request parameters based on your use case.