I’m looking for examples of calls to the Lemmy API… I’ve been to the following link in the documentation:

https://join-lemmy.org/docs/en/contributors/04-api.html

However I don’t see any direct examples of uses of the API for common cases, like creating a post, creating a comment or getting either type of item. Some of the linked documentation from that page points to what I believe is typescript code for interfaces, but that does not really have examples of actually calling those interfaces. I can make some logical guesses at to what the calls should be, but I don’t have a way to really verify this yet.

Does anyone have some working examples they can post?

  • Here’s another example, this time for creating a comment:

    import requests
    import json
    
    # Define the URL for the API endpoint
    url = "https://lemmy.ml/api/v1/comment"
    
    # Define the headers for the request
    headers = {'Content-Type': 'application/json'}
    
    # Define the data for the new comment
    data = {
     "content": "Your comment content",
     "post_id": 123,  # Replace with the ID of the post you're commenting on
     "form_id": "your_form_id",  # Replace with your form ID
     "auth": "your_auth_token_here"
    }
    
    # Send the POST request
    response = requests.post(url, headers=headers, data=json.dumps(data))
    
    # Print the response
    print(response.json())
    

    Does anyone know how to do the login process in Lemmy, and retrieve an auth token?