set the service endpoint
Stay organized with collections
Save and categorize content based on your preferences.
This sample demonstrates how to set an alternate endpoint when using the BigQuery client libraries.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page demonstrates how to configure an alternate endpoint when utilizing the BigQuery client libraries in both Go and Node.js.\u003c/p\u003e\n"],["\u003cp\u003eThe Go code sample illustrates the use of \u003ccode\u003ebigquery.NewClient\u003c/code\u003e with \u003ccode\u003eoption.WithEndpoint\u003c/code\u003e to set a custom endpoint.\u003c/p\u003e\n"],["\u003cp\u003eThe Node.js code sample shows how to create a BigQuery client with a specific API endpoint using the \u003ccode\u003eapiEndpoint\u003c/code\u003e configuration.\u003c/p\u003e\n"],["\u003cp\u003eBoth code samples are referencing the client libraries and require authentication by setting up Application Default Credentials.\u003c/p\u003e\n"]]],[],null,["# set the service endpoint\n\nThis sample demonstrates how to set an alternate endpoint when using the BigQuery client libraries.\n\nCode sample\n-----------\n\n### Go\n\n\nBefore trying this sample, follow the Go setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Go API\nreference documentation](https://godoc.org/cloud.google.com/go/bigquery).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n import (\n \t\"context\"\n \t\"fmt\"\n\n \t\"cloud.google.com/go/bigquery\"\n \t\"google.golang.org/api/option\"\n )\n\n // setClientEndpoint creates a bigquery.Client pointing\n // to a specific endpoint.\n func setClientEndpoint(endpoint, projectID string) (*bigquery.Client, error) {\n \t// projectID := \"my-project-id\"\n \t// endpoint := \"https://bigquery.googleapis.com/bigquery/v2/\n \tctx := context.Background()\n \tclient, err := bigquery.NewClient(ctx, projectID, option.WithEndpoint(endpoint))\n \tif err != nil {\n \t\treturn nil, fmt.Errorf(\"bigquery.NewClient: %w\", err)\n \t}\n \tdefer client.Close()\n\n \treturn client, nil\n }\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Node.js API\nreference documentation](https://googleapis.dev/nodejs/bigquery/latest/index.html).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n // Import the Google Cloud client library\n const {BigQuery} = require('https://cloud.google.com/nodejs/docs/reference/bigquery/latest/overview.html');\n\n function setClientEndpoint() {\n // Create a bigquery client pointing to a specific endpoint\n\n /**\n * TODO(developer): Uncomment the following line of code and fill in your region before running the sample.\n */\n // const region = 'my-region';\n\n const bigquery = new https://cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery.html({\n apiEndpoint: `${region}-bigquery.googleapis.com`,\n });\n\n console.log('API Endpoint:');\n console.log(bigquery.apiEndpoint);\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigquery)."]]