azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

unable to import function api to apim

Open arpitmishra-eaton opened this issue 3 years ago • 9 comments

I'm trying to import a function app's apis to APIM by below command and keep getting below error:

az apim api import -g test-rg --service-name test-apim --service-url "https://test.azure-api.net/api" --path deployCD --specification-url "https://url/apinameinapim/items" --specification-format OpenApi

WARNING: Command group 'apim' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus ERROR: ValidationError: One or more fields contain incorrect values:

here i have used specification url which is publicly accessible and service url is not publicly accessible. On the other hand even if i removed the service-url as well, getting the same error.

Also i would really appreciate if you can help me to understand Specification-url and service-url. i dont want to use specificatin path and needs to automate this.

arpitmishra-eaton avatar Aug 01 '22 06:08 arpitmishra-eaton

route to CXP team

yonzhan avatar Aug 01 '22 08:08 yonzhan

@arpitmishra-eaton Thank you for reaching out to us, we will get back to you with an update.

RakeshMohanMSFT avatar Aug 01 '22 15:08 RakeshMohanMSFT

Sure, Rakesh awaiting for your response!

arpitmishra-eaton avatar Aug 01 '22 16:08 arpitmishra-eaton

@arpitmishra-eaton can you please share the debug trace log? for us troubleshoot the issue further.

RakeshMohanMSFT avatar Aug 02 '22 08:08 RakeshMohanMSFT

az apim api import -g rg-test --service-name apim-test --path deployCD --specification-url "https://test.net/api" --specification-format OpenApi --subscription-key-header-name Ocp-Apim --subscription-key-query-param-name subs-key --subscription-required true --debug DEBUG: cli.knack.cli: Command arguments: ['apim', 'api', 'import', '-g', 'rg-test', '--service-name', 'apim-test', '--path', 'deployCD', '--specification-url', 'https://resi-test.net, '--specification-format', 'OpenApi', '--subscription-key-header-name', 'Ocp-Key', '--subscription-key-query-param-name', 'subs-key', '--subscription-required', 'true', '--debug'] DEBUG: cli.knack.cli: init debug log: Cannot enable color. DEBUG: cli.knack.cli: Event: Cli.PreExecute [] DEBUG: cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x039C7100>, <function OutputProducer.on_global_arguments at 0x03A34F58>, <function CLIQuery.on_global_arguments at 0x03A59B20>] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate [] DEBUG: cli.azure.cli.core: Modules found from index for 'apim': ['azure.cli.command_modules.apim'] DEBUG: cli.azure.cli.core: Loading command modules: DEBUG: cli.azure.cli.core: Name Load Time Groups Commands DEBUG: cli.azure.cli.core: apim 0.020 9 50 DEBUG: cli.azure.cli.core: Total (1) 0.020 9 50 DEBUG: cli.azure.cli.core: Loaded 9 groups, 50 commands. DEBUG: cli.azure.cli.core: Found a match in the command table. DEBUG: cli.azure.cli.core: Raw command : apim api import DEBUG: cli.azure.cli.core: Command table: apim api import DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x03D1B808>] DEBUG: cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\E0678235.azure\commands\2022-08-02.16-32-39.apim_api_import.27744.log'. INFO: az_command_data_logger: command args: apim api import -g {} --service-name {} --path {} --specification-url {} --specification-format {} --subscription-key-header-name {} --subscription-key-query-param-name {} --subscription-required {} --debug DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x03F70F58>, <function register_global_query_examples_argument..register_query_examples at 0x03FC7148>] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x03FC7190>, <function register_cache_arguments..add_cache_arguments at 0x03FC7220>] DEBUG: cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded [] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreParseArgs [] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x03A34FA0>, <function CLIQuery.handle_query_parameter at 0x03A59B68>, <function register_global_query_examples_argument..handle_example_parameter at 0x03F71070>, <function register_ids_argument..parse_ids_arguments at 0x03FC71D8>] WARNING: Command group 'apim' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus DEBUG: cli.azure.cli.core.commands.client_factory: Getting management service client client_type=ApiManagementClient DEBUG: cli.azure.cli.core.auth.persistence: build_persistence: location='C:\Users\ap\.azure\msal_token_cache.bin', encrypt=True DEBUG: cli.azure.cli.core.auth.identity: _load_msal_http_cache: C:\Users\E0678235.azure\msal_http_cache.bin DEBUG: cli.azure.cli.core.auth.identity: __load_msal_http_cache: C:\Users\E0678235.azure\msal_http_cache.bin DEBUG: urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None) DEBUG: msal.authority: openid_config = {'token_endpoint': 'https://login.microsoftonline.com/d6525c95-b906-431a-b926-e9b51ba43cc4/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_basic'], 'jwks_uri': 'https://login.microsoftonline.com/d6525c95-b906-431a-b926-e9b51ba43cc4/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.microsoftonline.com/d6525c95-b906-431a-b926-e9b51ba43cc4/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint': 'https://login.microsoftonline.com/d6525c95-b906-431a-b926-e9b51ba43cc4/oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com/d6525c95-b906-431a-b926-e9b51ba43cc4/oauth2/v2.0/devicecode', 'http_logout_supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.microsoftonline.com/d6525c95-b906-431a-b926-e9b51ba43cc4/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.microsoftonline.com/d6525c95-b906-431a-b926-e9b51ba43cc4/kerberos', 'tenant_region_scope': 'NA', 'cloud_instance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url': 'https://pas.windows.net'} DEBUG: msrest.universal_http.requests: Configuring retry: max_retries=4, backoff_factor=0.8, max_backoff=90 DEBUG: cli.azure.cli.core.commands.client_factory: Adding custom headers to the client: DEBUG: cli.azure.cli.core.commands.client_factory: 'x-ms-client-request-id': '9f7c819d-1252-11ed-89ea-e070eab62472' DEBUG: cli.azure.cli.core.commands.client_factory: 'CommandName': 'apim api import' DEBUG: cli.azure.cli.core.commands.client_factory: 'ParameterSetName': '-g --service-name --path --specification-url --specification-format --subscription-key-header-name --subscription-key-query-param-name --subscription-required --debug' DEBUG: cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token DEBUG: cli.azure.cli.core.auth.msal_authentication: UserCredential.get_token: scopes=('https://management.core.windows.net//.default',), kwargs={} DEBUG: msal.application: Cache hit an AT DEBUG: msal.telemetry: Generate or reuse correlation_id: 5a6ef87b-bb88-404c-b293-7a41e237e3e9 DEBUG: msrest.http_logger: Request URL: 'https:/test-api-management?api-version=2019-12-01' DEBUG: msrest.http_logger: Request method: 'PUT' DEBUG: msrest.http_logger: Request headers: DEBUG: msrest.http_logger: 'Accept': 'application/json' DEBUG: msrest.http_logger: 'Content-Type': 'application/json; charset=utf-8' DEBUG: msrest.http_logger: 'accept-language': 'en-US' DEBUG: msrest.http_logger: 'Content-Length': '262' DEBUG: msrest.http_logger: 'User-Agent': 'python/3.8.9 (Windows-10-10.0.19041-SP0) msrest/0.6.21 msrest_azure/0.6.4 azure-mgmt-apimanagement/0.2.0 Azure-SDK-For-Python AZURECLI/2.32.0 (MSI)' DEBUG: msrest.http_logger: Request body: DEBUG: msrest.http_logger: {"properties": {"subscriptionKeyParameterNames": {"header": "subscription-key", "query": "Ocp-Key"}, "subscriptionRequired": true, "path": "deployCD", "value": "https://resiiot-test.net/", "format": "openapi-link"}} DEBUG: msrest.universal_http: Configuring redirects: allow=True, max=30 DEBUG: msrest.universal_http: Configuring request: timeout=100, verify=True, cert=None DEBUG: msrest.universal_http: Configuring proxies: '' DEBUG: msrest.universal_http: Evaluate proxies against ENV settings: True DEBUG: urllib3.connectionpool: Starting new HTTPS connection (1): management.azure.com:443 DEBUG: urllib3.connectionpool: https://management.azure.com:443 "PUT /subscriptions/a0c29922-4f71-4dc1-a545-bdd9cd94626a/resourceGroups/rg-test/providers/Microsoft.ApiManagement/service/apim-test/apis/72aedb0abe3a480856ac?api-version=2019-12-01 HTTP/1.1" 400 361 DEBUG: msrest.http_logger: Response status: 400 DEBUG: msrest.http_logger: Response headers: DEBUG: msrest.http_logger: 'Cache-Control': 'no-cache' DEBUG: msrest.http_logger: 'Pragma': 'no-cache' DEBUG: msrest.http_logger: 'Content-Length': '361' DEBUG: msrest.http_logger: 'Content-Type': 'application/json; charset=utf-8' DEBUG: msrest.http_logger: 'Expires': '-1' DEBUG: msrest.http_logger: 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains' DEBUG: msrest.http_logger: 'X-Content-Type-Options': 'nosniff' DEBUG: msrest.http_logger: 'x-ms-request-id': 'c25d0c94-312a-4270-a0e8-c6f7d4047d75' DEBUG: msrest.http_logger: 'Server': 'Microsoft-HTTPAPI/2.0' DEBUG: msrest.http_logger: 'x-ms-ratelimit-remaining-subscription-writes': '1198' DEBUG: msrest.http_logger: 'x-ms-correlation-request-id': 'c25d0c94-312a-4270-a0e8-c6f7d4047d75' DEBUG: msrest.http_logger: 'x-ms-routing-request-id': 'SOUTHEASTASIA:20220802T110242Z:c25d0c94-312a-4270-a0e8-c6f7d4047d75' DEBUG: msrest.http_logger: 'Date': 'Tue, 02 Aug 2022 11:02:42 GMT' DEBUG: msrest.http_logger: Response content: DEBUG: msrest.http_logger: {"error":{"code":"ValidationError","message":"One or more fields contain incorrect values:","details":[{"code":"ValidationError","target":"representation","message":"Parsing error(s): Failed to import from specified resource https://resiiot-test.net/api: The remote name could not be resolved: 'api-test.net'."}]}} DEBUG: msrest.exceptions: One or more fields contain incorrect values: DEBUG: cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception: DEBUG: cli.azure.cli.core.util: Traceback (most recent call last): File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 658, in execute File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 721, in _run_jobs_serially File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 692, in _run_job File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 328, in call File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/apim/custom.py", line 385, in import_apim_api File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 678, in sdk_no_wait File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/mgmt/apimanagement/operations/_api_operations.py", line 370, in create_or_update File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/mgmt/apimanagement/operations/_api_operations.py", line 314, in _create_or_update_initial azure.mgmt.apimanagement.models._models.ErrorResponseException: One or more fields contain incorrect values:

ERROR: cli.azure.cli.core.azclierror: ValidationError: One or more fields contain incorrect values: ERROR: az_command_data_logger: ValidationError: One or more fields contain incorrect values: DEBUG: cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x03D1B928>] INFO: az_command_data_logger: exit code: 1 INFO: cli.main: Command ran in 4.140 seconds (init: 0.502, invoke: 3.637) INFO: telemetry.save: Save telemetry record of length 3131 in cache WARNING: telemetry.check: Negative: The C:\Users\E0678235.azure\telemetry.txt was modified at 2022-08-02 16:30:39.341114, which in less than 600.000000 s DEBUG: cli.azure.cli.core.auth.identity: _dump_msal_http_cache: C:\Users\E0678235.azure\msal_http_cache.bin

arpitmishra-eaton avatar Aug 02 '22 11:08 arpitmishra-eaton

@arpitmishra-eaton Please note this section from your log. Please ensure that the resiiot-test.net is publicly accessible for apim to import the specification template

{"error":{"code":"ValidationError","message":"One or more fields contain incorrect values:","details":[{"code":"ValidationError","target":"representation","message":"Parsing error(s): Failed to import from specified resource https://resiiot-test.net/api: The remote name could not be resolved: 'api-test.net'."}]}} DEBUG: msrest.exceptions: One or more fields contain incorrect values:

RakeshMohanMSFT avatar Aug 02 '22 13:08 RakeshMohanMSFT

specification url should be apim url or function app url..? Can you please help me to understand this?

i'm following below article. in this they have manually imported function app to apim first and then generate the openAPI defination file. so this would be manual work again.. so to automate i have to use specificationurl. so here specificationurl would be of functionapp? it would be really helpful if can help me with command with example.

https://techcommunity.microsoft.com/t5/azure-paas-blog/import-azure-function-app-to-azure-api-management/ba-p/2594810

arpitmishra-eaton avatar Aug 03 '22 02:08 arpitmishra-eaton

@arpitmishra-eaton Specification url is the one which has the OpenAPI/swagger specifications of your respective API (like details of its APIs, operations, request and response body) here is an example of specification file https://conferenceapi.azurewebsites.net?format=json. In your case it must be the API Specification file of function app

image

I suggest you open a support ticket. This is forum is specifically for azure cli issues only.

RakeshMohanMSFT avatar Aug 03 '22 02:08 RakeshMohanMSFT

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

ghost avatar Aug 10 '22 08:08 ghost

Hi. Any update on this ?

gowdadiksha avatar Sep 09 '22 11:09 gowdadiksha