Hello everyone, i need to create a post with the WordPress Rest-API but i get an error 401 “Your userrolle has no rights to create posts.” I use the WordPress application passwort to authenticate. I created that on my admin user. Do you know what the problem could be?
<script>
const apiUrl = ‘https://page.local/wp-json/wp/v2/posts’;
const authToken = ‘fkQt z5LK Ewmk 7Sn6 UM1f A7xD’;
const postData = {
“title”:”title”,
“content”:”content”,
“status”:”publish”
};
fetch(apiUrl, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
‘Authorization’: `Bearer ${authToken}`,
},
body: JSON.stringify(postData),
})
.then(response => response.json())
.then(data => {
console.log(‘Post created successfully:’, data);
})
.catch(error => {
console.error(‘Error creating post:’, error);
});
</script>
​