gatsby-source-optimizely-v2
This unofficial source plugin makes Optimizely/Episerver API data available in GatsbyJS sites. Currently in active development.
Features
- Support for multiple Optimizely API versions
- Support for additional headers
Installation and Setup
For npm
:
npm install gatsby-source-optimizely-v2
For yarn
:
yarn add gatsby-source-optimizely-v2
Setup this plugin in gatsby-config.js
as follows (*required fields):
module.exports = {
plugins: [
{
resolve: "gatsby-source-optimizely-v2",
options: {
auth: {
site_url: process.env.OPTMIZELY_API_SITE_URL
username: process.env.OPTMIZELY_API_USERNAME
password: process.env.OPTMIZELY_API_PASSWORD
grant_type: process.env.OPTMIZELY_API_GRANT_TYPE,
client_id: process.env.OPTMIZELY_API_CLIENT_ID,
},
endpoints: {
OptimizelySites: "/v2.0/site",
OptimizelyContent: "/v2.0/content/994?expand=*",
OptimizelyContent: "/v2.0/content/994/children?expand=*",
OptimizelySearchContent: "/v2.0/search/content?expand=*",
},
},
},
],
};
Additional Options
Add additional headers to the auth
request as follows:
options: {
auth: {
siteUrl: process.env.OPTMIZELY_API_SITE_URL,
username: process.env.OPTMIZELY_API_USERNAME,
password: process.env.OPTMIZELY_API_PASSWORD,
grant_type: process.env.OPTMIZELY_API_GRANT_TYPE,
client_id: process.env.OPTMIZELY_API_CLIENT_ID,
headers: {
"X-Custom-Header": "Custom Value",
"Access-Control-Allow-Credentials": "Custom Value",
"Access-Control-Allow-Origin": "Custom Value",
"Accept-Language": "en"
}
},
}
How to Query
Assuming you correctly setup the plugin in gatsby-config.js
and you have a OptimizelyContent
node name and its valid endpoint:
options: {
endpoints: {
OptimizelyContent: "/v2.0/content/994?expand=*";
}
}
you can query the data as follows:
{
allBigCommerceProducts {
nodes {
name
price
id
sku
variants {
id
product_id
price
cost_price
image_url
sku
}
reviews_count
reviews_rating_sum
page_title
images {
id
description
product_id
date_modified
}
bigcommerce_id
brand_id
custom_url {
url
}
categories
availability
}
totalCount
}
}
Contributing
Please feel free to contribute! PRs are always welcome.
License
This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
Author
Guy Romelle Magayano
License
Released under the MIT license.