Gadget snap prepare-device error on pi4

Hi. I used the same code we had in 16 to register the device it’s failing here though.

root@ubuntu:/# snap change 6
Status  Spawn       Ready               Summary
Undone  2020-04-01  today at 23:18 UTC  Run prepare-device hook
Done    2020-04-01  today at 23:18 UTC  Generate device key
Error   2020-04-01  today at 23:18 UTC  Request device serial

......................................................................
Request device serial

2021-01-11T23:18:35Z ERROR cannot deliver device serial request: unexpected status 400

root@ubuntu:/# snap change 8
Status  Spawn       Ready               Summary
Undone  2020-04-01  today at 23:22 UTC  Run prepare-device hook
Done    2020-04-01  today at 23:22 UTC  Generate device key
Error   2020-04-01  today at 23:22 UTC  Request device serial

......................................................................
Request device serial

2021-01-11T23:22:36Z ERROR cannot deliver device serial request: unexpected status 400

This is the code of prepare-device:

#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

# This will need hardware-observe interface
PRODUCT_SERIAL="$(grep Serial /proc/cpuinfo | cut -d : -f 2 | tr -d '[:space:]')"
SERIAL_FILE="${SNAP_COMMON}/device-serial"

echo "product_serial:[${PRODUCT_SERIAL}]" > "${SERIAL_FILE}"
if [ "${PRODUCT_SERIAL}" ]; then
    # Optionally pass details of the device as the body of registration request,
    # the body is a YAML string.
    # This might need to be obtained dynamically
    snapctl set registration.body="serial: ${PRODUCT_SERIAL}"

    # Set the serial number of the device (needed for the serial assertion)
    snapctl set registration.proposed-serial="${PRODUCT_SERIAL}"
else
    echo "Empty product_serial"
fi

# Set the location of the Serial Vault and the API key
snapctl set device-service.url="https://serial-vault-partners.canonical.com/v1/"
snapctl set device-service.headers="xxx"

The prepare-device script is located in prebuilt/meta/hooks/prepare-device

And this is the code in the snapcraft.yaml:

parts:
  prebuilt:
    plugin: dump
    source: prebuilt

And:

hooks:
  prepare-device:
    plugs: [network, hardware-observe]

Just in case I enabled auto connect for network and hardware-observe plugs in the store.

I managed to resolve it. Quite stupid to be honest. I changed the model name to contain pi4. And we did not know that it would cause us to need another key.

I managed to find a little bit of documentation that mentioned that the key is related to the model and should be checked at some kind of web page we did not hear about (we got the key by email a long time ago).