ActivityPub Code

From Organic Design wiki


The specification doesn't seem to provide endpoints for interacting with an AP server, that is why I believe that most servers use WebFinger. The only issue is that I can't find that in the specification either.

User Discovery

To request the user's endpoint from the server run the following command.

curl <URL>/.well-known/webfinger?resource=<ACCOUNT NAME>@<URL> \
	-X GET \
	-H "Accept: application/json"

This should return an object describing the user on the server, you should look for inside the links property for an object that has the property "type": "application/activity+json", the next command should be made to the href property of that object.

	-X GET \
	-H "Accept: application/activity+json"

That command should return an object describing the relevant endpoints for that user.

JS Code

const fetch = require("node-fetch");

const url = "";
const user = "john";

const fetcher = async (url, type = "application/json") => {
	const data = await fetch(url, {
		headers: {
			Accept: type

	return await data.json();

const getLatestActivities = async () => {
	let data = await fetcher(`https://${url}/.well-known/webfinger?resource=${user}@${url}`);

	let userUrl;

	for (const link of data.links) {
		if (link.type === "application/activity+json") {
			userUrl = link.href;

	if (!userUrl)
		throw "Could not find user activity url.";

	data = await fetcher(userUrl, "application/activity+json");

	if (!data.outbox)
		throw "No outbox specifed under the user.";

	data = await fetcher(data.outbox);

	if (!data.last)
		throw "Could not find last items in outbox.";

	data = await fetcher(data.last);

	return data;