🌉 bridged from @wjs018@piefed.wjs018.xyz by Tidepool
wjs018
@wjs018.piefed.wjs018.xyz.ap.tdpl.io
User Registration in the API
The
POST /user/registerendpoint has been a stub for some time now, but as of the next version of PieFed, that endpoint has been implemented (relevant PR). I wanted to walk through some of the specifics as a couple other endpoints were touched on to make this happen.Updates to
GET /siteThere are a couple fields I added to
GET /siteto help aid registration: •captcha_enabled- Lets you know if registration requires a captcha as well. •application_question- If the registration mode isRequireApplication, this field lets you know what the registration question is. •require_email_verification- Lets you know if the site requires email addresses to be verified before the application is reviewed or the user can be active.Updates to
GET /user/get_captchaPretty simple change on this endpoint. Basically, I updated this endpoint so that it no longer includes extraneous newline characters in the base64 encoded data. ——— The actual
POST /user/registerendpoint itself is fairly straightforward. I tried to include lots descriptive error messages if there are issues with the registration. Another note is that the endpoint has a rate limit of just 15/hour. Instance admins can add IP addresses to an allowlist to bypass this limit using theSKIP_RATE_LIMIT_IPSenvironment variable. This endpoint is now live on crust. Let me know if you run into issues or have questions.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/filtersin 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
pythorheadlibrary that I have extensively used in the past to interact with the Lemmy API. So, hopefully usingpieforheadwon'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): •pieforheaduseshttpxto do network requests under the hood, specifically anhttpx.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. •asyncis fully supported thanks tohttpx. Instead of instantiating aPieFedobject, use aPieFedAsyncobject, 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 toGET /post2.GET /post/scheduled/list- return a list of the user's scheduled posts. Similar toGET /post/list, but obviously much more constrained in scope. 3.POST /post/scheduled- create a new scheduled post. Similar toPOST /post. 4.PUT /post/scheduled- edit an existing scheduled post. Similar toPUT /post. 5.POST /post/scheduled/delete- delete or restore a scheduled post. Similar toPOST /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.New Plugin Hooks in PieFed 1.6.20 - New Communities and Webhooks
There are a couple new plugin hooks that were introduced in PieFed 1.6.20 that I wanted to make a post about to help spread the knowledge. As part of this, the plugins doc page has also been updated, but feel free to ask questions here as well if any come to mind.
New Community Hooks
The first two I wanted to mention are the easy ones. They are related to new communities: 1.
new_local_community2.new_remote_communityThese hooks fire whenever a new local community is created, or a new remote community has been federated to your instance. TheCommunityobject is passed to the plugin directly. A potential use-case for a plugin utilizing these hooks would be some kind of integration with a community discovery service. I already made an untested proof of concept to announce new local communities to the Threadirator service that tries to auto-federate new communities across instances for discoverability.The Webhook Hook
Broadly speaking, this hook lets you send webhooks to your PieFed instance and process that data with your plugins. As part of this, we added a new route to PieFed,
POST /webhook, that fires thewebhookplugin hook whenever it handles a valid request. So, here is what happens: 1. Some other service or API or whatever, sends aPOSTto/webhookwith some kind of json payload. 2. As long as there is a valid json payload, then thewebhookplugin hook will fire and that payload will be passed on to the plugin as adict. 3. Every plugin utilizing this hook is called sequentially, so plugins utilizing this hook, should return the original, unaltered payload in case other plugins also need to utilize it, or if the payload was intended for a different plugin. 4. After firing thewebhookplugin, the PieFed instance will return a202to the original request to/webhookto indicate that the request was properly passed to the plugin(s) on the server. There are some important notes I wanted to add about this plugin hook. As I already mentioned, because of the flexibility of this hook, it is quite possible that multiple plugins could be present on the same instance all utilizing it. So, any plugin utilizing this hook should do a couple things: 1. return the webhook payload unaltered for the next plugin to inspect 2. handle any input verification and authorization within the plugin 3. gracefully handle cases where the payload is not structured for, or intended for use with your plugin - just ignore it or log it instead of raising an exception Also of note is that there is a rate limit on the/webhookroute of no more than 60 requests per minute. So, if you are trying to integrate some service that is sending more requests than that, then you should look into batching them in some way or modifying the view function for your instance to remove the rate limit.Update: PieFed Application Actions Now Supports Sending Webhooks
In addition to the previously existing functionality of sending email(s) when an application is ready to review, now you can also (or alternatively) send a webhook. From the readme:
This feature lets you specify a webhook url and payload that is fired when an application is ready for review. The payload is a
dictthat is defined in the config file. You can use variable substitution in specified fields of your payload to help support properly formatting things like message bodies. The full list of variable substitutions is documented in the config file. It might not be desirable to do this substitution for all fields of the payload, so only fields that you specify will be formatted in this way. Add any fields you want to do variable substitution for to thewebhook_format_fieldslist in the config file.Upgrade notes
You probably want to rework your email templates if you previously set them up. Some variable names changed in the new email templates to make it easier to share variables across both the email and webhook functionality.
codeberg.org
More User Settings in the API
We just merged some updates to the
/user/change_user_settingsendpoint 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 thebot_visibilitysetting, nsfw posts through thensfw_visibilitysetting, and nsfl posts through thensfl_visibilitysetting. The oldshow_nsfwandshow_nsflfields are still there, but are overridden if the corresponding*_visibilityfield is provided. Also, as part of this, theLocalUserschema now returns additional fields for the new settings. There are now the three*_visibilityfields there as well as theshow_nsfwandshow_nsflfields. Theshow_*fields will be marked as true for any visibility option other thanHide. 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_settingsendpoint: •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!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/listendpoint 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 acommunity_nameor acommunity_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 anignore_stickyparameter 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!Piefed Onboarding - Actions to help onboard new users
A plugin that I put together making use of the
new_userhook. Currently it is customized through a.tomlfile and you can do these actions: • Create instance/domain/community/user blocks for new users • Automatically subscribe new users to communities/feeds • Send a welcome private messagecodeberg.org
Proposed /user Enpoint Updates for 1.2
I have taken a pass over another set of endpoints, this time the
/userendpoints. 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/notificationsendpoint. This is becausemarshmallow(the python library doing the schema validation for us) doesn't allow any kind of polymorphism in its schemata, thereby preventing the use of theanyOfpart 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•limitinput parameter now defaults to 20. Previously default was 50 for posts and 10 for comments. •PUT /user/subscribe• addedsubscribedfield 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 theflair_textfield or setting it tonullwill remove existing flair •GET /user/notifications•statusinput field options renamed to one ofUnread,Read, orAll•unreadfield replacesnew_notificationsin thecountsfield •readfield replacesread_notificationsin thecountsfield •totalfield replacestotal_notificationsin thecountsfield • I had to redefine the schema for theitemsfield because the auto-documenting library we are using doesn't support the OpenAPIanyOffeature. 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. •usernamefield replacesusersince it is just a string rather than a whole schema • I added theabout_htmlfield to a couple schema (/siteand/user/save_user_settingsresponses both have it) as the html version of a user'saboutin 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/listendpoint. 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/listby 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: • Addedinclude_communitiesrequest parameter. Functions exactly the same way as the/feed/listendpoint. • Droppedversionfield • 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_namefield as it was redundant withnamefield • renamenum_communitiestocommunities_countto better align with other counts fields for other endpoints • dropap_idandap_profile_idfields in favor of... • newactor_idfield is the url of the activitypub actor (examples:https://instance.tld/f/feed_namefor a public feed orhttps://instance.tld/f/feed_name/user_namefor a private feed) • newap_domainis the instance domain of the actor (example:piefed.social) • renameshow_posts_in_childrentoshow_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. • dropversionfield as it was not really informative • newlocalfield that is a boolean indicating whether the feed is local or remoteProposed Changes to Community Endpoints in Piefed 1.2
As part of our ongoing effort to make our api self-documenting and validating our api input/output, we have been working through the api endpoints one at a time to make things a bit more consistent and logical. I just finished doing this for our existing
/communityendpoints and thought I would share the changelog here for awareness and feedback. As of right now, these changes are only live on my instance and on our new, dedicated testing instance, crust.piefed.social. The self-documenting swagger for 1.2 (a WIP) can be found here.1.2 Community Endpoints Changelog
•
PUT /community• input parametercommunity_idproperly documented (was previously erroneously documented asid) •GET /community/list• madenext_pagenullable if there is no next page • this change was backported to 1.1 already •GET /community/moderate/bans•banned_byreplacesbannedBy- transitioning everything to snake case •banned_userreplacesbannedUser- transitioning everything to snake case •expired_atreplacesexpiredAt- transitioning everything to snake case •expired_atvalue ofnullindicates a permanent ban •expired_atonly returned if ban has expired •expires_atfield added, only returned if ban is still in effect •expires_atvalue ofnullindicates permanent ban •PUT /community/moderate/unban• same field name changes as above (snake_case instead of camelCase) •expired_atis now set equal to current time if ban was found (indicating that it was just set to expired) and returned in standard timestamp format found elsewhere in the api (2025-06-07T02:29:07.980084Z) •POST /community/moderate/ban• Input: •expires_atreplacesexpiredAt/expired_atfor input •expires_atuses standard timestamp format (2025-06-07T02:29:07.980084Z) •expires_atis optional •expires_atis checked to make sure it is in the future, raises an exception if it is not •permanentis new optional boolean field, supercedesexpires_atif true • Ifexpires_atis not provided andpermanentis either false or not provided, then the ban is set to expire in one year • Output: • same field name changes as above (snake_case instead of camelCase) •expires_atvalue ofnullindicates permanent ban • standardize timestamp format ofexpires_at• only returnsexpires_atbecause it is a time in the future (does not returnexpired_at)Site and Misc Endpoint Updates
As part of our ongoing effort to make the piefed api self-documenting and validate the input and output, there have been a couple tweaks to the api. I realized that I should probably document them here since not everybody is keeping tabs on every codeberg PR that comes through the repo. •
canAuthUserModeratehas been renamed tocan_auth_user_moderatein theCommentViewschema. This transitioning from camelCase to snake_case will be a theme as I work my way through the endpoints, this is just the first that I ran across. • Thetitlefield in thePersonViewschema will now be equal to theuser_nameinstead ofnullif the user never set a display name. The way this was handled was a bit inconsistent between local and remote users, but now all users should have this behave the same way. • All of the timestamps in theInstanceWithoutFederationStateschema have been standardized to the same format. Previously, these were in the standard iso format, but didn't have theZat the end. • TheSiteschema can now return the site sidebar in html and markdown (if both formats are present). Thesidebarfield will continue to be html, while the newsidebar_mdfield will provide the markdown rendition of the sidebar. In the past, the sidebar was only in html, so the markdown version will only become available after an admin updates their instance's sidebar to use markdown instead of html. That's all the changes that are live up to this point. I will continue to make posts in this community as changes are made to try to keep you all in the loop. While we are talking about the future, other plans for the future are to have a dedicated development instance for testing bleeding edge code while keeping piefed.social on a more stable branch. In the meantime, feel free to peruse my instance's swagger ui (json version), which is up to date with the api changes as I am working on them (community endpoints are next).