Abdullah
Abdullah

Reputation: 21

axios.post request to Strapi backend doesn't populate data

I'm facing a problem with an axios.post request to Strapi backend in a react-native project.

I've got the strapi backend running on a local server with some basic content-types, one of which is 'Orders', i'm pasting it's definition below

Order content type

Empty fields on entry

I've also assigned the necessary permissions to both the Authenticated and Public roles, I'm able to retrieve current orders in the db with an axios.get request. It also adds an entry everytime i try to make an axios.post request with body and headers.

However, the data never comes through, I can see the entry in the Strapi portal but without the data. I'm pasting my post request code below, any reason why this might be happening?

placeOrder: async (orderState) => {
   
    await axios.post('http://192.168.10.6:1337/orders'), {
       data : {
        location : orderState.loc.toString(),
        date : orderState.dt.toString(),
        email : state.user.email,
        json : orderState.items.toString(),
      }},
      {
        "content-type": "application/json",
        'Authorization' : 'Bearer ' + state.jwt
      }
  }

Upvotes: 2

Views: 3021

Answers (1)

Alan Yong
Alan Yong

Reputation: 1033

I think your axios configuration wrong.

    await axios.post('http://192.168.10.6:1337/orders', {
      location: orderState.loc.toString(),
      date: orderState.dt.toString(),
      email: state.user.email,
      json: orderState.items.toString()
    }, {
      headers: {
        'content-type': 'application/json',
        'Authorization': 'Bearer ' + state.jwt
      }
    })

It should be axios.post(url[, data[, config]]).

You can refer to axios documentation.

Upvotes: 3

Related Questions