this post was submitted on 11 Jun 2023
4 points (100.0% liked)

Asklemmy

44151 readers
1134 users here now

A loosely moderated place to ask open-ended questions

Search asklemmy ๐Ÿ”

If your post meets the following criteria, it's welcome here!

  1. Open-ended question
  2. Not offensive: at this point, we do not have the bandwidth to moderate overtly political discussions. Assume best intent and be excellent to each other.
  3. Not regarding using or support for Lemmy: context, see the list of support communities and tools for finding communities below
  4. Not ad nauseam inducing: please make sure it is a question that would be new to most members
  5. An actual topic of discussion

Looking for support?

Looking for a community?

~Icon~ ~by~ ~@Double_[email protected]~

founded 5 years ago
MODERATORS
 

Hi I'm looking for how to make some bookmarklets to browse a few things in a different way. Is there some way to at least get a json of a post/community/user to view some info that isn't readily available on the UI?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 2 points 2 years ago* (last edited 2 years ago)

nevermind, i actually did it now 4 minutes after complaining because i saw there's code examples here:

https://github.com/LemmyNet/lemmy/blob/ecc9469a02e63eab4e19093007c7ba6db0dca079/api_tests/src/shared.ts#L4

this works:

import { GetPost, GetPostResponse, LemmyHttp, Login } from "lemmy-js-client";

export interface API {
  client: LemmyHttp;
  auth: string;
}

export let alpha: API = {
  client: new LemmyHttp("https://sh.itjust.works"),
  auth: "",
};

let formAlpha: Login = {
  username_or_email: "username",
  password: "password",
};

export async function getPost(
  api: API,
  post_id: number
): Promise<GetPostResponse> {
  let form: GetPost = {
    id: post_id,
    auth: api.auth,
  };
  return api.client.getPost(form);
}

getPost(alpha, 1).then((res) => {
  console.log(res);
});