Hi!
I'm trying to create a new page via REST API and Python.
But I'm getting error 401 'Request rejected because issuer is either not authorized or not authorized to impersonate'.
Here's my code:
import requests
import json
from requests.auth import HTTPBasicAuth
url = 'https://<my_domain>.atlassian.net/wiki/rest/api/content'
auth = HTTPBasicAuth(<my_google_email>, <my_api_token>)
headers = {
'Authorization': 'Bearer {}'.format(<my_api_token>),
'Content-Type': 'application/json',
'Accept': 'application/json',
}
data = {
'type': 'page',
'title': 'My_New_Page',
'ancestors': [{'id': 393222}],
'space': {'key': 'BDPP'},
'body': {
'storage': {
'value': 'content',
'representation': 'storage',
}
}
}
r = requests.post(url=url, data=json.dumps(data), headers=headers, auth=auth)
# Consider any status other than 2xx an error
if not r.status_code // 100 == 2:
print("Error: Unexpected response {}".format(r.text))
else:
print('Page Created: {}'.format(r))
And here https://id.atlassian.com/manage-profile/security/api-tokens I see that the token has been used.
Am I doing something wrong?