Symfony Api Platform 400 Not Found Error While doing default item operations with MongoDB ODM

I would like to do default item crud operations with odm. I did with ORM it was okay but I have problems with ODM.

I created project in terminal with composer

composer create-project symfony/skeleton bookshop-api

Installed the API Platform’s server component in this skeleton with

composer req api

Installed mongodb bundle with

composer req doctrine/mongodb-odm-bundle

Changed the configuration of API Platform to add the right mapping path:

    # api/config/packages/api_platform.yaml
api_platform:
    # ...

    mapping:
        paths: ['%kernel.project_dir%/src/Entity', '%kernel.project_dir%/src/Document']

    # ...

Created document folder to src and documents Offer and Product as in shown the link below:

https://api-platform.com/docs/core/mongodb/#mongodb-support

Changed env file with this:

MONGODB_URL=mongodb+srv://test123:@cluster0-woj6t.mongodb.net/test
MONGODB_DB=api

When I run it in localhost. It shows the swagger ui. The problem is when I try to post, put, any operation for offer or product it says this

{
  "@context": "/api/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "An error occurred",
  "hydra:description": "Invalid IRI "product1".",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
      "line": 417,
      "args": []
    },
    {
      "namespace": "ApiPlatformCoreSerializer",
      "short_class": "AbstractItemNormalizer",
      "class": "ApiPlatformCoreSerializerAbstractItemNormalizer",
      "type": "->",
      "function": "denormalizeRelation",
      "file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
      "line": 684,
      "args": [
        [
          "string",
          "product"
        ],
        [
          "object",
          "ApiPlatformCoreMetadataPropertyPropertyMetadata"
        ],
        [
          "string",
          "AppDocumentProduct"
        ],
        [
          "string",
          "product1"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "post"
            ],
            "api_allow_update": [
              "boolean",
              false
            ],
            "resource_class": [
              "string",
              "AppDocumentProduct"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/offers"
            ],
            "uri": [
              "string",
              "http://127.0.0.1:8000/api/offers"
            ],
            "skip_null_values": [
              "boolean",
              true
            ],
            "api_denormalize": [
              "boolean",
              true
            ],
            "cache_key": [
              "string",
              "11906de107f2fd977c81c32553e19974"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatformCoreSerializer",
      "short_class": "AbstractItemNormalizer",
      "class": "ApiPlatformCoreSerializerAbstractItemNormalizer",
      "type": "->",
      "function": "createAttributeValue",
      "file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
      "line": 347,
      "args": [
        [
          "string",
          "product"
        ],
        [
          "string",
          "product1"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "post"
            ],
            "api_allow_update": [
              "boolean",
              false
            ],
            "resource_class": [
              "string",
              "AppDocumentOffer"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/offers"
            ],
            "uri": [
              "string",
              "http://127.0.0.1:8000/api/offers"
            ],
            "skip_null_values": [
              "boolean",
              true
            ],
            "api_denormalize": [
              "boolean",
              true
            ],
            "cache_key": [
              "string",
              "11906de107f2fd977c81c32553e19974"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatformCoreSerializer",
      "short_class": "AbstractItemNormalizer",
      "class": "ApiPlatformCoreSerializerAbstractItemNormalizer",
      "type": "->",
      "function": "setAttributeValue",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
      "line": 333,
      "args": [
        [
          "object",
          "AppDocumentOffer"
        ],
        [
          "string",
          "product"
        ],
        [
          "string",
          "product1"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "post"
            ],
            "api_allow_update": [
              "boolean",
              false
            ],
            "resource_class": [
              "string",
              "AppDocumentOffer"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/offers"
            ],
            "uri": [
              "string",
              "http://127.0.0.1:8000/api/offers"
            ],
            "skip_null_values": [
              "boolean",
              true
            ],
            "api_denormalize": [
              "boolean",
              true
            ],
            "cache_key": [
              "string",
              "11906de107f2fd977c81c32553e19974"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentSerializerNormalizer",
      "short_class": "AbstractObjectNormalizer",
      "class": "SymfonyComponentSerializerNormalizerAbstractObjectNormalizer",
      "type": "->",
      "function": "denormalize",
      "file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
      "line": 222,
      "args": [
        [
          "array",
          {
            "description": [
              "string",
              "description of first offer"
            ],
            "price": [
              "integer",
              1500
            ],
            "product": [
              "string",
              "product1"
            ]
          }
        ],
        [
          "string",
          "AppDocumentOffer"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "post"
            ],
            "api_allow_update": [
              "boolean",
              false
            ],
            "resource_class": [
              "string",
              "AppDocumentOffer"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/offers"
            ],
            "uri": [
              "string",
              "http://127.0.0.1:8000/api/offers"
            ],
            "skip_null_values": [
              "boolean",
              true
            ],
            "api_denormalize": [
              "boolean",
              true
            ],
            "cache_key": [
              "string",
              "11906de107f2fd977c81c32553e19974"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatformCoreSerializer",
      "short_class": "AbstractItemNormalizer",
      "class": "ApiPlatformCoreSerializerAbstractItemNormalizer",
      "type": "->",
      "function": "denormalize",
      "file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/JsonLd/Serializer/ItemNormalizer.php",
      "line": 117,
      "args": [
        [
          "array",
          {
            "description": [
              "string",
              "description of first offer"
            ],
            "price": [
              "integer",
              1500
            ],
            "product": [
              "string",
              "product1"
            ]
          }
        ],
        [
          "string",
          "AppDocumentOffer"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "post"
            ],
            "api_allow_update": [
              "boolean",
              false
            ],
            "resource_class": [
              "string",
              "AppDocumentOffer"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/offers"
            ],
            "uri": [
              "string",
              "http://127.0.0.1:8000/api/offers"
            ],
            "skip_null_values": [
              "boolean",
              true
            ],
            "api_denormalize": [
              "boolean",
              true
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatformCoreJsonLdSerializer",
      "short_class": "ItemNormalizer",
      "class": "ApiPlatformCoreJsonLdSerializerItemNormalizer",
      "type": "->",
      "function": "denormalize",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/serializer/Serializer.php",
      "line": 185,
      "args": [
        [
          "array",
          {
            "description": [
              "string",
              "description of first offer"
            ],
            "price": [
              "integer",
              1500
            ],
            "product": [
              "string",
              "product1"
            ]
          }
        ],
        [
          "string",
          "AppDocumentOffer"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "post"
            ],
            "api_allow_update": [
              "boolean",
              false
            ],
            "resource_class": [
              "string",
              "AppDocumentOffer"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/offers"
            ],
            "uri": [
              "string",
              "http://127.0.0.1:8000/api/offers"
            ],
            "skip_null_values": [
              "boolean",
              true
            ]
          }
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentSerializer",
      "short_class": "Serializer",
      "class": "SymfonyComponentSerializerSerializer",
      "type": "->",
      "function": "denormalize",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/serializer/Serializer.php",
      "line": 136,
      "args": [
        [
          "array",
          {
            "description": [
              "string",
              "description of first offer"
            ],
            "price": [
              "integer",
              1500
            ],
            "product": [
              "string",
              "product1"
            ]
          }
        ],
        [
          "string",
          "AppDocumentOffer"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "post"
            ],
            "api_allow_update": [
              "boolean",
              false
            ],
            "resource_class": [
              "string",
              "AppDocumentOffer"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/offers"
            ],
            "uri": [
              "string",
              "http://127.0.0.1:8000/api/offers"
            ],
            "skip_null_values": [
              "boolean",
              true
            ]
          }
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentSerializer",
      "short_class": "Serializer",
      "class": "SymfonyComponentSerializerSerializer",
      "type": "->",
      "function": "deserialize",
      "file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/EventListener/DeserializeListener.php",
      "line": 106,
      "args": [
        [
          "array",
          {
            "description": [
              "string",
              "description of first offer"
            ],
            "price": [
              "integer",
              1500
            ],
            "product": [
              "string",
              "product1"
            ]
          }
        ],
        [
          "string",
          "AppDocumentOffer"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "post"
            ],
            "api_allow_update": [
              "boolean",
              false
            ],
            "resource_class": [
              "string",
              "AppDocumentOffer"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/offers"
            ],
            "uri": [
              "string",
              "http://127.0.0.1:8000/api/offers"
            ],
            "skip_null_values": [
              "boolean",
              true
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatformCoreEventListener",
      "short_class": "DeserializeListener",
      "class": "ApiPlatformCoreEventListenerDeserializeListener",
      "type": "->",
      "function": "onKernelRequest",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/event-dispatcher/EventDispatcher.php",
      "line": 270,
      "args": [
        [
          "object",
          "SymfonyComponentHttpKernelEventRequestEvent"
        ],
        [
          "string",
          "kernel.request"
        ],
        [
          "object",
          "SymfonyComponentEventDispatcherEventDispatcher"
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentEventDispatcher",
      "short_class": "EventDispatcher",
      "class": "SymfonyComponentEventDispatcherEventDispatcher",
      "type": "::",
      "function": "SymfonyComponentEventDispatcher{closure}",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/event-dispatcher/EventDispatcher.php",
      "line": 230,
      "args": [
        [
          "object",
          "SymfonyComponentHttpKernelEventRequestEvent"
        ],
        [
          "string",
          "kernel.request"
        ],
        [
          "object",
          "SymfonyComponentEventDispatcherEventDispatcher"
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentEventDispatcher",
      "short_class": "EventDispatcher",
      "class": "SymfonyComponentEventDispatcherEventDispatcher",
      "type": "->",
      "function": "callListeners",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/event-dispatcher/EventDispatcher.php",
      "line": 59,
      "args": [
        [
          "array",
          [
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ],
            [
              "object",
              "Closure"
            ]
          ]
        ],
        [
          "string",
          "kernel.request"
        ],
        [
          "object",
          "SymfonyComponentHttpKernelEventRequestEvent"
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentEventDispatcher",
      "short_class": "EventDispatcher",
      "class": "SymfonyComponentEventDispatcherEventDispatcher",
      "type": "->",
      "function": "dispatch",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 121,
      "args": [
        [
          "object",
          "SymfonyComponentHttpKernelEventRequestEvent"
        ],
        [
          "string",
          "kernel.request"
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentHttpKernel",
      "short_class": "HttpKernel",
      "class": "SymfonyComponentHttpKernelHttpKernel",
      "type": "->",
      "function": "handleRaw",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 67,
      "args": [
        [
          "object",
          "SymfonyComponentHttpFoundationRequest"
        ],
        [
          "integer",
          1
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentHttpKernel",
      "short_class": "HttpKernel",
      "class": "SymfonyComponentHttpKernelHttpKernel",
      "type": "->",
      "function": "handle",
      "file": "/Users/goksel/bookshop-api/vendor/symfony/http-kernel/Kernel.php",
      "line": 191,
      "args": [
        [
          "object",
          "SymfonyComponentHttpFoundationRequest"
        ],
        [
          "integer",
          1
        ],
        [
          "boolean",
          true
        ]
      ]
    },
    {
      "namespace": "SymfonyComponentHttpKernel",
      "short_class": "Kernel",
      "class": "SymfonyComponentHttpKernelKernel",
      "type": "->",
      "function": "handle",
      "file": "/Users/goksel/bookshop-api/public/index.php",
      "line": 25,
      "args": [
        [
          "object",
          "SymfonyComponentHttpFoundationRequest"
        ]
      ]
    }
  ]
}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *