editPost
Opens the Predis.ai post editor interface to modify existing posts. This method provides direct access to the post editing functionality, allowing users to update previously created posts.
Usage
predis.editPost({
post_id: "YOUR_POST_ID",
onPostPublish: function (err, data) {
if (err) {
console.error("Error during post publication:", err);
} else {
console.log("Post published successfully:", data);
}
},
});
Call the editPost
method inside the on("ready")
callback to ensure that the SDK is properly initialized.
The editPost
method requires user authentication via embedToken
in the initialize
method for proper user identification and post ownership validation.
Prerequisites
Before using the editPost
method, ensure that:
- The SDK has been properly initialized with both
appId
andembedToken
- The user has the necessary permissions to edit the specified post
- The
post_id
parameter corresponds to an existing post
Parameters
Name | Description | Type | Required |
---|---|---|---|
post_id | The unique identifier of the post to be edited. This ID is typically received from the API response in `post_ids` field or from the onPostPublish callback when creating a post. | String | Yes |
onPostPublish | Callback function executed when the user clicks the "Publish" button inside the editor interface. Receives error and data parameters. See onPostPublish for more details. | Function | No |
Complete Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Predis SDK - Edit Post</title>
</head>
<!-- Predis.ai SDK -->
<script
type="text/javascript"
src="https://predis.ai/sdk/embed.js"
async
defer
crossorigin="anonymous"
></script>
<body>
<button id="edit-post-button">Edit Post</button>
<script type="text/javascript">
document.getElementById("edit-post-button").addEventListener("click", function () {
try {
// Create an instance of the Predis SDK
const predis = new window.Predis();
// Handle successful initialization
predis.on("ready", () => {
console.log("SDK initialized successfully");
predis.editPost({
post_id: "YOUR_POST_ID", // Replace with actual post ID
onPostPublish: function (err, data) {
if (err) {
console.error("Error during post publication:", err);
// Handle publication error appropriately
} else {
console.log("Post published successfully:", data);
// Process the published post data
}
},
});
});
// Handle SDK errors
predis.on("error", (error) => {
console.error("SDK Error:", error);
});
// Initialize SDK with authentication
predis.initialize({
appId: "YOUR_APP_ID",
embedToken: "USER_EMBED_TOKEN" // Required for user authentication
});
} catch (error) {
console.error("Failed to initialize Predis SDK:", error);
}
});
</script>
</body>
</html>
Error Handling
The editPost
method may encounter various error scenarios:
- Invalid post_id: The specified post ID doesn't exist or is not accessible
- Authentication failure: Missing or invalid
embedToken
- Permission denied: User doesn't have edit permissions for the specified post
- Network errors: Connection issues preventing the editor from loading
Always implement proper error handling SDK error listeners to provide a seamless user experience.
Response Data
Upon successful post publication (when user clicks "Publish" in the editor), the onPostPublish
callback receives a data object.
Refer to the onPostPublish documentation for detailed information about the response structure.