How to move Azure sphere device to another device group using API

95504669 521 Reputation points
2022-10-28T12:13:49.893+00:00

Hi.
I have used the C# code provided in this below link to run public API's and it worked.
public-api-overview

But when I tried the move device API, it didnt work. Please let me know whether I have to make any changes for these asynchronous API's. The "MOVE" api that I tried is from the below link. I have added the json body.

https://learn.microsoft.com/en-us/rest/api/azure-sphere/devices/move

Thank you.

Azure Sphere
Azure Sphere
An Azure internet of things security solution including hardware, operating system, and cloud components.
157 questions
Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
383 questions
{count} votes

Accepted answer
  1. Alistair Lowe 191 Reputation points Microsoft Employee
    2022-12-13T18:11:00.183+00:00

    Thank you, could you try to adapt the below code instead? If this doesn't help it would also be good if you could paste your exact code minus any uniquely identifiable information.

    private async Task<string> MoveDeviceGroupAsync(string accessToken, string tenant, string deviceid, string devicegroup, CancellationToken cancellationToken)  
            {  
                using (HttpClient client = new HttpClient())  
                {  
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);  
      
       
      
                    Uri uri = new Uri(AzureSphereApiUri, String.Format("v2/tenants/{0}/devices/{1}/devicegroup", tenant, deviceid));  
      
       
      
                    using (HttpResponseMessage response = await client.PutAsync(uri, JsonContent.Create(devicegroup), cancellationToken))  
                    {  
                        response.EnsureSuccessStatusCode();  
                        return await response.Content.ReadAsStringAsync();  
                    }  
                }  
            }  
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful