vsf-api-prismic
v0.3.2
Published
Prismic implementation for vue storefront-api
Downloads
4
Maintainers
Readme
Prismic Api Module
This API extension
- get data from prismic repository
- Saving this data to Elastic Search and uses Elastic Search data layer (you can switch it off in configs
useElasticSearchLayer
) - Listen to Prismic webhooks, on api change updates 3 lately published pages (you can switch it off in configs
useElasticSearchLayer
) - Provides methods to modify the Prismic content on return
Installation
In your config/local.json
file you should register the extension:
"registeredExtensions": ["cms-prismic"],
and also add your prismic API config:
"prismic": {
"apiEndpoint": "https://publicrepo.prismic.io/api/v2",
"useElasticSearchLayer": true,
"webhook": {
"secretKey": "<< your secret >>"
}
}
Make sure that you have installed prismic-javascript
npm module
npm install prismic-javascript --save
To switch off Elastic Search layer and stop to listen to Prismic weebhooks
in config file set useElasticSearchLayer
to false.
GET /api/ext/cms-prismic/index/
GET parameters
id - id from Prismic.
/api/ext/cms-prismic/index/?id=W1G4GxEAACIAdKrj
-> will search for document with id W1G4GxEAACIAdKrjtype - type from Prismic, type of document
/api/ext/cms-prismic/index/?type=cms_page
-> will search for documents with type cms_page NOTE, if you want to use searching bytype
with Elastic Search Layer on, then usenode src/api/extensions/cms-prismic/scripts/prismic.js fetch
command in console to fetch and save Prismic datatag - Prismic document tag NOTE, if you want to use searching by
tag
with Elastic Search Layer on, then usenode src/api/extensions/cms-prismic/scripts/prismic.js fetch
command in console to fetch and save Prismic dataindex_name - use if you have multiple indexes in ElasticSearch (for different languages). By default module uses:
vue_storefront_catalog
(from config, first of elasticsearch.indices)filter - use filter with given name
filter_option - use with
filter
, passing parameter to filters
Example response
{
"code":200,
"result":
{
"prismic_content":[{"image":{"dimensions":{"width":1920,"height":350},"alt":null ...
}
}
POST /api/ext/cms-prismic/webhook/
listens to Prismic webhooks.
To listen to Prismic webhooks:
- set up webhook on your Prismic repo (Look on Prismic docs: [https://user-guides.prismic.io/webhooks/webhooks])
- Use url: /api/ext/cms-prismic/webhook/
- Paste your secret token to config/local.json
Ideas for use
Imagine that you want to promote your 'New product' on some landing page, or anywhere on your store. You have multiple documents in prismic, with many types like 'banner', 'promotion_text', 'countdown' etc. containing information about 'New product' So give them new, common tag like 'new-product' and fetch your data like this: http://localhost:8080/api/ext/cms-prismic/index/?tag=new-product
You want to manage menu using prismic, so copy id of this document http://localhost:8080/api/ext/cms-prismic/index/?id=W-G4GxEAACIAdKrj
Using types, for example fetch all social media data http://localhost:8080/api/ext/cms-prismic/index/?type=social_media