Skip to content

Class: PostResource

Post Comments

.addComment(postId, content, photos): Promise<Comment> Since1.0.0

POST /posts/{post_id}/comment API Docs
Adds comment to post

Parameters

NameTypeDescription
postIdnumberPost identifier
contentstringComment 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> Since1.0.0

DELETE /comments/{comment_id} API Docs
Deletes a comment

Parameters

NameTypeDescription
commentIdnumberComment identifier

Returns

Promise<BaseOkay>

Delete response

Throws

If comment ID is invalid

Example

javascript
await rest.posts.deleteComment(789);

.getComments(postId, lastId): Promise<Comment[]> Since1.0.0

GET /posts/{post_id}/comments API Docs
Gets comments from post

Parameters

NameTypeDescription
postIdnumberPost identifier
lastId?numberLast 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> Since1.0.0

POST /user/{user}/post No API Docs
Creates a new post

Parameters

NameTypeDescription
userstring | numberUser ({tag}/{id}/u{id}/@me)
payloadCreatePostPayloadCreatePostPayload 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> Since1.0.0

DELETE /posts/{post_id} API Docs
Deletes a post

Parameters

NameTypeDescription
postIdnumberPost 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> Since1.0.0

PATCH /posts/{post_id} API Docs
Edits a post

Parameters

NameTypeDescription
postIdnumberPost identifier
dataCreatePostPayloadCreatePostPayload 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[]> Since1.0.0

GET /user/{user}/posts No API Docs
Gets posts from user

Parameters

NameTypeDescription
userstring | numberUser ({tag}/{id}/u{id}/@me)
payloadGetPostPayloadGetPostPayload 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 });