clarkwinkelmann
i solved my problem thanks for your kindness <3
The problem was the headers.
Here a python code for to get a api token.
import requests
import json
Data = {
'identification': 'USER',
'password': 'PASS'
}
newHeaders = {'Content-type': 'application/json', "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/80.0.3987.163 Safari/537.36 "}
r = requests.post("https://EXAMPLE.COM/api/token", data=json.dumps(Data), headers=newHeaders)
print(f"Status Code: {r.status_code}, Response: {r.text}")
print(json.dumps(Data))
and also that code for the send a discussion:
import requests
import json
# Change APIKEY to the key that u have
api_key = "APIKEY"
# Change example.com to your site
forum_url = "https://EXAMPLE.COM/api/"
# In this part edit xxxTITLExxx and xxxCONTENTxxx
payload = {
"data": {
"type": "discussions",
"attributes": {
"title": "xxxTITLExxx",
"content": "xxxCONTENTxxx"
},
"relationships": {
"tags": {
"data": [
{"type": "tags", "id": "2"} # Example, 'General' tag's ID
]
}
}
}
}
headers = {
"Content-Type": "application/json",
"Authorization": "Token " + api_key,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/80.0.3987.163 Safari/537.36 "
}
# POST isteğini oluştur ve gönder
response = requests.post(forum_url + 'discussions', headers=headers, data=json.dumps(payload))
# Yanıtı kontrol et
if response.status_code == 201:
print("Succesfully posted.")
else:
print("ERROR CODE:", response.status_code)
print("ERROR MESSAGE:", response.text)