405 error on post request

System Information

-4.0.0

  • Operating System: Windows 10
  • Database: postgresql 8.6.0
  • Node Version: <=16.x.x
  • NPM Version: >=6.0.0
  • Yarn Version: 1.22.17

I am having trouble making a post request. I am getting a 405 Method Not Allowed error. Is there something I need to enable?


data2 = {
    'title': "A test product"
}

headers = {
    'Authorization':  f"Bearer {jwt}",
    'Content-Type': 'application/json',
}

#post new product
url = f"{strapi_server_ip_and_port}/product"
response = requests.post(url, data=json.dumps(data2), headers=headers)

I made a few changes to get it to work.


data2 = {
    'data'"{
        'title': "A test product"
    }
}

headers = {
    'Authorization':  f"Bearer {jwt}",
    'Content-Type': 'application/json',
}
#post new product

url = f"{strapi_server_url}/api/products"
print(url)
response = requests.post(url, data=json.dumps(data), headers=headers)

I had to add ‘api’ in front of products and I had to wrap the dictionary in a ‘data’ key. I also had to change ‘product’ to ‘products’