For quick development, you can use the registration tool provided with the Google Assistant SDK to quickly register or update a device model and instance.
If you don't want to use this tool, you can manually register or update a device using a JSON file and the REST API. You can do this on any computer. First get an access token and then skip to the appropriate section.
Get an access token
Make sure the authorization tool is up to date:
python -m pip install --upgrade google-auth-oauthlib[tool]
Obtain credentials to be able to register a new device model. Reference the JSON file you copied over to the device in a previous step.
google-oauthlib-tool --scope https://www.googleapis.com/auth/assistant-sdk-prototype \ --headless --client-secrets /path/to/client_secret_client-id.json
You should see a URL displayed in the terminal:
Please visit this URL to authorize this application: https://...
Copy the URL and paste it into a browser (this can be done on your development machine, or any other machine). After you approve, a code will appear in your browser, such as "4/XXXX". Copy and paste this code into the terminal:
Enter the authorization code:
If authorization was successful, you will see a JSON response similar to the following:
{ "scopes": ["https://www.googleapis.com/auth/assistant-sdk-prototype"], "token_uri": "https://accounts.google.com/o/oauth2/token", "token": "ya29.GlujBLa_kuXZ5GnGBPBe_A6NpczLcpOtglEC0wHVORnmEhHETzlSW", "client_id": "795595571889-6iesr9a3nkmnipbdfnqi6gehiklm2m28.apps.googleusercontent.com", "client_secret": "Un8_TNFnb55555auSAGasvAg", "refresh_token": "1/4ZMBhTR3bTYWVEMatYWLOxW755555hlQXZI5uC02F2U" }
If instead you see
UNAUTHENTICATED
, then an invalid code was entered. Try again, taking care to copy and paste the entire code.Find
token
in the JSON response. Copy this access token (not including the double quotes) into an environment variable:ACCESSTOKEN=access-token
Device model operations
Define and register the device model
Create a file (e.g.,
device_model.json
) describing the characteristics of your device model. See the device model JSON reference for more information.Register your device model using either of the following methods. Remember to substitute the
project_id
associated with the device model in the URLs below.Use the following command:
curl -s -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" -d @device_model.json \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/
- Method:
POST
- Body: Contents of
device_model.json
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token
For either method, the server should return a copy of the device model JSON that you sent. If the model already exists on the server, you will receive an
ALREADY_EXISTS
error.
Get a device model
Get a device model using either of the following methods. Remember to
substitute the project_id
and device_model_id
associated with your device model in the URLs below.
Use the following command:
curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/device_model_id
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/<device_model_id>
- Method:
GET
- Body: None
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token
List the device models
List all of your device models for a given project using either of the following methods. Remember to
substitute the project_id
associated with your device models in the URLs below.
Use the following command:
curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/
- Method:
GET
- Body: None
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token
Update the device model
Update the device model using either of the following methods. Remember to
substitute the project_id
and device_model_id
associated with your device model.
Use the following command:
curl -s -X PUT -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" -d @device_model.json \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/device_model_id
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/<device_model_id>
- Method:
PUT
- Body: Contents of
device_model.json
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token
For either method, the server should return a copy of the updated device model JSON that you sent.
Delete a device model
Delete a device model using either of the following methods. Remember to
substitute the project_id
and device_model_id
associated with your device model in the URLs below.
Use the following command:
curl -s -X DELETE -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/device_model_id
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/<device_model_id>
- Method:
DELETE
- Body: None
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token
Device instance operations
Define and register a device instance
Create a file (e.g.,
test_device.json
) that identifies your device. See the device instance JSON reference for more information.Register your device using either of the following methods. Remember to substitute the
project_id
associated with the device model in the URLs below.Use the following command:
curl -s -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" -d @test_device.json \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/devices/
- Method:
POST
- Body: Contents of
test_device.json
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token
For either method, the server should return a copy of the device instance JSON that you sent. If the instance already exists on the server, you will receive an
ALREADY_EXISTS
error.
Get a device instance
Get your device instance using either of the following methods. Remember to
substitute the project_id
associated with the device model and the device id
in the URLs below.
Use the following command:
curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/id
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/devices/<id>
- Method:
GET
- Body: None
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token
List the device instances
List all of your device instances for a given project using either of the
following methods. Remember to substitute the project_id
associated with the device instances in the URLs below.
Use the following command:
curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/devices/
- Method:
GET
- Body: None
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token
Delete a device instance
Delete your device instance using either of the following methods. Remember to
substitute the project_id
associated with the device model and the device id
in the URLs below.
Use the following command:
curl -s -X DELETE -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/id
Send an HTTPS request with the following attributes:
- URL: https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/devices/<id>
- Method:
DELETE
- Body: None
- Headers:
Authorization: Bearer <access-token>
where <access-token> is the string containing the access token