Prismicio.getDocumentBySlug()

Get a prismic document by slug.

Usage

Hover over inputs/exits for more info.

var Prismicio = require('machinepack-prismicio');


// Get a prismic document by slug.

Prismicio.getDocumentBySlug({

apiEndpoint: 'https://mycompany.prismic.io/api',

accessToken: 'MC5WUWg4VFOHFh.77-9777-9Me-_73vv73vv70rUO-_vWPvv71O77-9ZUPvv73vv71pX--_vQdaNe-_vQ',

slug: 'my-great-post',

ref: 'VUYf7y0AAJkBHcVj',

html: true,

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// Document not found

notFound: function () {

 

},

// Not authorized

notAuthorized: function () {

 

},

// OK.

success: function () {

 

},

});

Inputs

apiEndpoint required

Api endpoint for your prismic instance

'https://mycompany.prismic.io/api'
accessToken required

Token provided via settings/apps/.

'MC5WUWg4VFOHFh.77-9777-9Me-_73vv73vv70rUO-_vWPvv71O77-9ZUPvv73vv71pX--_vQdaNe-_vQ'
slug required

Slug of document.

'my-great-post'
ref

Control which versions of documents we can access. Defaults to master which is all live documents.

'VUYf7y0AAJkBHcVj'
html

Return document as html?

true

Exits

error

An unexpected error occurred.

notFound

Document not found

notAuthorized

Not authorized

success

OK.