Azure API Management returns "404 - resource not found" but endpoint testing works

Does anybody have any ideas on why PUT requests to APIM return 404 “Resource not found” but other operation types return HTTP 200?

I can use the test functionality in the APIM to call the PUT operation endpoints and I can check the console output on back-end web app and see the calls come through. However when using Postman or the a frontend web app we get the resource not found error message.

I'm really confused because, as mentioned, other verbs work fine. We generate the API endpoint definition from Swagger so it's the exact same method that's used to define the other endpoints.

Postman output:

{ "statusCode": 404, "message": "Resource not found" } 

EDIT: endpoint config

{ "openapi": "3.0.1", "info": { "title": "Foo", "description": "", "version": "1.0" }, "servers": [{ "url": "" }], "paths": { "/api/v{version}/Tasks/{taskId}/Complete": { "put": { "tags": ["Tasks"], "summary": "/api/v{version}/Tasks/{taskId}/Complete - PUT", "operationId": "put-api-v-version-tasks-taskid-complete", "parameters": [{ "name": "taskId", "in": "path", "description": "Format - int64.", "required": true, "schema": { "type": "integer" } }, { "name": "version", "in": "path", "required": true, "schema": { "type": "string" } }], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Foo.Tasks.TaskStatusRequest" } }, "text/json": { "schema": { "$ref": "#/components/schemas/Foo.Tasks.TaskStatusRequest" } }, "application/*+json": { "schema": { "$ref": "#/components/schemas/Foo.Tasks.TaskStatusRequest" } } } }, "responses": { "200": { "description": "Success" }, "400": { "description": "Bad Request", "content": { "text/plain": { "schema": { "$ref": "#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails" } }, "application/json": { "schema": { "$ref": "#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails" } }, "text/json": { "schema": { "$ref": "#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails" } } } } } } } } } 
4

1 Answer

The policies in APIM weren't set to allow PUT methods.

 <policies> <inbound> <cors allow-credentials="true"> <allowed-origins> <origin> </allowed-origins> <allowed-methods> <method>GET</method> <method>POST</method> <method>OPTIONS</method> <method>PUT</method> </allowed-methods> <allowed-headers> <header>*</header> </allowed-headers> <expose-headers> <header>*</header> </expose-headers> </cors> </inbound> <backend> <forward-request /> </backend> <outbound /> <on-error /> </policies> 

Setting <method>PUT</method> has resolved this.

The Postman query was sending a POST request not a PUT request. When we changed Postman to the proper method we got a 405 - method not allowed. That made the issue obvious.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like