3

I am trying to use Azure Maps API to search POIs around a point using its coordinates, and I do not know how to call the API by adding the Authorization and client-id.

This is the request preview I get when I try the API on the Microsoft documentation website.

GET https://atlas.microsoft.com/search/poi/json?api-version=1.0&query=university&lat=10.8232&lon=2.98234&limit=1

Authorization: Bearer eyJ0eXAiOiJKV1……

X-ms-client-id: SUXrtewLVItIG3X5…..
rbrundritt
  • 16,570
  • 2
  • 21
  • 46
Farjad
  • 67
  • 1
  • 7

2 Answers2

5

There is an open source project that provides a .NET client for the Azure Maps REST services. There is a NuGet package too. You can find it here: https://github.com/perfahlen/AzureMapsRestServices The Azure Maps plans on also providing an official .NET client for the rest services later this year.

rbrundritt
  • 16,570
  • 2
  • 21
  • 46
1

You could use RestSharp. The authorization and client-id are added as header:

using RestSharp;

string url = $"https://atlas.microsoft.com/search/poi/json?api-version=1.0&query=university&lat=10.8232&lon=2.98234&limit=1";

var client = new RestClient(url);
var request = new RestRequest(Method.GET);

request.AddHeader("cache-control", "no-cache");
request.AddHeader("Authorization", “Bearer eyJ0eXAiOiJKV1……”);
request.AddHeader("X-ms-client-id", “SUXrtewLVItIG3X5…..”);

IRestResponse response = client.Execute(request);

if (response.IsSuccessful)
{
    string content = response.Content;
}

Don't forget to start by installing the RestSharp NuGet package.

Métoule
  • 13,062
  • 2
  • 56
  • 84
André
  • 108
  • 7