Skip Navigation

PieFed API & mobile app dev

Members
0
Posts
32
Created
1 yr. ago

Keyword Filters and Getting Blocks

There was recently a batch of newly added endpoints that I added to the API. Not everybody follows every PR in the repo, so I thought I would share them here so that more people can make use of them. Here are the new endpoints: • GET user/block/list_all - This returns a paginated list of all the different blocks that a user has. This is based on the lower portion of /user/settings/filters in the web UI. We already have endpoints to add blocks, but haven't had anywhere to fetch them for a user...until now. • GET user/filter - This returns the info for a specific keyword filter • GET user/filter/list - This returns a paginated list of a user's keyword filters • POST user/filter - This creates a new keyword filter • PUT user/filter - This edits a keyword filter • POST user/filter/delete - This deletes a keyword filter These new endpoints are live on crust. Let me know if you have any questions or requests!

Pieforhead - A python wrapper for the PieFed API

Quick links: • source repo: https://github.com/wjs018/pieforhead • docs: https://wjs018.github.io/pieforhead ——— Recently, I have been working on a client meant to consume the PieFed API in addition to the work I have done on the PieFed codebase itself. To this end, I have made a python library to interact with the PieFed API. In addition to the name, much of the big-picture organization of the code is inspired by the excellent pythorhead library that I have extensively used in the past to interact with the Lemmy API. So, hopefully using pieforhead won't be a huge lift for python developers out there and they should be able to hit the ground running. Some notable differences (other than base PieFed vs. Lemmy differences): • pieforhead uses httpx to do network requests under the hood, specifically an httpx.Client. This means that you benefit from some optimizations like connection pooling, but it means that the client should be closed when you are done with it. See the relevant docs page for more info/examples. • async is fully supported thanks to httpx. Instead of instantiating a PieFed object, use a PieFedAsync object, and all the same functions are now async. See how this can be used on the examples page of the docs. Feel free to let me know if you run into any issues!

github.com

Scheduled Posts in the API

I recently made a PR that introduced scheduled post functionality into the API. This is all now live on the crust server for testing. I wanted to make a post describing the new endpoints and bring them to the attention of app developers as early as possible to solicit feedback. The basic thought process was to create new endpoints for scheduled posts because the schema was sufficiently different than the schema used for existing post endpoints, as well as it will make our development lives easier on the backend. There are five new endpoints introduced with this that mirror the primary endpoints for doing basic post actions...

New Endpoints

1. GET /post/scheduled - return the information for a single scheduled post from a given post id. Similar to GET /post 2. GET /post/scheduled/list - return a list of the user's scheduled posts. Similar to GET /post/list, but obviously much more constrained in scope. 3. POST /post/scheduled - create a new scheduled post. Similar to POST /post. 4. PUT /post/scheduled - edit an existing scheduled post. Similar to PUT /post. 5. POST /post/scheduled/delete - delete or restore a scheduled post. Similar to POST /post/delete. You can check out the schema on crust's swagger page. Also feel free to do testing over on crust and let me know of any issues that come up. The easiest time to make changes is now, before this makes its way into a stable release.

Emoji reactions in the PieFed API

PieFed v1.4 (to be released very soon) will have emoji reactions on posts and comments. An emoji reaction can be a unicode character like 😍 or a colon-delineated string like :piefed: which gets automatically converted into an image when the post/comment is displayed. Setting a reaction uses the same API endpoint as casting a vote (and behind the scenes reactions are federated as Likes, for Lemmy compatibility) but with an emoji element added to the JSON payload. image Also when looking at a post or comment in the API there is an emoji_reactions element that can be used to get a summary of the reactions that have happened so far. Compare https://crust.piefed.social/api/alpha/comment?id=456791 with https://crust.piefed.social/post/84566#comment_456791 to see what I mean. Do a GET on /api/v3/site to retrieve a list of all the custom emoji (the ones with :something:) that this instance knows about and to find what images to convert usages of them in emoji_reactions to.

Endpoint to get metadata about a url

/api/alpha/post/site_metadata e.g. https://crust.piefed.social/api/alpha/post/site_metadata?url=https://edition.cnn.com/2025/12/02/politics/second-strike-drug-boat-trump-hegseth It functions identically to Lemmy's endpoint of the same name although embed_video_url is never populated. ——— Over the last few days there's been a raft of other API changes too, to do with • The new Gen AI filter (user settings to determine), an AI label on posts, etc. • Marking comments as an answer. Each comment has an answer boolean on it and there's an endpoint to toggle it. Also you can change whether a community is a Q n A community or not in the community edit endpoint.

Search endpoint now has a 'Relevance' sort

More User Settings in the API

We just merged some updates to the /user/change_user_settings endpoint to add a bunch of user settings that were previously only found in the web ui. I have tried to compile them in a list below. However, first I wanted to provide a bit of extra information about the visibility settings that have been added. Part of this update adds visibility controls for NSFW posts, NSFL posts, and posts made by bot accounts. Previously in the api, NSFW and NSFL controls were just a simple on/off control. I have retained those fields as a Boolean so that nothing breaks with existing api clients. However, I have added new fields that override the old ones if they are provided. They offer a more fine-grained control over the visibility of the content that mirrors what is available in the web ui. Namely, the new options are: • Show - posts show up in the feed • Hide - completely hides the posts from the feed • Blur - In the web ui, this setting blurs any thumbnail or text previews associated with these posts until the thumbnail is expanded or the post is clicked into. This feature would need to be implemented client side to match your client's styling if you want to support it. • Transparent - In the web ui, this setting makes these posts semi-transparent (css: opacity: 0.2;) until the thumbnail is expanded or the post is clicked into. This feature would need to be implemented client side to match your client's styling if you want to support it. As mentioned above, these settings are available for three different kinds of content; bot posts through the bot_visibility setting, nsfw posts through the nsfw_visibility setting, and nsfl posts through the nsfl_visibility setting. The old show_nsfw and show_nsfl fields are still there, but are overridden if the corresponding *_visibility field is provided. Also, as part of this, the LocalUser schema now returns additional fields for the new settings. There are now the three *_visibility fields there as well as the show_nsfw and show_nsfl fields. The show_* fields will be marked as true for any visibility option other than Hide. If you have questions, feel free to ask here or hit us up on matrix or zulip. Without further ado, here are the new fields in the /user/change_user_settings endpoint: • accept_private_messages - controls who the user will accept private messages from • bot - marks or unmarks the user as a bot account • bot_visibility - as discussed above, offers more options for how to display bot posts (will need to be implemented client side if you plan to support them) • community_keyword_filter - a list of words which will prevent communities with those words in their name from appearing in the user's feed • email_unread - receive an email about unread notifications occasionally (if the local admin has set it up) • federate_votes - setting to control whether the user's votes are federated out (more public) or only stay on the local instance (more private) • feed_auto_follow - setting that auto-subscribes to any community in a feed that the user subscribes to • feed_auto_leave - setting that auto-unsubscribes to any community in a feed that the user unsubscribed to (if the user subscribed outside of being auto-subscribed, then they will not be auto-unsubscribed) • hide_low_quality - setting that hides communities that are marked as low quality by the local admin from the user's feed • indexable - setting to allow the user's posts to show up using the search function • newsletter - subscribe to the local instance's newsletter (if the local admin has set it up or ever uses it) • nsfl_visibility - as discussed above, offers more options for how to display nsfl posts (will need to be implemented client side if you plan to support them) • nsfw_visibility - as discussed above, offers more options for how to display nsfw posts (will need to be implemented client side if you plan to support them) • reply_collapse_threshold - in the web ui, post replies below this score are automatically collapsed, but can still be expanded to be viewed (will need to be implemented client side if you plan to support this) • searchable - setting to allow the user to show up in the user list on the instance • reply_hide_threshold - in the web ui, post replies below this threshold are automatically hidden completely (will need to be implemented client side if you plan to support this) I have pushed these changes to the crust server (swagger here). Let us know if you run into any issues or have feedback/questions/suggestions!

Poll and Event posts in the API

This is ready for testing on crust.piefed.social. I've made two testing posts in the testing community • https://crust.piefed.social/c/test/p/74625/test-poll • https://crust.piefed.social/c/test/p/74626/test-event In the API they show up as extra data on a post. For example here https://crust.piefed.social/api/alpha/post/list?community_name=test@crust.piefed.social you'll see this for event posts: GtQa90oNvDcKyW5.png and this for poll posts: RQIMWGmG1aQkUu5.png Other types of post will not have that data present, not even as an empty object or null. Let me know if that causes you problems. As always, the full API spec is at https://crust.piefed.social/api/alpha/swagger including how to add or edit those types of post. It's the same data structure as getting a post.

Image management endpoints for images inside post and comment bodies

POST /api/alpha/upload/image - upload an image, get a url back. Use that to construct markdown/html as you wish. Uploaded images are associated with the current user and count towards their quota (50 MB by default, tweakable by instance admin) GET /api/alpha/user/media - get all the images the current user has uploaded. Use this to provide a image picker. POST /api/alpha/image/delete - provide the url of an image that the current user owns and it'll be deleted. Details in the swagger docs.

Sticky Posts and the post/list Endpoint

Hi devs and API enthusiasts! Just wanted to call your attention to a change in the way posts are returned in the /post/list endpoint in the api. This hasn't been backported, so only instances running 1.3.0-dev (the main branch) would currently have this change. The stable, 1.2.x branch is unaffected. Now, when you are filtering to a single community (either by providing a community_name or a community_id), any sticky posts for that community will be returned as the first results of page 1, regardless of the sort order specified. This matches the web ui behavior where sticky posts are...well...stuck to the top of the community's list of posts. One aspect that is different than the web ui is that as you page through the posts, the api will not keep the sticky posts at the top of the results for pages 2+. This should make it easier to create a seamless flow from one page into the next for something like an infinite scroll since the sticky posts won't keep showing up with each request for subsequent pages. I added an ignore_sticky parameter that, when true, allows you to turn off the stickiness of posts when returning results. This should help for applications where you don't care what posts are sticky or not, but you just want them sorted in a specific way. Let me know if you have any questions or feedback!

Stable API Docs

For reasons unrelated to the api, rimu recently pushed piefed.social to the main branch for now. The piefed.social swagger page was acting as the home to the stable branch api docs, so that was no longer available anywhere. To remedy the situation in a more permanent fashion I created an instance whose sole purpose is to just live on the stable branch and serve the swagger docs. So, going forward, here is where you can find piefed api docs. I have updated the project's main readme accordingly. • Stable branch: https://stable.wjs018.xyz/api/alpha/swagger • Development branch (either works, I have ssh access to both to keep them updated): • https://crust.piefed.social/api/alpha/swagger • https://piefed.wjs018.xyz/api/alpha/swagger

New: user details endpoint

GET /api/alpha/user/me - retrieves all the information about the current user, including all the things they've blocked, communities they have joined and communities they moderate. I built this because I realised that many apps are making requests to /api/alpha/site for this purpose, which is unfortunate as that endpoint returns a lot more besides and can sometimes be slow to do so. This is intended to be a more lightweight alternative to doing a GET of /api/alpha/site so the information in /user/me is the same as the my_user part of /site.

v1.2 is coming very soon, please get ready

There's a massive backlog of awesome stuff that really needs to be released so I'll be doing that within the next week or two. Along with that there have been several small changes to the API, mostly just fields being renamed. wjs018 has been posting to this community about them as he goes, please take a look if you haven't already. We have two swagger docs available, the automatically-updated one that includes all the changes at https://crust.piefed.social/api/alpha/swagger and the old one at https://freamon.github.io/piefed-api/ There is a new endpoint at https://crust.piefed.social/api/alpha/site/version which will tell you which version the instance is running on. You can get the same information at https://crust.piefed.social/api/alpha/site but /version is lighter on the server so please use that where possible.

Proposed /user Enpoint Updates for 1.2

I have taken a pass over another set of endpoints, this time the /user endpoints. Overall, there were less changes to these endpoints compared to previous groups I have done. Most of the work for this group focused on the /user/notifications endpoint. This is because marshmallow (the python library doing the schema validation for us) doesn't allow any kind of polymorphism in its schemata, thereby preventing the use of the anyOf part of the OpenAPI spec. So, I had to define a base notification schema and then tried to document the optional fields to indicate what fields would be present for which type of notification. Here is crust running the updated swagger and here is the codeberg PR. I have included a changelog compared to 1.1 below: • GET /user • limit input parameter now defaults to 20. Previously default was 50 for posts and 10 for comments. • PUT /user/subscribe • added subscribed field to response to mirror similar pattern elsewhere, like /user/block • PUT /user/save_user_settings • Documented some input fields that were previously undocumented in the swagger • Documented the response • POST /user/set_flair • modified so that either omitting the flair_text field or setting it to null will remove existing flair • GET /user/notifications • status input field options renamed to one of Unread, Read, or All • unread field replaces new_notifications in the counts field • read field replaces read_notifications in the counts field • total field replaces total_notifications in the counts field • I had to redefine the schema for the items field because the auto-documenting library we are using doesn't support the OpenAPI anyOf feature. So, this field is now a list of a generic notification schema. I have documented which types of notifications the optional fields are returned for. • username field replaces user since it is just a string rather than a whole schema • I added the about_html field to a couple schema (/site and /user/save_user_settings responses both have it) as the html version of a user's about in case it would be easier for you to use the html version of a user's bio instead of markdown.

Proposed /topic/list Endpoint Documentation and Tweaks for 1.2

Me again, here to document some more upcoming api changes as the self-documentation adventure continues. This time, it is the /topic/list endpoint. Similar to feeds, this endpoint exists in 1.1, but it was undocumented. This has led to it not being widely used yet, so I have taken the liberty to make a series of changes to it to help it be more consistent with other endpoints. This has mostly taken the form of field name changes. In the end, this endpoint now looks and functions very similarly to /feed/list by design. Here is the updated swagger running on crust, and here is the codeberg PR if you prefer to look things over there. If you have made use of this endpoint in its 1.1 form, I have included a changelog compared to 1.1 below. Let me know if there are any questions/feedback/requested changes. Changes from 1.1: • Added include_communities request parameter. Functions exactly the same way as the /feed/list endpoint. • Dropped version field • Multiple field name changes for better consistency with other endpoints. I have summarized them in the table below:

 
Old field name | New Field name
--- | ---
num_communities | communities_count
name | title
machine_name | name
parent_id | parent_topic_id
show_posts_in_children | show_posts_from_children

Proposed /feed/list Endpoint Documentation and Tweaks for 1.2

Another post from me as I continue to work through endpoints. This endpoint is present in 1.1, but it is undocumented. AFAIK, only Boost has made use of it so far, so this might be of particular relevance for them. The updated swagger is available here for your perusal. If you have already experimented with this endpoint from 1.1, I have included the changelog below. So far, this is the only feed endpoint in the api, documented or otherwise. I am sure more will be added in the future. This is still open for feedback/suggestions, so if there is something here that would help/hurt, please let me know! Changes from 1.1: • drop machine_name field as it was redundant with name field • rename num_communities to communities_count to better align with other counts fields for other endpoints • drop ap_id and ap_profile_id fields in favor of... • new actor_id field is the url of the activitypub actor (examples: https://instance.tld/f/feed_name for a public feed or https://instance.tld/f/feed_name/user_name for a private feed) • new ap_domain is the instance domain of the actor (example: piefed.social) • rename show_posts_in_children to show_posts_from_children. This is purely a linguistic preference on my part and so I am taking the opportunity before this endpoint gets more widely used, to change it now. • drop version field as it was not really informative • new local field that is a boolean indicating whether the feed is local or remote