Guides

Get Profiles

Fetch all Lens profiles that match the given criteria.

This method can be used for many different use-cases such as:

  • Fetch all profiles that match a given list of profile ids
  • Fetch profiles that are owned by an address within a given list of EVM address
  • Fetch profiles that are owned by a handle within a given list of handles
  • Fetch profiles that have mirrored a given publication
  • Fetch profiles that have quoted a given publication
  • Fetch profiles that have commented on a given publication

Request

Below is the structure of the request, followed by some examples of how to construct it for common use-cases.

  • where: ProfilesRequestWhere (required)
    • profileIds: ProfileId[] (optional)
      • A list of profile ids to filter by
    • ownedBy: ProfileId[] (optional)
      • A list of profile ids to filter by
    • handles: Handle[] (optional)
      • A list of handles to filter by
    • whoMirroredPublication: PublicationId (optional)
      • The identifier of the publication to filter which profiles have mirrored it
    • whoQuotedPublication: PublicationId (optional)
      • The identifier of the publication to filter which profiles have quoted it
    • whoCommentedOn: PublicationId (optional)
      • The identifier of the publication to filter which profiles have commented on it
  • limit: number (optional)
    • The maximum number of profiles to fetch
  • cursor: number (optional)
    • The number of profiles to skip before fetching the first profile

A ValidationError will be thrown if you provide more than more field in the where object.

Fetch Profiles by Profile Ids

Fetch profiles that match a given array of profileIds.

Note: Passing an empty array will also result in a ValidationError being thrown.

{
  where: {
    profileIds: ["0x01", "0x02"]
  }
}

Fetch Profiles by Owned By

Fetch profiles that match a given array of ownedBy which is an array of EVM addresses.

Note: Passing an empty array will result in a ValidationError being thrown.

{
  where: {
    ownedBy: ["0x01", "0x02"]
  }
}

Fetch Profiles by Handles

Fetch profiles that match a given array of handles.

Note: Passing an empty array will result in a ValidationError being thrown.

{
  where: {
    handles: ["lens/@lensprotocol", "lens/@aave"]
  }
}

Fetch Profiles by Mirrored Publication

Fetch all profiles that have mirrored a given publication.

{
  where: {
    whoMirroredPublication: "0x01-0x01"
  }
}

Fetch Profiles by Quoted Publication

Fetch all profiles that have quoted a given publication.

{
  where: {
    whoQuotedPublication: "0x01-0x01"
  }
}

Fetch Profiles by Commented Publication

Fetch all profiles that have commented on a given publication.

{
  where: {
    whoCommentedOn: "0x01-0x01"
  }
}

Invocation

const profiles = await lensClient.profile.fetchAll({
  where: { profileIds: ["PROFILE_ID"] },
})
query Profile {
  profiles(request: { where: { profileIds: ["PROFILE_ID"] } }) {
    items {
      ...Profile
    }
    pageInfo {
      ...PaginatedResultInfo
    }
  }
}

Response

{
  "items": [
    // list of Profiles
    {
      // ...Profile
    }
  ],
  "pageInfo": {
    // ...PaginatedResultInfo
  }
}

Using LensClient SDK

// your LensClient does not need to be authenticated

// by list of profile ids
const profilesById = await lensClient.profile.fetchAll({
  where: { profileIds: ["0x0635"] },
})

console.log(
  `Profiles fetched by ids: `,
  profilesById.items.map((i) => ({ id: i.id, handle: i.handle }))
)

// by wallet address profiles are owned by
const address = "0xe3D871d389BF78c091E29deCe83200E9d6B2B0C2"
const allOwnedProfiles = await lensClient.profile.fetchAll({
  where: { ownedBy: [address] },
})

console.log(
  `Profiles owned by address: ${address}: `,
  allOwnedProfiles.items.map((i) => ({ id: i.id, handle: i.handle }))
)

// by a list of Lens handles
const profilesByHandle = await lensClient.profile.fetchAll({
  where: { handles: ["lens/@lensprotocol"] },
})

console.log(
  `Profiles fetched by handles: `,
  profilesByHandle.items.map((i) => ({ id: i.id, handle: i.handle }))
)

// by which profiles have mirrored a publication
const profilesWhoMirroredPublicationId = await lensClient.profile.fetchAll({
  where: { whoMirroredPublication: "0x0635-0x0f" },
})

console.log(
  `Profiles who mirrored publication: `,
  profilesWhoMirroredPublicationId.items.map((i) => ({
    id: i.id,
    handle: i.handle,
  }))
)

// by which profiles have quoted a publication
const profilesWhoQuotedPublicationId = await lensClient.profile.fetchAll({
  where: { whoQuotedPublication: "0x0635-0x0f" },
})

console.log(
  `Profiles who quoted publication: `,
  profilesWhoQuotedPublicationId.items.map((i) => ({
    id: i.id,
    handle: i.handle,
  }))
)

// by which profiles have commented on a publication
const profilesWhoCommentedPublicationId = await lensClient.profile.fetchAll({
  where: { whoCommentedOn: "0x0635-0x0f" },
})

console.log(
  `Profiles who commented publication: `,
  profilesWhoCommentedPublicationId.items.map((i) => ({
    id: i.id,
    handle: i.handle,
  }))
)

Full GraphQL API Example

πŸ“˜

Get Profiles: GraphQL API Full Example