1

I'm calling the SDM API using the google-api-nodesj-client package, and receiving an Enterprise not found message when I try to set the temperature.

The API returns a 404 on the nest.enterprises.devices.executeCommand call with the following error block :

message: 'Enterprise enterprises/long-enterprise-id-here not found.',
domain: 'global',
reason: 'notFound'

async function setTemp(device_name, tempFahrenheit) {

    const auth = new google.auth.GoogleAuth({
        scopes: ['https://www.googleapis.com/auth/sdm.service']
    });

    const authClient = await auth.getClient();
    const nest = await google.smartdevicemanagement(
    {
        version: 'v1',
        auth: authClient,
    });

    // Do the magic
    try {
        const res = await nest.enterprises.devices.executeCommand({
            name: device_name,
            requestBody: {
                "command" : "sdm.devices.commands.ThermostatTemperatureSetpoint.SetHeat",
                "params" : {
                    "heatCelsius" : getCelcius(tempFahrenheit)
                }
            }
        });
        console.log(res.data);
    } catch (e) {
        console.dir(e);
    }

}

I haven't found anything in the SDM documentation that alludes to this error. It feels like a GCP service account configuration issue but I can't make sense of it.

Greg
  • 2,559
  • 4
  • 28
  • 46
  • I've gone through the quick start guide linked from the Device Access Console and verified that I have access to the device. I've also verified that I can get data flowing through PubSub and hitting a GCP Function! I'm assuming I can also access the device from the API using a service account. Perhaps a bad assumption? – Greg Feb 01 '21 at 02:52
  • I've found API error documentation - https://developers.google.com/nest/device-access/reference/errors/api - and this error indicates that the Project ID is not correct. I've verified I'm passing the correct device_name here which includes the correct project ID. – Greg Feb 01 '21 at 02:58
  • Where did you get your enterprise id from? – searlea Feb 01 '21 at 23:57
  • @searlea it's the project ID in the Device Access Console. And it's also returned to me in the payload of events that get routed via PubSub – Greg Feb 03 '21 at 02:57
  • OK. It's just I've seen Enterprise ID labelled as Customer ID in some places, Organisation ID in others, but can't remember ever seeing it as Project ID. – searlea Feb 03 '21 at 11:35
  • Hey @Greg, did you figure this out? I'm in exactly the same position now. I know for a fact this API call should work because it works just fine when I use my personal account getting the oauth access token, but when I try and use the service account it is not able to see the same enterprise/project. I get a 404. – Vizzyy Oct 17 '22 at 02:17
  • @Vizzyy never did and the project is sitting unfinished. – Greg Oct 18 '22 at 14:10
  • Same issue here. Turned out I cannot do this with a service account, I need to do this with an oauth2 token. Also, the OAuth client ID should be filled into the Device Access Console at https://console.nest.google.com/device-access/ – Sam Dec 12 '22 at 22:43

0 Answers0