跳至主要內容

API to Change Vehicle Group

DPete-1854
原始發文者

I'm using the API runner to test the entity api to change a vehicle group. I'm getting "undefined" as the result. Any suggestions? Thank you for your time and help.

 

api.call("Set", {

    "typeName": "Device",

    "entity":{

        "name":"13651",

        "id":"bB16",

        "groups":[{"id": "b27B8"}]

    }

}, function(result) {

    console.log("Done: ", result);

}, function(e) {

    console.error("Failed:", e);

});

加入對話

You need to be logged in to reply to this post and participate in the Geotab Community discussions.

2 則回覆

Hey @DPete-1854​,

 

You code looks correct, assuming the device ID and name are set properly in your parameters, this should be performing the update.

However, calling the API method Set does not return the new updated entity, hence the undefined return value. You must re-fetch the entity using a followup request using the Get method with a valid search.

 

Please note that this Set request is overriding all groups on this device, leaving the group with id: b27B8 assigned as the only group to this device. If you are simply intending to add a group, you should first Get the device, and set the entity in the Set to this device, and add your group to the existing array of group objects. Let me know if you need help with this.

 

 

DPete-1854
原始發文者

Thank you for the reply and direction, its much appreciated. My goal is to replace the existing group with the new group.

還有問題嗎?