Recommended profiles

📘

full code repo https://github.com/lens-protocol/lens-api-examples

The API right now has basic ways to get popular profiles. It does not support a paging list as of yet. The API will undergo continuous improvement to ensure that it is returning profiles that are more relevant to the user using machine learning. By using this API you inherit all improvements without needing to change code.

API details

query RecommendedProfiles {
  recommendedProfiles {
        id
      name
      bio
      attributes {
        displayType
        traitType
        key
        value
      }
        followNftAddress
      metadata
      isDefault
      picture {
        ... on NftImage {
          contractAddress
          tokenId
          uri
          verified
        }
        ... on MediaSet {
          original {
            url
            mimeType
          }
        }
        __typename
      }
      handle
      coverPicture {
        ... on NftImage {
          contractAddress
          tokenId
          uri
          verified
        }
        ... on MediaSet {
          original {
            url
            mimeType
          }
        }
        __typename
      }
      ownedBy
      dispatcher {
        address
        canUseRelay
      }
      stats {
        totalFollowers
        totalFollowing
        totalPosts
        totalComments
        totalMirrors
        totalPublications
        totalCollects
      }
      followModule {
        ... on FeeFollowModuleSettings {
          type
          amount {
            asset {
              symbol
              name
              decimals
              address
            }
            value
          }
          recipient
        }
        ... on ProfileFollowModuleSettings {
         type
        }
        ... on RevertFollowModuleSettings {
         type
        }
      }
  }
}
{
  "data": {
    "recommendedProfiles": [
      {
        "id": "0x11",
        "name": null,
        "bio": null,
        "attributes": [
          {
            "displayType": null,
            "traitType": null,
            "key": "custom_field",
            "value": "yes this is custom"
          }
        ],
        "followNftAddress": null,
        "metadata": "ipfs://QmSfyMcnh1wnJHrAWCBjZHapTS859oNSsuDFiAPPdAHgHP",
        "isDefault": false,
        "picture": null,
        "handle": "hh",
        "coverPicture": null,
        "ownedBy": "0x5905232b8ea73f1F2FCBE4297573733bf41b666d",
        "dispatcher": null,
        "stats": {
          "totalFollowers": 2,
          "totalFollowing": 0,
          "totalPosts": 4,
          "totalComments": 0,
          "totalMirrors": 0,
          "totalPublications": 4,
          "totalCollects": 0
        },
        "followModule": null
      },
      {
        "id": "0x14",
        "name": null,
        "bio": null,
        "location": null,
        "website": null,
        "twitter": null,
        "attributes": [
          {
            "displayType": null,
            "traitType": null,
            "key": "custom_field",
            "value": "yes this is custom"
          }
        ],
        "followNftAddress": null,
        "metadata": "ipfs://QmSfyMcnh1wnJHrAWCBjZHapTS859oNSsuDFiAPPdAHgHP",
        "isDefault": false,
        "picture": null,
        "handle": "lucasaave",
        "coverPicture": null,
        "ownedBy": "0x7953FE8b8cC7c6391683353aE016B9D90f072767",
        "depatcher": null,
        "stats": {
          "totalFollowers": 2,
          "totalFollowing": 0,
          "totalPosts": 0,
          "totalComments": 5,
          "totalMirrors": 0,
          "totalPublications": 5,
          "totalCollects": 0
        },
        "followModule": null
      },
      {
        "id": "0x06",
        "name": null,
        "bio": null,
        "attributes": [
          {
            "displayType": null,
            "traitType": null,
            "key": "custom_field",
            "value": "yes this is custom"
          }
        ],
        "followNftAddress": null,
        "metadata": "ipfs://QmSfyMcnh1wnJHrAWCBjZHapTS859oNSsuDFiAPPdAHgHP",
        "isDefault": false,
        "picture": null,
        "handle": "lucas",
        "coverPicture": null,
        "ownedBy": "0x6ea7c12CbB8480236716d1EEB0B31C2950166F3B",
        "dispatcher": null,
        "stats": {
          "totalFollowers": 2,
          "totalFollowing": 0,
          "totalPosts": 2,
          "totalComments": 1,
          "totalMirrors": 1,
          "totalPublications": 4,
          "totalCollects": 0
        },
        "followModule": null
      },
      {
        "id": "0x13",
        "name": null,
        "bio": null,
        "attributes": [
          {
            "displayType": null,
            "traitType": null,
            "key": "custom_field",
            "value": "yes this is custom"
          }
        ],
        "followNftAddress": null,
        "metadata": "ipfs://QmSfyMcnh1wnJHrAWCBjZHapTS859oNSsuDFiAPPdAHgHP",
        "isDefault": false,
        "picture": null,
        "handle": "pawelprofile",
        "coverPicture": null,
        "ownedBy": "0xb19C2890cf947AD3f0b7d7E5A9ffBce36d3f9bd2",
        "dispatcher": null,
        "stats": {
          "totalFollowers": 2,
          "totalFollowing": 8,
          "totalPosts": 3,
          "totalComments": 1,
          "totalMirrors": 0,
          "totalPublications": 4,
          "totalCollects": 0
        },
        "followModule": null
      },
      {
        "id": "0x01",
        "name": null,
        "bio": null,
        "attributes": [
          {
            "displayType": null,
            "traitType": null,
            "key": "custom_field",
            "value": "yes this is custom"
          }
        ],
        "followNftAddress": null,
        "metadata": "ipfs://QmSfyMcnh1wnJHrAWCBjZHapTS859oNSsuDFiAPPdAHgHP",
        "isDefault": false,
        "picture": null,
        "handle": "hey",
        "coverPicture": null,
        "ownedBy": "0xD020E01C0c90Ab005A01482d34B808874345FD82",
        "dispatcher": null,
        "stats": {
          "totalFollowers": 2,
          "totalFollowing": 1,
          "totalPosts": 1,
          "totalComments": 0,
          "totalMirrors": 0,
          "totalPublications": 1,
          "totalCollects": 0
        },
        "followModule": null
      }
    ]
  }
}
type Query { 
    recommendedProfiles: [Profile!]!
}

Full code example

import { apolloClient } from './apollo-client';
// this is showing you how you use it with react for example
// if your using node or something else you can import using
// @apollo/client/core!
import { gql } from '@apollo/client'

const RECOMMENDED_PROFILES = `
  query {
    recommendedProfiles {
        id
        name
        bio
        attributes {
            displayType
            traitType
            key
            value
        }
        metadata
        isDefault
        picture {
          ... on NftImage {
            contractAddress
            tokenId
            uri
            verified
          }
          ... on MediaSet {
            original {
              url
              width
              height
              mimeType
            }
            small {
              url
              width
              height
              mimeType
            }
            medium {
              url
              width
              height
              mimeType
            }
          }
          __typename
        }
        handle
        coverPicture {
          ... on NftImage {
            contractAddress
            tokenId
            uri
            verified
          }
          ... on MediaSet {
            original {
              url
              width
              height
              mimeType
            }
            small {
              height
              width
              url
              mimeType
            }
            medium {
              url
              width
              height
              mimeType
            }
          }
          __typename
        }
        ownedBy
        dispatcher {
          address
          canUseRelay
        }
        stats {
          totalFollowers
          totalFollowing
          totalPosts
          totalComments
          totalMirrors
          totalPublications
          totalCollects
        }
        followModule {
          ... on FeeFollowModuleSettings {
            type
            amount {
              asset {
                symbol
                name
                decimals
                address
              }
              value
            }
            recipient
          }
          ... on ProfileFollowModuleSettings {
           type
          }
          ... on RevertFollowModuleSettings {
           type
          }
      }
    }
  }
`

export const getRecommendedProfiles = () => {
   return apolloClient.query({
    query: gql(RECOMMENDED_PROFILES),
  })
}
// this is showing you how you use it with react for example
// if your using node or something else you can import using
// @apollo/client/core!
import { ApolloClient, InMemoryCache, HttpLink, ApolloLink } from '@apollo/client'

const httpLink = new HttpLink({ uri: 'https://api-mumbai.lens.dev/' });

// example how you can pass in the x-access-token into requests using `ApolloLink`
const authLink = new ApolloLink((operation, forward) => {
  // Retrieve the authorization token from local storage.
  // if your using node etc you have to handle your auth different
  const token = localStorage.getItem('auth_token');

  // Use the setContext method to set the HTTP headers.
  operation.setContext({
    headers: {
      'x-access-token': token ? `Bearer ${token}` : ''
    }
  });

  // Call the next link in the middleware chain.
  return forward(operation);
});

export const apolloClient = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache(),
})

Did this page help you?