Manually Register a Device with the REST API

For quick prototyping, 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

  1. Make sure the authorization tool is up to date:

    python -m pip install --upgrade google-auth-oauthlib[tool]

  2. 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://...

  3. 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.

  4. 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

  1. Create a file (e.g., device_model.json) describing the characteristics of your device model. See the device model JSON reference for more information.

  2. 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 -k -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:

    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.

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 -k -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:

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.

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.

Device instance operations

Define and register a device instance

  1. Create a file (e.g., test_device.json) that identifies your prototype device. See the device instance JSON reference for more information.

  2. 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 -k -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:

    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 -k -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:

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 -k -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:

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 -k -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: