Azure SQL sp_invoke_external_rest_endpoint to APIM 401 error

Shaun 50 Reputation points
2024-01-30T23:29:28.1+00:00

I have set up a published API in APIM to query the Azure Maps API from Azure SQL.

The Maps API returns a 200 response in test in APIM

In Azure SQL, I have

  1. created the sql user from entra,
  2. granted reference on data scoped credential to the user
  3. created the database scoped credential to the url/function WITH IDENTITY = 'HTTPEndpointHeaders', secret = '{"Ocp-Apim-Subscription-Key":"**********"}'; running below:
   declare @ret int, @response nvarchar(max);
   exec @ret = sp_invoke_external_rest_endpoint 
       @url = N'https://*******-api.azure-api.net/search/search/address/json?api-version=1.0&query=15127%20NE%2024th%20Street,%20Redmond,%20WA%2098052',
       @method = 'GET', 
       @credential = [https://******-api.azure-api.net/search],
       @response = @response OUTPUT  
   
   SELECT @ret AS ReturnCode, @response AS Response;
   
   
   

i get a 401 error but the subscription key is copied and pasted from APIM / API / Test / HHTP Request pane

Suggestions on how to resolve?

Thanks

Shaun

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,446 questions
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Shaun 50 Reputation points
    2024-01-31T00:24:06.8+00:00

    figured it out, which is contrary to the documentation - you need to pass both the subscription key and the APIM subscription key from sql to APIM not just the APIM subscription key

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.