Datastream には、プライベート接続構成、接続プロファイル、ストリームをプログラムで管理するための REST API が用意されています。REST API は、プライベート接続構成、接続プロファイル、ストリームの作成と管理に関連するリソースによって定義されます。すべてのリソースとそのメソッドの詳細については、Datastream API リファレンスをご覧ください。
Datastream REST API に直接リクエストを送信する場合、正しい形式のリクエストを作成して、認証済みユーザーとしてリクエストを承認し、返されたレスポンスを処理する必要があります。このドキュメントのタスクの多くで、cURL を使用した API の例が紹介されています。
API の使用例については、Datastream API リファレンスでリクエストのページをご覧ください。各ページには、複数のプログラミング言語で API を呼び出す例、正しい形式のリクエストの内容と、レスポンスで返されることが予想される内容を理解するのに役立つ、リクエスト固有の Explorer が含まれています。
次のいずれかの方法でインスタンスを管理する場合も、Datastream API を間接的に使用しています。
これらの方法、特に Google Cloud Console を使用するメリットは、プライベート接続構成、接続プロファイル、ストリームを(ユースケースに応じて)非常に簡単に管理できることです。Datastream をこれから使い始める場合は、REST API を直接操作する前に、まずはこれらのツールのいずれかから始めることをおすすめします。
Google Cloud には Identity and Access Management(IAM)機能があり、特定の Google Cloud リソースに対するアクセス権を詳細に設定できるため、他のリソースへの不要なアクセスを防ぐことができます。Google Cloud Console、API の IAM メソッド、Google Cloud SDK を使用して Datastream の権限を取得、設定できます。詳細については、リソースへのアクセス権の付与、変更、取り消しをご覧ください。
API の例
Datastream API と cURL をあわせて使用する例は、Datastream ドキュメントの次のページで確認できます。
オブジェクトの作成など、一部の API 呼び出しは完了するまでに時間がかかることがあります。API は非同期であるため、オペレーションがまだ進行中の場合でも、呼び出しはすぐに返されます。後続の API 呼び出しで新しく作成されたオブジェクトを使用する場合は、最初のオペレーションが完了するまで待ってから続行する必要があります。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-03 UTC。"],[[["\u003cp\u003eDatastream offers a REST API for programmatically managing private connectivity configurations, connection profiles, and streams, with the v1 version now generally available.\u003c/p\u003e\n"],["\u003cp\u003eThe Datastream API can be accessed directly via REST, or indirectly through the Google Cloud CLI or Google Cloud console, with the latter two offering simplified administration.\u003c/p\u003e\n"],["\u003cp\u003eEnabling the Datastream API is required, which can be done through the Google Cloud console or using gcloud commands, and proper IAM permissions are necessary for usage.\u003c/p\u003e\n"],["\u003cp\u003ecURL examples are available for managing various aspects such as private connectivity configurations, connection profiles, and streams, and JSON data can be securely provided via files.\u003c/p\u003e\n"],["\u003cp\u003eThe API supports asynchronous operations, requiring you to manage long-running calls, and integrates with Google APIs Discovery Service.\u003c/p\u003e\n"]]],[],null,["# Use the Datastream API\n\nDatastream provides a REST API for administering your private connectivity configurations, connection profiles, and streams programmatically. The REST API is defined by resources associated with creating and managing private connectivity configurations, connection profiles, and streams. For details about all resources and their methods, see the [Datastream API Reference](/datastream/docs/reference/rest).\n| The v1 version of the Datastream API is now generally available. If you're using the v1alpha1 version of this API, then we strongly recommend migrating to the v1 version. The v1alpha1 version will be deprecated by the end of 2022.\n\nWhen you send requests directly to the Datastream REST API, you must create the correct form of the request, authorize the request as an authenticated user, and process any responses returned. Many of the tasks in this documentation provide API examples using [cURL](http://curl.haxx.se).\n\nFor more examples of using the APIs, see the page for the request in the\n[Datastream API Reference](/datastream/docs/reference/rest). Each page has\nexamples calling the API in several programming languages, as well as a\nrequest-specific Explorer to help you see what goes into a well-formed request\nand what to expect in the response.\n\nYou're also using the Datastream API, indirectly, when you use any of the\nfollowing ways of administering instances:\n\n- [Google Cloud CLI](/sdk): A command-line interface (CLI) that you can use to work with your instances.\n\n- [Google Cloud console](https://console.cloud.google.com/): A graphical web interface.\n\nThe advantage of using these methods, especially the\nGoogle Cloud console, is that they can greatly simplify administering your\nprivate connectivity configurations, connection profiles, and streams (depending on your use case). If you're just starting out with\nDatastream, then we recommend that you start with one of these tools first\nbefore working with the REST API directly.\n\nEnable the API\n--------------\n\nTo use the Datastream API, you need to enable it: \n\n### Console\n\n1. [Enable the Datastream API](https://console.cloud.google.com/apis/enableflow?apiid=datastream.googleapis.com).\n2. Select your project.\n3. Select **Continue**.\n\n### gcloud\n\n1. Enter the following to display the project IDs for your Google Cloud projects: \n\n ```bash\n gcloud projects list\n ```\n2. Set your default project: \n\n ```bash\n gcloud config set project YOUR_PROJECT_ID\n ```\n3. Enable the Datastream API: \n\n ```bash\n gcloud services enable datastream.googleapis.com\n ```\n\nPermissions\n-----------\n\nYou must have the required permissions to use the Datastream API. These permissions include:\n\n- Datastream Admin: With this permission, a user gains access to all resources of Datastream used to manage private connectivity configurations, connection profiles, and streams.\n- Datastream Viewer: With this permission, a user has read-only access to private connectivity configurations, connection profiles, and streams in Datastream.\n\nGoogle Cloud offers Identity and Access Management (IAM), which lets you give more granular access to specific Google Cloud resources and prevents unwanted access to other resources. You can get and set permissions for Datastream using the Google Cloud Console, the IAM methods of the API, or the Google Cloud SDK. For more information, see [Granting, changing, and revoking access to resources](/iam/docs/granting-changing-revoking-access).\n\nAPI examples\n------------\n\nYou can see examples of using the Datastream API with cURL in the following pages of the Datastream documentation:\n\n- [Manage private connectivity configurations](/datastream/docs/manage-private-connectivity-configurations)\n- [Manage connection profiles](/datastream/docs/manage-connection-profiles)\n- [Manage streams](/datastream/docs/manage-streams)\n\nProvide JSON data from a file\n-----------------------------\n\nWhen you use the API with cURL, you provide property values using the command\nline. If you're working with sensitive values such as passwords or security\nkeys, then providing them on the command line poses a security risk. For increased\nsecurity, you can create a file containing the JSON data for the API call, and\nprovide the path to the file on the command line.\n\nTo provide JSON data to your cURL API call from a file:\n\n1. Create a file containing everything enclosed in single quotes for the\n `--data` field.\n\n Include the curly brackets, but don't include the single quotes.\n2. At the command line, provide the path to the file, preceded by the\n `@` character, as the `--data` parameter:\n\n ```bash\n --data @\u003cpath-to-file\u003e/\u003cfilename\u003e\n ```\n\n For example, to create a connection profile for a MySQL source, you could create a file named `request.json` with the following content: \n\n ```\n {\n \"displayName\": \"my MySQL connection profile\",\n \"mysql\": {\n \"host\": \"10.11.12.13\",\n \"port\": 3306,\n \"username\": \"myusername\",\n \"password\": \"mypassword\"\n }\n }\n ```\n\n Then, you would use the following cURL command at the command line: \n\n ```bash\n curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header 'Content-Type: application/json' \\\n --data @./request.json \\\n -X POST \\\n https://datastream.googleapis.com/v1/projects/myProject/locations/myLocation/connectionProfiles?connectionProfileId=myMySQLconnectionprofile\n ```\n\nWork with long-running API calls\n--------------------------------\n\nSome API calls, such as object creation, can take some time to complete. Because\nthe API is asynchronous, the call returns immediately, even if the operation is\nstill in progress. If a subsequent API call uses the newly created object, then you\nmust wait for the first operation to complete before proceeding.\n\nYou can use the Datastream API to [manage operations](/sdk/gcloud/reference/beta/datastream/operations). This includes:\n\n- [Showing details about an operation](/sdk/gcloud/reference/beta/datastream/operations/describe)\n- [Listing operations for a region](/sdk/gcloud/reference/beta/datastream/operations/list)\n- [Deleting an operation](/sdk/gcloud/reference/beta/datastream/operations/delete)\n\nDatastream and Google APIs Discovery Service\n--------------------------------------------\n\n[Google APIs Discovery Service](/discovery) is a service that you can use to\ndiscover Google APIs. For example, when you use the [Google APIs Explorer](/apis-explorer) tool, you're using the Discovery Service.\n\nIn the Discovery Service, Datastream is represented as \"datastream\" (for example:\nhttps://**datastream**.googleapis.com/$discovery/rest?version=v1)."]]