I am trying to follow the link below for forwarding my api request to another base url, in Azure API management service, which i had created by importing apis from one azure function app.
https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-deploy-multi-region
my policies look like
<policies>
<inbound>
<base />
<choose>
<when condition="#(context.Request.OriginalUrl.Host.Contains("centralus-01.regional"))">
<set-backend-service base-url="https://apiservtmt.trafficmanager.net/api/" />
</when>
<when condition="#(context.Request.OriginalUrl.Host.Contains("southeastasia-01.regional"))">
<set-backend-service base-url="https://apiservt.trafficmanager.net/api/" />
</when>
<otherwise>
<set-backend-service base-url="https://apiservtmt.trafficmanager.net/api/" />
</otherwise>
</choose>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
but unfortunately even though i set the inbound policy to change the base url, post inbound policy is applied, the url is again getting reset to the original azure function that I had used to associate the apis with the api management.
u can see in the trace log, even after setting it to the base url of my desired choice its getting reset.
I tried every possible policy compbination, but still issue persists, please help.
api-inspector (0.322 ms)
{
"request": {
"method": "GET",
"url": "https://apiservapimt.azure-api.net/xtxs/sds/",
"headers": [
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Ocp-Apim-Subscription-Key",
"value": "*****************"
},
{
"name": "Sec-Fetch-Site",
"value": "cross-site"
},
{
"name": "X-Forwarded-For",
"value": "188888888888888"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store"
},
{
"name": "Content-Type",
"value": "text/plain;charset=UTF-8"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.9,de;q=0.8,af;q=0.7"
},
{
"name": "Host",
"value": "apiservapimt.azure-api.net"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/apimanagement/Content/1.0.574.0/apimap//apimap-apis/index.html"
}
]
}
}
api-inspector (0.003 ms)
{
"configuration": {
"api": {
"from": "/",
"to": null,
"version": null,
"revision": "1"
},
"operation": {
"method": "GET",
"uriTemplate": "/jsdhakj/{surveyId}/"
},
"user": "-",
"product": "-"
}
}
cors (0.474 ms)
"Origin header was missing or empty and the request was classified as not cross-domain. CORS policy was not applied."
choose (0.010 ms)
{
"message": "Expression was successfully evaluated.",
"expression": "context.Request.OriginalUrl.Host.Contains(\"centralus-01.regional\")",
"value": false
}
choose (0.003 ms)
{
"message": "Expression was successfully evaluated.",
"expression": "context.Request.OriginalUrl.Host.Contains(\"southeastasia-01.regional\")",
"value": false
}
set-backend-service (0.005 ms)
{
"message": "Backend service URL was changed.",
"oldBackendServiceUrl": "",
"newBackendServiceUrl": "https://apiservtmt.trafficmanager.net/api/",
"request": {
"url": "https://apiservtmt.trafficmanager.net/api/adhsakjd/sds/"
}
}
**set-backend-service (0.005 ms)
"Backend 'apiservt' set to current."**
**Backend
(668.101 ms)↑ Back to top
set-backend-service (0.030 ms)
{
"message": "Backend service URL was changed.",
"oldBackendServiceUrl": "https://apiservtmt.trafficmanager.net/api/",
"newBackendServiceUrl": "https://apiservt.azurewebsites.net/api",
"request": {
"url": "https://apiservt.azurewebsites.net/api/surveys/sds/"
}
}**
set-header (0.019 ms)
{
"message": "Specified value was assigned to the header (see below).",
"header": {
"name": "x-functions-key",
"value": "hjwjrhewj"
}
}
forward-request (0.101 ms)
{
**"message": "Request is being forwarded to the backend service. Timeout set to 300 seconds",
"request": {
"method": "GET",
"url": "https://apiservt.azurewebsites.net/api/surveys/sds/",
"headers": [**
{
"name": "Host",
"value": "apiservt.azurewebsites.net"
},
{
"name": "Request-Id",
"value": "|9ab257c67368465b904f288b38b44118.c248de116fca4824_83e3e6e7."
},
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Ocp-Apim-Subscription-Key",
"value": "wrewrwer"
},
{
"name": "Sec-Fetch-Site",
"value": "cross-site"
},
{
"name": "X-Forwarded-For",
"value": "shakjdhkjsa"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store"
},
{
"name": "Content-Type",
"value": "text/plain;charset=UTF-8"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.9,de;q=0.8,af;q=0.7"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/apimanagement/Content/1.0.574.0/apimap//apimap-apis/index.html"
},
{
"name": "Request-Context",
"value": "appId=cid-v1:552f0e64-cebd-4730-b0b8-8cf0a0fa6caf"
},
{
"name": "x-functions-key",
"value": "shdsajdhskjf"
}
]
}
}
forward-request (667.950 ms)
{
"response": {
"status": {
"code": 401,
"reason": "Unauthorized"
},
"headers": [
{
"name": "Transfer-Encoding",
"value": "chunked"
},
{
"name": "Request-Context",
"value": "appId=cid-v1:552f0e64-cebd-4730-b0b8-8cf0a0fa6caf"
},
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Date",
"value": "Tue, 24 Sep 2019 17:40:07 GMT"
}
]
}
}
Outbound
(0.146 ms)↑ Back to top
transfer-response (0.050 ms)
{
"message": "Response headers have been sent to the caller."
}
transfer-response (0.096 ms)
{
"message": "Response body streaming to the caller is complete."
}
its resolved now.
there was another set base url policy getting added at each operation level while importing the apis from the azure function. by removing these, picked the parent policy.
Related
I have been trying desperately for 5 days to create an elasticsearch watcher alert that sends a notification on an incoming webhook teams. However, the answer I receive is "Bad payload received by generic incoming webhook". I do not understand why it does not work.
{
"trigger": {
"schedule": {
"interval": "2m"
}
},
"input": {
"simple": {
"summary": "Test Nom",
"text": "test"
}
},
"condition": {
"always": {}
},
"actions": {
"MS_TEAMS_PORT443": {
"webhook": {
"scheme": "https",
"host": "outlook.office.com",
"port": 443,
"method": "post",
"path": "/webhook/XYZ",
"params": {},
"headers": {
"content-type": "application/json"
},
"body": "{{#toJson}}ctx.payload.summary{{/toJson}}"
}
}
}
}
And this is the response when I launch it:
{
"watch_id": "_inlined_",
"node": "QUApyNq4S5GyhHF-CuNjfg",
"state": "executed",
"status": {
"state": {
"active": true,
"timestamp": "2019-10-21T08:40:39.802Z"
},
"last_checked": "2019-10-21T08:40:39.802Z",
"last_met_condition": "2019-10-21T08:40:39.802Z",
"actions": {
"MS_TEAMS_PORT443": {
"ack": {
"timestamp": "2019-10-21T08:40:39.802Z",
"state": "awaits_successful_execution"
},
"last_execution": {
"timestamp": "2019-10-21T08:40:39.802Z",
"successful": false,
"reason": "received [400] status code"
}
}
},
"execution_state": "executed",
"version": -1
},
"trigger_event": {
"type": "manual",
"triggered_time": "2019-10-21T08:40:39.802Z",
"manual": {
"schedule": {
"scheduled_time": "2019-10-21T08:40:39.802Z"
}
}
},
"input": {
"simple": {
"summary": "Test Nom",
"text": "test"
}
},
"condition": {
"always": {}
},
"metadata": {
"name": "testJsonALaMano",
"xpack": {
"type": "json"
}
},
"result": {
"execution_time": "2019-10-21T08:40:39.802Z",
"execution_duration": 125,
"input": {
"type": "simple",
"status": "success",
"payload": {
"summary": "Test Nom",
"text": "test"
}
},
"condition": {
"type": "always",
"status": "success",
"met": true
},
"actions": [
{
"id": "MS_TEAMS_PORT443",
"type": "webhook",
"status": "failure",
"reason": "received [400] status code",
"webhook": {
"request": {
"host": "outlook.office.com",
"port": 443,
"scheme": "https",
"method": "post",
"path": "/webhook/XYZ",
"headers": {
"content-type": "application/json"
},
"body": "Test Nom"
},
"response": {
"status": 400,
"headers": {
"date": [
"Mon, 21 Oct 2019 08:40:38 GMT"
],
"content-length": [
"49"
],
"expires": [
"-1"
],
"x-beserver": [
"VI1PR07MB5053"
],
"x-aspnet-version": [
"4.0.30319"
],
"x-proxy-backendserverstatus": [
"400"
],
"x-cafeserver": [
"VE1PR03CA0023.EURPRD03.PROD.OUTLOOK.COM"
],
"x-calculatedbetarget": [
"VI1PR07MB5053.eurprd07.prod.outlook.com"
],
"request-id": [
"6d651f70-74b5-4010-a2a6-662666fa9985"
],
"pragma": [
"no-cache"
],
"x-msedge-ref": [
"Ref A: C6E8A3DCFF9541DD95D63FD71ACD695C Ref B: PAR02EDGE0513 Ref C: 2019-10-21T08:40:39Z"
],
"x-feserver": [
"VE1PR03CA0023"
],
"x-powered-by": [
"ASP.NET"
],
"x-backendhttpstatus": [
"400"
],
"content-type": [
"text/plain; charset=utf-8"
],
"cache-control": [
"no-cache"
]
},
"body": "Bad payload received by generic incoming webhook."
}
}
}
]
},
"messages": []
}
Wrong body statement. Need to send text in body. Change your body to be like this
"body": "{\"text\": \"{{ctx.payload.summary}}\"}"
source property is your friend here:
"body": {
"source": {
"text" : "Test Nom"
}
}
I try to process my Azure Analysis Service Cube via logic APP:
In HTTP action I have the following body:
{
"inputs": {
"method": "POST",
"uri": "https://northeurope.asazure.windows.net/servers/xxx/models/xxx/refreshes",
"body": {
"refresh": {
"objects": [
{
"database": "ModelName",
"table": "TableName"
}
],
"type": "full"
}
},
"authentication": {
"type": "ActiveDirectoryOAuth",
"authority": "https://login.windows.net",
"tenant": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"audience": "https://*.asazure.windows.net",
"clientId": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"secret": "xxxxYjxx7y5xxskHxxxxxxznxxxxxxxxODX+xxxxxxxx"
}
}
}
After runningthis logic app, I get the following error:
{
"statusCode": 400,
"headers": {
"Strict-Transport-Security": "max-age=xxxxxx00; includeSubDomains",
"x-ms-root-activity-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx",
"x-ms-current-utc-date": "2/7/2019 9:25:05 AM",
"x-ms-xmlaerror-extended": "Request parameter RefreshType is not in correct format.",
"Date": "Thu, 07 Feb 2019 09:25:05 GMT",
"Server": "Microsoft-HTTPAPI/2.0",
"Content-Length": "294",
"Content-Type": "application/json; charset=utf-8"
},
"body": {
"code": "BadRequest",
"subCode": 2,
"message": "Request parameter RefreshType is not in correct format.",
"timeStamp": "2019-02-07T09:25:05.4650388Z",
"httpStatusCode": 400,
"details": [
{
"code": "RootActivityId",
"message": "353ab74e-2793-4ee5-954f-819c851f4cb6"
},
{
"code": "Param1",
"message": "RefreshType"
}
]
}
}
Do you have any Idea, why I get this error message? and How can I solve this problem
Refresh Type is an ENUM which only takes values from below list, Can you make the type to Full and check if works:
Hope it helps.
We're using API Management to execute an always on function app that, in turn, is calling Azure Search. The function app responds within 100 ms (usually well under), but API Management intermittently takes 3 to 8 seconds to process. I've gone through the trace and found the delay is consistently in the backend step in which API Management is processing the results (sample trace for backend below). The returned data in this case is 664 bytes. Does anyone know what may cause this and, more importantly, how to remove this latency?
The Azure API Management instance, function app, and Azure Search are all in the same region.
"backend": [
{
"source": "forward-request",
"timestamp": "2018-10-11T13:33:54.0578250Z",
"elapsed": "00:00:00.0005890",
"data": {
"message": "Request is being forwarded to the backend service. Timeout set to 300 seconds",
"request": {
"method": "GET",
"url": "https://ommitted.azurewebsites.net/api/HollanderSearch/?hollander=125-222L&websiteId=1&retrieveAllProductNames=false&onlyRetrieveProductNames=true&numRecsToRetrieve =25&code=%2Fxu1iz0EimDFnOUvhDVaM4ZejfaW7umV3somaIDCeWJYI5RMIfNnNg%3D%3D&keyword=125-222L",
"headers": [
{
"name": "Ocp-Apim-Subscription-Key",
"value": "ommitted"
},
{
"name": "Postman-Token",
"value": "9e809f11-6e63-4422-8c3f-d61962cec6ac"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate"
},
{
"name": "User-Agent",
"value": "PostmanRuntime/7.3.0"
},
{
"name": "X-Forwarded-For",
"value": "omitted"
}
]
}
}
},
{
"source": "forward-request",
"timestamp": "2018-10-11T13:33:59.6717259Z",
"elapsed": "00:00:05.6045857",
"data": {
"response": {
"status": {
"code": 200,
"reason": "OK"
},
"headers": [
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Transfer-Encoding",
"value": "chunked"
},
{
"name": "Content-Encoding",
"value": "gzip"
},
{
"name": "Vary",
"value": "Accept-Encoding"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Date",
"value": "Thu, 11 Oct 2018 13:33:59 GMT"
},
{
"name": "Expires",
"value": "-1"
},
{
"name": "Set-Cookie",
"value": "ARRAffinity=8065e5ea6c0774f598f30cd38416a122cd6afe1af34a15c7f6430e1a0fe9924c;Path=/;HttpOnly;Domain=omitted-dev.azurewebsites.net"
},
{
"name": "Server",
"value": "Microsoft-IIS/10.0"
},
{
"name": "X-Powered-By",
"value": "ASP.NET"
}
]
}
}
},
{
"source": "decompressor",
"timestamp": "2018-10-11T13:33:59.6717259Z",
"elapsed": "00:00:05.6045976",
"data": "Content-Encoding header with value `gzip` detected in message headers. Content re-compression may require to correctly apply content modification policies."
}
]
I am new to node js and swagger-ui.
I want to pass below input body to my web service using swagger-ui,
I am able to pass normal json like:
{
"username":"abc",
"password":"******"
}
but I want to give following input to my web service using swagger-ui.
{
"data":
{"username":"abc",
"password":"******"
}
}
my api-docs.json file is below:
{
"info": {
"title": "Node Swagger API",
"version": "1.0.0",
"description": "Demonstrating how to describe a RESTful API with Swagger"
},
"host": "localhost:5002",
"basePath": "/",
"swagger": "2.0",
"paths": {
"/login": {
"post": {
"description": "user login",
"produces": [
"application/json"
],
"parameters": [
{
"name": "userName",
"description": "username to get userType",
"required": true,
"type": "string",
"in": "formData"
},
{
"name": "password",
"description": "password to get userType",
"required": true,
"type": "string",
"in": "formData"
}
],
"responses": {
"0": {
"description": "Access token has been expired. Please login again."
},
"200": {
"description": "Successfully returns the response"
},
"400": {
"description": "Invalid input Parameters"
},
"401": {
"description": "Invalid Access Token"
},
"404": {
"description": "No data found"
},
"500": {
"description": "Internal Server Error"
}
}
}
}
},
"definitions": {},
"responses": {},
"parameters": {},
"securityDefinitions": {},
"tags": []
}
So How can pass below input using swagger-ui to my web service:
{
"data":
{"username":"abc",
"password":"******"
}
}
Any Help will be appreciable.
Thanks In Advance.
I always use the yml format. Try this. should work. Now you will get the details in the req.body.
{
"info": {
"title": "Node Swagger API",
"version": "1.0.0",
"description": "Demonstrating how to describe a RESTful API with Swagger"
},
"host": "localhost:5002",
"basePath": "/",
"swagger": "2.0",
"paths": {
"/login": {
"post": {
"description": "user login",
"produces": [
"application/json"
],
"parameters": [
{
"name": "userDetails",
"description": "username to get userType",
"required": true,
"in": "body",
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"0": {
"description": "Access token has been expired. Please login again."
},
"200": {
"description": "Successfully returns the response"
},
"400": {
"description": "Invalid input Parameters"
},
"401": {
"description": "Invalid Access Token"
},
"404": {
"description": "No data found"
},
"500": {
"description": "Internal Server Error"
}
}
}
}
},
"definitions": {
"User" : {
"type":"object",
"properties": {
"data": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
}
}
}
}
}
},
"responses": {},
"parameters": {},
"securityDefinitions": {},
"tags": []
}
I'm newer to Swagger UI. I use swagger with Json. When the response is also Json. When clicking Try it Out, I see a correct Request URL, but the Swagger UI returns "no content" in the Response Body, and Response Code 0.
Mentioned that API's URL is not publicly accessible, but the site that hosts the Swagger UI is in the same network as the site that hosts the API.
I see this stack overflow question, but not found the solution.
My Swagger.Json file:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger for Rest API",
"description": "A sample API that uses a application as an example to demonstrate features in the swagger-2.0 specification",
"termsOfService": "http://helloreverb.com/terms/",
"contact": {
"name": "Swagger API team",
"email": "abc#gmail.com",
"url": "http://xxxx.com"
},
"license": {
"name": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
},
"host": "localhost:85xx",
"basePath": "/v1",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/test/{username}/{albumname}/{imagename}": {
"get": {
"description": "Returns all images from the system that the user has access to",
"operationId": "findface",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"name": "username",
"in": "path",
"description": "tags to filter by",
"required": true,
"type": "string"
},
{
"name": "albumname",
"in": "path",
"description": "maximum number of results to return",
"required": true,
"type": "string"
},
{
"name": "imagename",
"in": "path",
"description": "maximum number of results to return",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/test1"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/errorModel"
}
}
}
}
}
},
"definitions": {
"test1": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"errorModel": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
Please can any one help.
Thank in Advance.
It should be a CORS issue. You should add Access-Control-Allow-Origin: * into response headers.
Please refer: https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support
It should be a CORS issue. You should add Access-Control-Allow-Origin: * into response headers.
Use this code in the startup class
// global cors policy
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());