Class: PostResource
Post Comments
.addComment(postId, content, photos): Promise<Comment>
1.0.0
Adds comment to post
Parameters
| Name | Type | Description |
|---|---|---|
postId | number | Post identifier |
content | string | Comment content |
photos? | number[] | Photo IDs array |
Returns
Promise<Comment>
Created comment
Throws
If parameters are invalid
Example
javascript
await rest.posts.addComment(123, "Nice post!");
await rest.posts.addComment(123, "With photo", [456]);.deleteComment(commentId): Promise<BaseOkay>
1.0.0
Deletes a comment
Parameters
| Name | Type | Description |
|---|---|---|
commentId | number | Comment identifier |
Returns
Promise<BaseOkay>
Delete response
Throws
If comment ID is invalid
Example
javascript
await rest.posts.deleteComment(789);.getComments(postId, lastId): Promise<Comment[]>
1.0.0
Gets comments from post
Parameters
| Name | Type | Description |
|---|---|---|
postId | number | Post identifier |
lastId? | number | Last comment ID for pagination |
Returns
Promise<Comment[]>
Array of comments
Throws
If parameters are invalid
Example
javascript
const comments = await rest.posts.getComments(123);
const olderComments = await rest.posts.getComments(123, 456);Posts Core
.create(user, payload): Promise<PostModel>
1.0.0
POST /user/{user}/post
Creates a new post
Parameters
| Name | Type | Description |
|---|---|---|
user | string | number | User ({tag}/{id}/u{id}/@me) |
payload | CreatePostPayload | CreatePostPayload Post data |
Returns
Promise<PostModel>
PostModel Created post
Throws
If user or data is invalid
Example
javascript
// Text post
const post = await rest.posts.create('@me', {
content: "Hello world!"
});
// Post with photos
const postWithPhotos = await rest.posts.create('username', {
content: "Check out these photos!",
photos_list: [123, 456]
});
// Post with attachments
const postWithAttachments = await rest.posts.create(12345, {
content: "Sharing some content",
attachments: [
{ Type: "video", Item: 28 },
{ Type: "track", Item: 6422 }
]
});
// Edit existing post
const editedPost = await rest.posts.create('@me', {
content: "Updated content",
edit: 98765
});
// Repost
const repost = await rest.posts.create('@me', {
content: "Great post!",
repost: 54321
});.delete(postId): Promise<BaseOkay>
1.0.0
Deletes a post
Parameters
| Name | Type | Description |
|---|---|---|
postId | number | Post identifier |
Returns
Promise<BaseOkay>
DeletePostResponse Delete response
Throws
If post ID is invalid
Example
javascript
await rest.posts.delete(12345);.edit(postId, data): Promise<PostModel>
1.0.0
Edits a post
Parameters
| Name | Type | Description |
|---|---|---|
postId | number | Post identifier |
data | CreatePostPayload | CreatePostPayload Updated post data |
Returns
Promise<PostModel>
PostModel Updated post
Throws
If parameters are invalid
Example
javascript
const updatedPost = await rest.posts.edit(12345, {
text: "Updated content"
});.get(user, payload): Promise<PostModel[]>
1.0.0
GET /user/{user}/posts
Gets posts from user
Parameters
| Name | Type | Description |
|---|---|---|
user | string | number | User ({tag}/{id}/u{id}/@me) |
payload | GetPostPayload | GetPostPayload Get posts parameters |
Returns
Promise<PostModel[]>
Array of PostModel objects
Throws
If user is invalid
Example
javascript
const posts = await rest.posts.get('username', {});
const postsById = await rest.posts.get(12345, {});
const postsByUid = await rest.posts.get('u12345', {});
const myPosts = await rest.posts.get('@me', {});
const olderPosts = await rest.posts.get('username', { lastId: 123 });