Register Balena API Function, how to link a device?

We have a requirement that we need to be able to create Balena Devices via the API, and then manually provision a device that points towards that before created device.

I’ve found the Balena API Function balena.models.devices.register this allows us to create a new device, with a uuid generated by us. And this works flawlessly as well. We see the device in our Fleet with the “inactive” status.

Now the problem is that i want to link a physical device towards that digital device. Since the register function returns an API key, i tried to replace the API key, in the config.json that is downloadable when creating a device via the Web UI. Unfortunately, the device is just stuck in the Splashscreen and never appears on the Dashboard.

Using the default API key, which i get when i downloaded that file from balena itself. The system provisioned successfully and also showed up in the Dashboard. The only problem is that it created a new device, with new UUID.

Maybe i’m missing something here, but can someone please give me a hint on how i can achieve what i tried to?

Appreciate any help or pointers, thanks!

1 Like

Might this be the wrong place to ask this question? Or anything else i can do to get some help?

Hi @lukasknk

Have you tried to use the 3 fields returned by the registerfunction in your configuration file?
with key being the return from register and config the config.json file:

config.deviceId = key.id;
config.uuid = key.uuid;
config.deviceApiKey = key.api_key;

Last time I tried this it worked.

Thanks for your answer! This actually works!

Appreciate the help on this