Post url is not working

I am trying to send datas with post but I think the post url provided by strapi is not good. However, I have no problem to get datas with the same url. I tested it on Postman and I get this error :

{
    "data": null,
    "error": {
        "status": 400,
        "name": "ValidationError",
        "message": "Missing \"data\" payload in the request body",
        "details": {}
    }
}

Have you found the answer yet? I’m having the same problem and can’t seem to find any working solution.

Hello Luka,

No. Actually, my error changed.

{
  "data": null,
  "error": {
    "status": 500,
    "name": "InternalServerError",
    "message": "Internal Server Error"
  }
}

I guess the same.

You may not be facing this error anymore, but just someone encounters the error.

I am using v 4.2.0.

I followed the tutorial below and got the same error.
# Strapi.js Crash Course | Headless CMS Traversy Media

I was sending data like this as in the tutorial but got the error.

{
    "title": "Test product",
    "description": "test product description.",
    "price": 99.99,
    "qty": 20
}

Solved the error with this.

 {
     "data": {
    "title": "Test product",
    "description": "test product description.",
    "price": 99.99,
    "qty": 20
    }
}
1 Like

On strapi you have to select Body > Raw + JSON

{
  "data": {
    "title": "Hello",
    "subtitle": "Lorem Ipsum is simply dummy text of the printing and typesetting industrLorem",
    "slug": "slug",
    "targetedRaise": "990",
    "body":"Lorem Ipsum is simply dummy text of the printing and typesetting industrLorem"
  }
``
![Screenshot 2022-10-08 at 09.24.49|690x308](upload://ozx4VWPbos9UWC0w4NQfKX9wjjf.png)
1 Like

What do you mean by select body raw + JSON ?

I have the same issue with error 400, i can post with the data using post man but if i use node-fetch or axios throught my script i get the error. I copy past my console loged body and it work on postman, it drive crazy

Requires header: "Content-Type": "application/json"

Example function for entry update:

async function sendRequest(url, {arg}) {
  return fetch(url, {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({data: {...arg}}),
  });
}

Payload:
{ "data": { "name": "Test name" } }

2 Likes

I have a problem trying to insert data as well using python…mind you i am a little bit of a novice. I can connect to the application fine:

STRAPI_API_KEY = os.environ["STRAPI_API_KEY"]
STRAPI_URL_ENDPOINT = f"http://192.168.0.35:1337/api/flight-datas"
STRAPI_HEADERS = {
    "Authorization": f"Bearer {STRAPI_API_KEY}",
    "Content-Type": "application/json"
}

Then with request:

    def sheet_data_insert(self):
        """Insert data back into spreadsheet"""
        schema = {
            "data": {
                "city": "Paris",
                "iatacode": "",
                "lowestprice": "42"
            }
        }
        r = requests.post(url=STRAPI_URL_ENDPOINT, headers=self.auth_header, params=schema)
        print(r.text)

I recieve this error:

{"data":null,"error":{"status":400,"name":"ValidationError","message":"Missing \"data\" payload in the request body","details":{}}}

Anyone point me in the right direction? I clearly have a “data” payload but is params not the request body?

This is the example value from the documentation so I am a little confused:

{
  "data": {
    "city": "string",
    "iatacode": "string",
    "lowestprice": "string"
  }
}
1 Like

Okay my problem was with the

params=schema

it should be:

json=schema

:slight_smile:

Hi!, I have the same error but you can solve it change the format to send.

I used postman whit the next headers:
Content-Type | application/json
Authorization | Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjgzNjEyMzA0LCJleHAiOjE2ODYyMDQzMDR9.-5Q1iuUzu6CUc3X2bqdFgQQ2-KScbQWzGC3X2O

and the body:

{
    "data": {
        "Title": "Formateo",
        "Description": "example.",
        "Price": 200
    }
}

Greetings from Puebla :wave:

I’m facing the same error on POST request and it drives me crazy.

I added the “data” to my payload but I’m still getting the same error.

Screenshot from Postman:

GET request works fine. Any ideas?

Issue solved.

Without having the “content-type: application/json” header set in Postman, I had the same error response about having a missing “data” field (which was actually not true-- the error message simply doesn’t respond correctly if you’re missing the header).

But with the header, it worked.

I checked via the VS Code Extension “HTTP Rest Client” (which is similar to Postman), and it’s the same thing.

So, just make sure the header is set with “content-type: application/json” and you should be good to go.

e.g.: (using VS Code Extension “HTTP Rest Client” )

###
POST http://localhost:1337/api/newsletter-signups
content-type: application/json

{
    "data": { "email": "someTest123@test.com" }
}