API POST new content
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Post Comment</title>
</head>
<body>
<h1>Post a Comment</h1>
<button onclick="postComment()">Post Comment</button>
<div id="response"></div>
<script>
async function postComment() {
const url = '/cms/web/node?_format=json';
const data = {
"type": [
{
"target_id": "client_s_email"
}
],
"title": [
{
"value": "Sample Node Title"
}
],
"body": [
{
"value": "client@example.com"
}
]
};
const tokenUrl = '/cms/web/session/token';
const tokenResponse = await fetch(tokenUrl);
const csrfToken = await tokenResponse.text();
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken
},
body: JSON.stringify(data)
})
.then(response => response)
.then(response => {
console.log(response);
});
}
</script>
</body>
</html>
留言
發佈留言