1
votes

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": "https://custom.domain.com"
    }],
    "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"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
1
Can u add APIM endpoint configuration to the post?Tomasz Kaniewski
I've added what I believe will work. Let me know if I need to add more detail.Damon Stamper
Also, could you specify the call you're making to APIM, please.Vitaliy Kurokhtin
I've scrubbed all but one call from the configuration. We are using /api/v{version}/Tasks/{taskId}/Complete, specifically /api/v1/Tasks/3/CompleteDamon Stamper

1 Answers

2
votes

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

    <policies>
      <inbound>
        <cors allow-credentials="true">
          <allowed-origins>
            <origin>https://URL</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.