Add AppKey via API

Hello, i’m currently trying to use a csv to add sensor to my Chirpstack LNS but i can’t post my application key using the api route “/api/devices/{deviceKeys.devEui}/keys”

the server response is “{}” so i tought it was good but when i’m going to the sensor page the application key he got is “00000000000000000000000000000000” (this make the same for all of my sensor…)

here is my code:

full_url = f"http://{url_chirpstack}/api/devices"

with open(‘data.csv’, ‘r’) as fichier:
reader = csv.reader(fichier)
for ligne in reader:
if not ligne[0]:
ligne[0] = “Untitled”

    values =  {"device": {
        "applicationId": ligne[6],
        "description": ligne[1],
        "devEui": ligne[2],
        "deviceProfileId": ligne[5],
        "isDisabled": False,
        "joinEui": ligne[3],
        "name": ligne[0],
        "skipFcntCheck": True,
    }}

    requests.post(full_url,headers=headers,json=values).json()

    full_url_key = f"http://{url_chirpstack}/api/devices/{ligne[2]}/keys"
    values2 =  {
                "deviceKeys": {
                    "appKey": ligne[4]                 
                    }
        }
    
    print(requests.post(full_url_key,headers=headers,json=values2).json())

the post do not response the informations, after you add the keys you need make get

what api rest are you using, i recomandly using the lib on pip if are you using python

https://pypi.org/project/chirpstack-api/

1 Like

Perfect, using the chirpstack lib fixed my problem!
Thank you

1 Like