Query Documents by ID or UID

You can retrieve either multiple documents or a single one by their document id. It is also possible to query a document by its uid.

Query a document by its id using the helper function

Copy
      api.getByID('WAjgAygABN3B0a-a').then(function(pageContent) {
    // pageContent contains the document content
});
    
Copy
      $pageContent = $api->getByID('WAjgAygABN3B0a-a');
// $pageContent contains the document object
    
Copy
      page_content = api.getByID("WAjgAygABN3B0a-a")
# page_content contains the document content
    

Query a document by its id without the helper function

Copy
      api.query(
    Prismic.Predicates.at('document.id', 'WAjgAygAAN3B0a-a')
).then(function(pageContent) {
    // pageContent.results[0] contains the document content
});
    
Copy
      $pageContent = $api->query(Predicates::at('document.id', 'WAjgAygAAN3B0a-a'));
// $pageContent->getResults()[0] contains the document content
    
Copy
      page_content = api.query(Prismic::Predicates.at("document.id", "WAjgAygAAN3B0a-a"))
# page_content.results[0] contains the document content
    

Query multiple documents by their ids using the helper function

Copy
      var ids = ['WAjgAygAAN3B0a-a', 'WC7GECUAAHBHQd-Y', 'WEE_gikAAC2feA-z'];
api.getByIDs(ids).then(function(content) {
    // content is the response object, content.results holds the documents
});
    
Copy
      $ids = ['WAjgAygAAN3B0a-a', 'WC7GECUAAHBHQd-Y', 'WEE_gikAAC2feA-z'];
$content = $api->getByIDs($ids);
// $content contains the response object, $content->getResults() holds the documents
    
Copy
      ids = [ "WAjgAygAAN3B0a-a", "WC7GECUAAHBHQd-Y", "WEE_gikAAC2feA-z" ]
content = api.getByIDs(ids)
# content is the response object, content.results holds the documents
    

Query multiple documents by their ids without the helper function

Copy
      var ids = ['WAjgAygAAN3B0a-a', 'WC7GECUAAHBHQd-Y', 'WEE_gikAAC2feA-z'];
api.query(
    Prismic.Predicates.in('document.id', ids)
).then(function(content) {
    // content is the response object, content.results holds the documents
});
    
Copy
      $ids = ['WAjgAygAAN3B0a-a', 'WC7GECUAAHBHQd-Y', 'WEE_gikAAC2feA-z'];
$content = $api->query(
    Predicates::in('document.id', $ids)
);
// $content is the response object, $content->getResults() holds the documents
    
Copy
      ids = [ "WAjgAygAAN3B0a-a", "WC7GECUAAHBHQd-Y", "WEE_gikAAC2feA-z" ]
content = api.query(Prismic::Predicates.in("document.id", ids))
# content is the response object, content.results holds the documents
    

Query a document of the type “page” by its uid “about-us”.

Copy
      api.getByUID('page', 'about-us').then(function(pageContent) {
    // pageContent contains the document content
});
    
Copy
      $pageContent = $api->getByUID('page', 'about-us');
// $pageContent contains the document content
    
Copy
      page_content = api.getByUID("page", "about-us")
# page_content contains the document content
    

Query a document of the type "page" by its uid "about us" without using the helper function

Copy
      api.query(
    Prismic.Predicates.at('my.page.uid', 'about-us')
).then(function(pageContent) {
    // pageContent is the response object, pageContent.results holds the documents
});
    
Copy
      $pageContent = $api->query(Predicates::at('my.page.uid', 'about-us'));
// $pageContent->getResults()[0] contains the document content
    
Copy
      page_content = api.query(Prismic::Predicates.at("my.page.uid", "about-us"))
# page_content.results[0] contains the document content