How could i use the API over the lemmy-js-client library?

I added my credentials and wanted to comment on a test post.

But when i execute client.createComment({content: text, post_id: Number(process.env.LEMMY_POST_ID), auth: “WHATTOPUTHERE?”})

FetchError: invalid json response body at https://lemmy.world/api/v3/user/login reason: Unexpected token J in JSON at position 0

I dont know if this instance “allows” api usage? or i missunderstood the api?

  • @joyjoy
    link
    English
    41 year ago

    I’m no expert, but after looking at lemmy-js-client, I think I can help.

    You need to pass your jwt token to the auth key. You can get your jwt token by calling client.login(form). It will return an object with { jwt }.

    Full example:

    const {jwt} = await client.login({
      username_or_email: "myname",
      password: "mypassword",
    });
    
    await client.createComment({
      content: text,
      post_id: Number(process.env.LEMMY_POST_ID),
      auth: jwt,
    });
    
    • @RookiOPA
      link
      English
      11 year ago

      Btw this was correct.