Lens API

Learn how to integrate directly with the Lens API.


The Lens API utilizes GraphQL, a query language for APIs that allows clients to precisely request the data they need, leading to more efficient data retrieval. GraphQL queries are executed using a type system defined for your data.

Environments

The API links below act as API endpoints as well as playgrounds for testing queries.

NetworkURL
Polygon Mainnethttps://api-v2.lens.dev
Amoy Testnethttps://api-v2-amoy.lens.dev

Visit the examples repository for practical demonstrations of using the Lens API.

GraphQL Clients

GraphQL operations can be performed either through HTTP POST requests or by using specialized GraphQL clients like Apollo or urql. These clients simplify the process of sending GraphQL requests. For mobile development, Apollo also offers iOS and Android SDKs.

const ENDPOINT = 'https://api-v2.lens.dev';
const graphqlQuery = {  query: `    query Publications($orderBy: ExplorePublicationsOrderByType!) {      explorePublications(request: {        orderBy: $orderBy,      }) {        items {          ... on Post {            stats {              reactions            }            metadata {              ... on ImageMetadataV3 {                id                content                asset {                  image {                    optimized {                      uri                    }                  }                }              }              ... on TextOnlyMetadataV3 {                id                content              }            }          }        }      }    }  `,  variables: {    orderBy: "TOP_REACTED"  }};
const response = await fetch(ENDPOINT, {  method: 'POST',  headers: {    'Content-Type': 'application/json',    // 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', // Include this if your API request requires authentication  },  body: JSON.stringify(graphqlQuery)})
const data = await response.json();
console.log(data);