Issue with adding devices via requests/Json

Hello,
I’m currently writing a python script for bulk-provisioning MCCI Catena 4610 Boards. When I’m creating end devices with the API, Everything works fine except that the network and application layer can’t be expanded in the devices general settings. It gives me an error trying to do so that says: “An unknown error occurred. Please try again later. If the error persists, please contact support.
We’re sorry for the inconvenience.”

Also Frequency Plan, Regional Parameter version and lorawan version says “n/a”.

My code for registering devices currently looks like this:

        add_device_data = {
            "end_device": {
                "ids": {
                    "device_id": device_id,
                    "application_ids": {
                        "application_id": app_id
                    },
                    "dev_eui": deveui,
                    "join_eui": "0000000000000000"
                },
                "created_at": datetime.now().isoformat() + "Z",  
                "updated_at": datetime.now().isoformat() + "Z",  
                "name": f"Device named",
                "lorawan_version": "MAC_V1_0_3",
                "lorawan_phy_version": "RP001_V1_0_3_REV_A",
                "frequency_plan_id": "EU_863_870_TTN",  
                "attributes": {},
                "version_ids": {
                    "brand_id": "mcci",
                    "model_id": "catena4610",
                    "hardware_version": "_unknown_hw_version_",
                    "firmware_version": "0.2.0",
                    "band_id": "EU_863_870_TTN"
                    
                },
                "network_server_address": "eu1.cloud.thethings.network", 
                "application_server_address": "eu1.cloud.thethings.network",
                "join_server_address": "eu1.cloud.thethings.network",
                "supports_join": True,
                "root_keys": {
                    "app_key": {
                        "key": appkey
                },
                "mac_settings": {
                    "supports_32_bit_f_cnt": True
                },
                "formatters": {
                    "up_formatter": "FORMATTER_REPOSITORY",
                    "down_formatter": "FORMATTER_REPOSITORY"
                }
    
                },
                },
                "field_mask": {
                    "paths": [
                        "ids.device_id",
                        "ids.dev_eui",
                        "ids.join_eui",
                        "lorawan_version",
                        "lorawan_phy_version",
                        "frequency_plan_id",
                        "root_keys.app_key.key",
                        "version_ids.brand_id",
                        "version_ids.model_id",
                        "version_ids.hardware_version",
                        "version_ids.firmware_version",
                        "version_ids.band_id"
                    ]

            
            }
        }

    
        url = f"https://eu1.cloud.thethings.network/api/v3/applications/{app_id}/devices"
        try:
            response = requests.post(url, json=add_device_data, headers=headers)
            if response.status_code == 200:
                print("Devices registered successfully!")
                if x is amount-1: 
                    messagebox.showinfo("Success", "Devices Added Successfully")
                data = response.json()

            

                
            else:
                print(f"Error registering device: {response.text}")
                messagebox.showerror("Error", f"Error registering device: {response.text}")

        except requests.RequestException as e:
            print(f"An error occurred during registration: {e}")  
            messagebox.showerror("Error", f"An error occurred during registration: {e}")

Console says:

send: b'POST /api/v3/applications/testsemifinal/devices HTTP/1.1\r\nHost: eu1.cloud.thethings.network\r\nUser-Agent: python-requests/2.31.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Bearer NNSXS.QQNSHPRPR6E5PSM6ZZQIHEOB65AYALTBZFZLVRA.JSC2UE6RJRMHL5OVH44KZMS57JCUHF2Q7R7VD4EKBUORQHWQNK7A\r\nContent-Type: application/json\r\nContent-Length: 1259\r\n\r\n'
send: b'{"end_device": {"ids": {"device_id": "3c8bfe18-b6e0-4b4f-901b-9dc2419b15f5", "application_ids": {"application_id": "testsemifinal"}, "dev_eui": "198127f91f154feb", "join_eui": "0000000000000000"}, "created_at": "2024-01-26T16:30:54.607511Z", "updated_at": "2024-01-26T16:30:54.607511Z", "name": "Device named", "lorawan_version": "MAC_V1_0_3", "lorawan_phy_version": "RP001_V1_0_3_REV_A", "frequency_plan_id": "EU_863_870_TTN", "attributes": {}, "version_ids": {"brand_id": "mcci", "model_id": "catena4610", "hardware_version": "_unknown_hw_version_", "firmware_version": "0.2.0", "band_id": "EU_863_870_TTN"}, "network_server_address": "eu1.cloud.thethings.network", "application_server_address": "eu1.cloud.thethings.network", "join_server_address": "eu1.cloud.thethings.network", "supports_join": true, "root_keys": {"app_key": {"key": "f73ea92227a4d9bb219c3512e81a0c85"}, "mac_settings": {"supports_32_bit_f_cnt": true}, "formatters": {"up_formatter": "FORMATTER_REPOSITORY", "down_formatter": "FORMATTER_REPOSITORY"}}}, "field_mask": {"paths": ["ids.device_id", "ids.dev_eui", "ids.join_eui", "root_keys.app_key.key", "version_ids.brand_id", "version_ids.model_id", "version_ids.hardware_version", "version_ids.firmware_version", "version_ids.band_id"]}}'
reply: 'HTTP/1.1 200 OK\r\n'

Picture of Device not having parameters:
Missing Parameters

How did you come up with this scheme? As in where is this from?

Acutally the Code has already been written by another person. I’m the one who’s supposed to fix it…
After researching for a while my guess is that it is made out of the “End Device API Documentation” aswell as the “CSV File Reference” - Adding devices in bulk. My guess is, that it didn’t follow an instruction. When researching is saw some codes and issues that looked the same, like:
Maybe from here?

Maybe worth going back to the documentation to review what’s needed vs what you were given, as what you’ve been given doesn’t create a device properly.

The forum post you refer to has a call that produces an error, so not particularly similar. But if you re-read the opening sentence and count, you may figure a material difference between the code you’ve been given and the number of entities that are involved. Additionally, as a sub-conscious hint from the depths of your brain, you used a plural in the title but then only told us about a singular …

Well… Reading the Documentation carefully was the solution. I only sent the JSONs to the identity server. Sorry for wasting your time…

1 Like

Don’t worry about me, but do feel free to let your colleague know he put you on the spot so he doesn’t do that again!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.