Calling Developers!
We are reenergizing our code contribution process! Learn More

What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello all, I have added a POST route to my Glue resource (check the code below) ``` public function

Options
U048WDEP3R7
U048WDEP3R7 Posts: 217 🧑🏻‍🚀 - Cadet

Hello all, I have added a POST route to my Glue resource (check the code below)

 public function configure(ResourceRouteCollectionInterface $resourceRouteCollection)
    : ResourceRouteCollectionInterface {

        // to get all pickup points
        $resourceRouteCollection->addGet('get', true);

        // to add a pickup point
        $resourceRouteCollection->addPost('post', true);

        //

        return $resourceRouteCollection;
    }

I send the following POST request to the endpoint using the PHPStorm Scratch file:

###
POST <http://glue.de.spryker.local/addax-pickup-points/>
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJmcm9udGVuZCIsImp0aSI6ImZlYjI2OWZhMGI2OTBmMGM3ODY4ZTYzMGE0YzRjOGZhZWI5YjI1ZTNlZTdiY2NjYjcxZWU5YTEzNDYwYjU2NGY4MjliNGM4ZmYzZjRiYTc3IiwiaWF0IjoxNjY4NjgxMTc1LCJuYmYiOjE2Njg2ODExNzUsImV4cCI6MTY2ODcwOTk3NSwic3ViIjoie1wiaWRfYWdlbnRcIjpudWxsLFwiY3VzdG9tZXJfcmVmZXJlbmNlXCI6XCJERS0tMTZcIixcImlkX2N1c3RvbWVyXCI6MTZ9Iiwic2NvcGVzIjpbImN1c3RvbWVyIl19.3DSGl2f4Bs30ic6prumfYbN7iGweMeWyKs9XuObVCCnwxtkxPS2H4UNcZDr3_cLbNqtLW2PaU_N5raUjCI6bhjmiT0dAc2kkW6iFq_2MVsroQDALKe_odRb_ibAAgLIjGDXsAWFbaJ3lHk7qpDCNdqMwbvny0oQkVxc90aB6CPVqWXW_Yh4Gpl-zUJTD-NFM_XxDTSJax5Qtq80t7SZzEXKuPHVN7tOO8dGxUKMavgfU6vCZTqUrlRCskB7RG8ctCR3x6XLJzOuIEBWOUvDQsE_2DyiKTz9_ZzjRiDWqxOzlH6kIrT1Eph4-kSL0aOhGDWYBeFbc3z_kRENnZg6JkQ
accept: application/json
Content-Type: application/json

{
    "data":
    {
        "idAddaxPickupPoint":"123",
        "shopName" : "Wolf Land",
        "address" : "Carl Zeiss Street 12",
        "city" : "Berlin",
        "country" : "Germany",
        "idNumber" : "123"
    }
}

But I get the following error:

<http://glue.de.spryker.local/addax-pickup-points/>

HTTP/1.1 400 Bad Request
Server: nginx
Date: Thu, 17 Nov 2022 13:41:04 GMT
Content-Type: application/vnd.api+json
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-cache, private
content-language: en_US
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: same-origin
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

{
  "errors": [
    {
      "detail": "Post data is invalid.",
      "status": 400
    }
  ]
}

Can someone please advise?

Comments

  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 🪐 - Explorer
    edited November 2022
    Options

    Request body should be in JSON:API format:

    {
        "data": {
            "type": "<your resource type>",
             "id": "<id of resource>",
             "attributes": 
        {
            "idAddaxPickupPoint":"123",
            "shopName" : "Wolf Land",
            "address" : "Carl Zeiss Street 12",
            "city" : "Berlin",
            "country" : "Germany",
            "idNumber" : "123"
        }
      }
    }
    
  • U048WDEP3R7
    U048WDEP3R7 Posts: 217 🧑🏻‍🚀 - Cadet
    Options

    @UL6DGRULR Thank you. This works.