0
votes

I am trying to create a proof of concept with Azure APIM and am stuck at a 400 invalid hostname error.

I have tried following this example

https://docs.microsoft.com/en-gb/azure/api-management/api-management-howto-log-event-hubs

which leads me to this page

https://docs.microsoft.com/en-us/rest/api/apimanagement/2019-12-01/logger/createorupdate

I have in postman the put command with the following url, edited out the personal details

https://management.azure.com/subscriptions/xxxxx-yyyy-zzz-a4ed-b0b5ddddddd/resourceGroups/xx-Trial/providers/Microsoft.ApiManagement/service/xxx-API-Management-Services/loggers/loggerId?api-version=2019-12-01

This is being sent as a PUT command

This is the body that is also being sent

{  
 "type": "AzureEventHub",  
 "description": "xx Poc description",  
 "credentials": {  
   "name": "apim",  
   "connectionString": "Endpoint=sb://xx-poc.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yyyyyyK/ixxxxxxxxxxxxxxc="  
 }  
}  

The response that comes back is

<h2>Bad Request - Invalid Hostname</h2>
<hr>
<p>HTTP Error 400. The request hostname is invalid.</p>

I would be grateful if anyone can help me progress this forward as I cannot see what I have missed.

Thanks

2

2 Answers

1
votes

After hours of searching I finally stumbled across this url https://www.svenmalvik.com/azure-apim-with-eventhub/ which has resolve my issue.

I had done everything right in terms of setup, but this was the final step that was missing

$apimCtx = New-AzApiManagementContext -ResourceGroupName "xx-Trial" -ServiceName "xx-API-Management-Services"
$ehConnection = (Get-AzEventHubKey -ResourceGroupName "xx-Trial" -NamespaceName "xx-yyy-zzz-eh-ns" -AuthorizationRuleName "xx-yyy-zzz-eh-auth-rule").PrimaryConnectionString
New-AzApiManagementLogger -Context $apimCtx -LoggerId "simon-logger" -Name "simon-logger" -ConnectionString "$ehConnection;EntityPath=xx-yyy-eh"
0
votes

I believe there'are something wrong with the request body.

{  
 "type": "AzureEventHub",  
 "description": "xx Poc description",  
 "credentials": {  
   "name": "apim",  
   "connectionString": "Endpoint=sb://xx-poc.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yyyyyyK/ixxxxxxxxxxxxxxc="  
 }  
}

Please check the following settings in your request body:

  1. For name, please make sure it's the Event hub instance name, not the Eventhub namespace name. And you can refer to this doc for more details about them.

  2. For connectionString, please make sure it's the Eventhub namespace connectiong string(do not use the Eventhub instance level connection string). For more details, please refer to this doc.

At the end, please also check if the eventhub instance is disabled or not.