I have a http triggered azure function whose function key I need to populate during deployment itself. I am currently trying to get the function key using the process given here (only instead of calling the host key API I am calling the function key API /admin/functions/$functionName/keys?code=$masterKey). I am making a call to the API as soon as I upload the zipped function code to the function app using the KUDU zip API.
The issue I am facing is that while trying to set the application settings of the function app I am getting the error
Invoke-RestMethod : {"id":"643ea0b3-5ffe-4683-a8d3-62daec8c8db9","requestId":"ec5461d6-57bc-45dd-b3ac-358602cfa94c","statusCode":500,"errorCode":0,"message":" Value cannot be null.\r\nParameter name: source"}
But this works when I try it out locally. I am doubting that the function is not yet deployed when I make a REST call to get the function key and hence the error. What does the error message mean and how can I fix it?. Is it a transient issue?
UPDATE: code snippet
function get_credentials($resourceGroupName, $functionAppName){
$creds = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName `
-ResourceType Microsoft.Web/sites/config -ResourceName "$functionAppName/publishingcredentials" `
-Action list -ApiVersion 2015-08-01 -Force
$username = $creds.Properties.PublishingUserName
$password = $creds.Properties.PublishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
return $base64AuthInfo
}
function get_master_key($kuduAuthToken, $functionAppName ){
Write-Host "KUDU token is $kuduAuthToken"
$apiUrl = "https://$functionAppName.scm.azurewebsites.net/api/functions/admin/masterkey"
$result = Invoke-RestMethod -Uri $apiUrl -Headers @{"Authorization"="Basic $kuduAuthToken";"If-Match"="*"}
$masterKey = $result.masterKey
Write-Host "master key is $masterKey"
return $masterKey
}
function get_function_key($functionAppName, $functionName, $masterKey ){
$apiUrl = "https://$functionAppName.azurewebsites.net/admin/functions/$functionName/keys?code=$masterKey"
Write-Host "Calling $apiUrl"
$result = Invoke-RestMethod -Uri $apiUrl
Write-Host "Result is $result"
return $result.keys[0].value
Write-Host "host token is $result"
}
$authToken = get_credentials $resourceGroupName $functionAppName
$masterKey = get_master_key $authToken $functionAppName
get_function_key $functionAppName $purgeFunctionName $masterKey


