question

HisashiGoto-8203 avatar image
0 Votes"
HisashiGoto-8203 asked ·

Farmbeats: Failed to Create Device using Swagger API (Post) /Device

When I tried to crate a dvice from Swagger API .. from URL.."https://xxxfarmbeats-api.azurewebsites.net/swagger/"

I copied and paste deviceModelID from "GET /Device"...

When I tried to create a device, "POST /Device"
It returns error code 400 with error message... device model does not exist...

 {
   "message": "Device model with id 02c7801c-e91d-46dd-898e-35a4716a223a doesn't exists",
   "status": 400,
   "code": "DeviceModelIdNotFound",
   "moreInfo": null
 }

How to set Device Model ID?

--reference -Body message used for "POST /Device" ---

 {
   "deviceModelId": "02c7801c-e91d-46dd-898e-35a4716a223a",
   "hardwareId": "dummydevice001",
   "farmId": "1c43b019-42f1-420e-8db9-a3f9e7b69925",
   "reportingInterval": 300,
   "location": {
     "latitude": 38.50723,
     "longitude": -120.7948768,
     "elevation": 0
   },
   "name": "YoumustDeleteIt",
   "description": "Temporary device for Testing API please delete it"
 }

Best Regards


azure-farmbeats
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HisashiGoto-8203 avatar image
0 Votes"
HisashiGoto-8203 answered ·

Thank you for your support...

I tried to create a new device model as you suggested, "Please follow the steps here to enable partner access"...

or ...

 [POSt]  /DeviceModel
 (message body)
 {
   "type": "Node",
   "manufacturer": "HGdummyCompany",
   "productCode": "1234567900",
   "ports": [
     {
       "name": "Port0",
       "type": "Analog"
     }
   ],
   "name": "HGDUMMYDEVMODEL01",
   "description": "dummy device model"
    
 }

Then, I could get a new Model ID in response body { id: 23353149-9e3f-401b-b97b-0aa6bc0c4dca}
By using the id, I tried to create a device...

 [POST] /Device
 {message body}
 {
   "type": "Node",
   "manufacturer": "HGdummyCompany",
   "productCode": "1234567900",
   "ports": [
     {
       "name": "Port0",
       "type": "Analog"
     }
   ],
   "name": "HGDUMMYDEVMODEL01",
   "description": "dummy device model"
 }


The results are OK, I could succeeded to create a new devcie, then confirmed my device is listed in FarmBeats Dashboard..

Best Regards
Hisashi Goto




· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@HisashiGoto-8203 glad that you are now unblocked :). Could you be so kind and mark as answer so others can easily find their answer for similar issues?

Thank you and happy coding.

0 Votes 0 ·
sunayana avatar image
0 Votes"
sunayana answered ·

Hi, The DeviceModelId needs to be created by a client application which has a partner role assigned to it. Please follow the steps here to enable partner access. You can then use the credentials as mentioned in the document to create the DeviceModel, Device etc.

· 4 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

 {
   "status": "Online",
   "id": "5cddc176-fb21-4688-bcd5-35c28aa8c0f0",
   "lastTelemetryRcdAt": "2020-06-15T17:40:50.8332759Z",
   "createdAt": "2020-03-08T03:01:13.8897043Z",
   "lastModifiedAt": "2020-05-26T01:16:58.48221Z",
   "deviceModelId": "02c7801c-e91d-46dd-898e-35a4716a223a",
   "hardwareId": "TelemetryApp",
   "farmId": "1c43b019-42f1-420e-8db9-a3f9e7b69925",
   "reportingInterval": 600,
   "location": {
     "latitude": 38.50718,
     "longitude": -120.7948761,
     "elevation": 0
   },
   "name": "DemoDevice1",
   "properties": {}
 }

]

0 Votes 0 ·

Sorry but , my important message was deleted (or not uploaded) to this thread...


DeviceModelId was created as you mentioned... so I could get the information of deviceModelID by using REST API "GET /Device"...

My problem is happened when I tried to create "A device" by using existing deviceModelID...

0 Votes 0 ·

Hello @HisashiGoto-8203 , Could you please help me with the following information: 1. How did you create the Device Model? Is it programmatically or via the swagger? 2. Are you using the same client credentials to create the Device as well? 3. Are you trying to create the Device via the swagger?


The Device needs to be created using the same client credentials that is used to create the Device Model.



0 Votes 0 ·

@HisashiGoto-8203 please share the information requested so we can proceed with the troubleshooting. Otherwise, if you are now unblocked please share the answer so others can learn as well. Thanks!

0 Votes 0 ·