Fetching a list of documents from a custom entity in Master Data V1

Hi,
I wan to fetch list of documents from my custom entity which i have created in master data v1 .
@georgebrindeiro Could you please suggest me any solution,
Thanks

Hi @Ashif112,
Have you tried using the VTEX Get Documents method with Data Entity and Name,
For fetching all the documents with a given size you can also use Scroll Documents.

export const resolvers = {
  Query:{

    getAllYears:async(_:any,__:any,ctx:any)=>{
        const {
          clients : {masterdata}
        } =ctx 

       return masterdata.scrollDocuments({
        dataEntity:SHOP_BY_VEHICLE,
          fields:['year','makes','id',],
          schema:SCHEMA_VERSION,
          sort:`year DESC`,
          size:20
        }).then(({data}:{data:any})=>data)
    },}

This is a basic representation of Scroll Documents for creating GraphQL Queries you can use the same for REST APIs

2 Likes

Great solution, @TanishqxSharma! That’s the way to go if you’re developing a store theme or app in VTEX IO. We talk about it in the Connecting to VTEX Core Commerce APIs guide in our documentation… Using the MasterData client is the easiest way to do it inside our infrastructure.

If you are building an API integration outside our infrastructure, however, you could achieve the same result by using the Master Data API.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.