0

I am trying to export an existing API and import using Bicep. Error I am getting is "Validation error-The field serviceUrl is invalid"

module apis_resource 'apis/deploy.bicep' = { name:'${uniqueString(deployment().name, parLocation)}-Apim-Api-0' params: { apiManagementServiceName: apiManagementService.name displayName: 'Tortue ADT API V1' name: 'TortueADTAPIV1' format:'openapi+json' value:loadTextContent('apis/TortueADTAPI.json') path:'/getTwinbyquery' subscriptionRequired:true } } 

Exported API template

{ "openapi": "3.0.1", "info": { "title": "Test API", "description": "", "version": "1.0" }, "servers": [ { "url": "https://zneetwdn11apim00.azure-api.net" } ], "paths": { "/gettwinbyquery": { "post": { "summary": "getTwinByQuery", "description": "", "operationId": "gettwinbyquery", "responses": { "200": { "description": null } } } } }, "components": { "securitySchemes": { "apiKeyHeader": { "type": "apiKey", "name": "subscriptionKey", "in": "header" }, "apiKeyQuery": { "type": "apiKey", "name": "subscriptionKey", "in": "query" } } }, "security": [ { "apiKeyHeader": [] }, { "apiKeyQuery": [] } ] } 

2 Answers 2

1

ServiceUrl is the url for backend service and I think it needs to be set, at least per this:

https://learn.microsoft.com/en-us/azure/templates/microsoft.apimanagement/service/apis?pivots=deployment-language-bicep

The code snippet leads me to think that you are using the apim module from ResourceModule repo:

https://github.com/Azure/ResourceModules/tree/main/modules/Microsoft.ApiManagement/service/apis

In that implementation the default value set for the parameter is set to empty, so I'm not exactly sure if it's supposed to work with empty value. I'm not an APIM expert, but I think the bicep implementation of an API might actually need that value to be set to something.

Sign up to request clarification or add additional context in comments.

Comments

-2

I have tried to reproduce the above issue and find the below one

1.Open azure portal and select the app you what to redeploy

2.Goto properties on the right-side search for Resource ID copy the Id and shown below enter image description here

  1. open the vs code application and create a file with .bicep extension
  2. Goto right side and click ctrl+shift+p it will open a command palette and search for Bicep: insert Resource paste the Resource ID in that as show below

enter image description here

enter image description here

AFAIK, if we give the same name, it will give an error the app name is already exist

So, We have the change the name to different places as shown below

https:// https://i.imgur.com/CAwPw5O.png

enter image description here

enter image description here

To convert from bicep to json uses below command in Azure CLI

 bicep build main.bicep 

So it will create a .json format file in the same file location

Now used the below command to deploy it again into azure portal

az deployment group create --resource-group ResourceGroupName --template-file FileName.json 

enter image description here

enter image description here

final output deployed to azure portal:

https://i.sstatic.net/1HTWN.png

1 Comment

Tarun, you got the question wrong. It is not about convering bicep to json but asking importing a json as an api def to APIM

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.