Iam trying to delete a post (by ID number) using word press Rest_api (through python). However, i keep getting this error.
{"code":"rest_no_route","message":"No route was found matching the URL and request method.","data":{"status":404}}
I have tried several methods such as:
import requests
user='admin'
password='mypassword'
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header = {'Authorization': 'Basic ' + token.decode('utf-8'),'Content-Type': 'application/json','User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
url='https://www.mywebsite.com/wp-json/wp/v2/car'
######
#method1 (Delete request)
r=requests.delete(url,headers=header,json={"id":22091})
#method 2(Get with force=True)
r=requests.get(url+'{22091}?force=True',headers=header)
I got same error for both methods.
My diagnosis is that the url I’am trying to request through the API does not accept the delete method.(as defined in mywebsite.com/wp-json/)
I’ve looked for available methods online to add the DELETE method to to the url however i only found JS code which I’am not completely familiar with and I don’t want to risk sending wrong code as I might mess up something.
Presuming my diagnosis is correct,can anyone propose a solution(preferably in python) to add the DELETE method to the url (https://www.mywebsite.com/wp-json/wp/v2/car) in my wp-json settings.
Appreciating your support on this matter.