Writing Follows to Your Graph
Follows represent a follow relationship between two users. Creating follows is easy. Simply pass in the id
or the username
of the user creating the follow (i.e. the follower) into the startId
field, and id
or the username
of the follow recipient (i.e. the followee) into the endId
field. Use the same id you used when creating the profile.
Here's an example command that makes user marcus
follow user nehemiah
.
import { SocialFi } from 'socialfi';
const API_URL = 'https://api.dev.usetapestry.dev/v1/';
const API_KEY = process.env.TAPESTRY_API_KEY;
const client = new SocialFi({ baseURL: API_URL, apiKey: API_KEY });
// Make 'marcus' follow 'nehemiah'
await client.followers.postFollowers(
{},
{
startId: 'marcus',
endId: 'nehemiah',
},
);
To check if the follow succeeded, you can GET the followers count of the user who received the follow. In this example, we'll ask for nehemiah
's followers count:
// Get nehemiah's follower count
const { data: followerCount } = await client.request.get(
`/profiles/followers/${encodeURIComponent('nehemiah')}`
);
console.log(`nehemiah has ${followerCount} followers`);
and you can also check the following count of the user who performed the follow. In this example, we'll ask for marcus
's following count:
// Get marcus's following count
const { data: followingCount } = await client.request.get(
`/profiles/following/${encodeURIComponent('marcus')}`
);
console.log(`marcus is following ${followingCount} users`);