I have an API access to a url that looks a little like this:
curl https://api_url.com/device_groups/ -u api_key:
Which outputs in JSON:
{
"data":[
{
"type":"device_group",
"id":85015,
"attributes":{
"name":"Initial"
},
"relationships":{
"devices":{
"data":[
]
}
}
},
{
"type":"device_group",
"id":85683,
"attributes":{
"name":"mode-4"
},
"relationships":{
"devices":{
"data":[
]
}
}
},
{
"type":"device_group",
"id":85684,
"attributes":{
"name":"Employees-3"
},
"relationships":{
"devices":{
"data":[
{
"type":"device",
"id":506044
},
{
"type":"device",
"id":658670
},
{
"type":"device",
"id":506034
},
{
"type":"device",
"id":506037
},
{
"type":"device",
"id":506038
},
{
"type":"device",
"id":506046
},
{
"type":"device",
"id":506043
},
{
"type":"device",
"id":658669
},
{
"type":"device",
"id":506036
},
{
"type":"device",
"id":502256
}
]
}
}
},
{
"type":"device_group",
"id":91589,
"attributes":{
"name":"Subcontractors-2"
},
"relationships":{
"devices":{
"data":[
{
"type":"device",
"id":658668
},
{
"type":"device",
"id":658671
},
{
"type":"device",
"id":506051
},
{
"type":"device",
"id":506048
},
{
"type":"device",
"id":506040
},
{
"type":"device",
"id":506050
},
{
"type":"device",
"id":506042
},
{
"type":"device",
"id":502236
},
{
"type":"device",
"id":506041
},
{
"type":"device",
"id":523577
},
{
"type":"device",
"id":506053
},
{
"type":"device",
"id":655780
},
{
"type":"device",
"id":508070
},
{
"type":"device",
"id":506052
},
{
"type":"device",
"id":506047
},
{
"type":"device",
"id":506035
},
{
"type":"device",
"id":506045
},
{
"type":"device",
"id":506039
},
{
"type":"device",
"id":506049
},
{
"type":"device",
"id":589426
}
]
}
}
},
{
"type":"device_group",
"id":92316,
"attributes":{
"name":"Employees-2"
},
"relationships":{
"devices":{
"data":[
{
"type":"device",
"id":673452
},
{
"type":"device",
"id":576554
},
{
"type":"device",
"id":672077
},
{
"type":"device",
"id":589167
}
]
}
}
},
{
"type":"device_group",
"id":92325,
"attributes":{
"name":"Employees"
},
"relationships":{
"devices":{
"data":[
]
}
}
},
{
"type":"device_group",
"id":94908,
"attributes":{
"name":"mode 2"
},
"relationships":{
"devices":{
"data":[
{
"type":"device",
"id":501727
}
]
}
}
},
{
"type":"device_group",
"id":95017,
"attributes":{
"name":"Mode 1"
},
"relationships":{
"devices":{
"data":[
]
}
}
},
{
"type":"device_group",
"id":95381,
"attributes":{
"name":"Employees-test"
},
"relationships":{
"devices":{
"data":[
{
"type":"device",
"id":658672
}
]
}
}
},
{
"type":"device_group",
"id":95382,
"attributes":{
"name":"Subcontracters-test"
},
"relationships":{
"devices":{
"data":[
]
}
}
}
],
"has_more":false
}
I need to move each device into a predefined device group id and then return the device to their original group taken from the initial JSON curl.
eg.
curl https://api_url.com/group/$predefined_group_id/devices/506044 -u api_key: -X POST
curl https://api_url.com/group/$original_group_id/devices/506044 -u api_key: -X POST
Can you also exclude specific device_groups either by id or description as a variable?