Synchronize content types
How to synchronize customer content types with the Optimizely GraphQL API.
Optimizely Graph provides endpoints to let customers synchronize content types on their site to the service.
Synchronize full content type
Note
Refer to the Full content type update API reference for more information.
The full content type
API endpoint lets you synchronize the full content type to the service. This endpoint also lets you synchronize your content type with your content source registered.
Example
{
"propertyTypes": {
"ProductLanguage": {
"properties": {
"DisplayName": {
"name": "DisplayName",
"type": "String"
},
"Name": {
"name": "Name",
"type": "String"
}
}
}
},
"label": "Commerce",
"languages": [
"sv"
],
"contentTypes": {
"Catalog": {
"abstract": true,
"contentType": [],
"properties": {
"Id": {
"type": "String"
},
"Name": {
"type": "String"
}
}
},
"Product": {
"contentType": [
"Catalog"
],
"properties": {
"Id": {
"type": "String"
},
"Name": {
"type": "String"
},
"Language":{
"type": "ProductLanguage"
},
"Quantity": {
"type": "Int"
},
"Size": {
"type": "Float"
},
"Color": {
"type": "String"
}
}
}
}
}
curl --location --request PUT 'https://cg.optimizely.com/api/content/v3/types?id=' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic V25KQmNtUlpSNTFYaDJuSmE1UWV5eEkwWWxOUVpFdWsxMDRWV1BYZkcydlcxZUluOkYwaWRhcDRPQ1ZOc0JSQTJmdVpCVDNtYXVoaVl1QWtRcDM5SHduazB2dW1XblpoZytjbmg4QnpHVU5VQlVIYTM=' \
--data '{
"propertyTypes": {
"ProductLanguage": {
"properties": {
"DisplayName": {
"name": "DisplayName",
"type": "String"
},
"Name": {
"name": "Name",
"type": "String"
}
}
}
},
"label": "Commerce",
"languages": [
"sv"
],
"contentTypes": {
"Catalog": {
"abstract": true,
"contentType": [],
"properties": {
"Id": {
"type": "String"
},
"Name": {
"type": "String"
}
}
},
"Product": {
"contentType": [
"Catalog"
],
"properties": {
"Id": {
"type": "String"
},
"Name": {
"type": "String"
},
"Language":{
"type": "ProductLanguage"
},
"Quantity": {
"type": "Int"
},
"Size": {
"type": "Float"
},
"Color": {
"type": "String"
}
}
}
}
}'
Authorization
The acceptable authorization is Basic
and epi-hmac
:
Basic
:
- Username – AppKey
- Password – Secret
Both the Username and Password must be encoded by the base64 algorithm, so the header is Authorization: Basic base64(AppKey:Secret)
.
epi-hmac
: the AppKey and the Secret are signed by the hmac algorithm.
var crypto = require("crypto-js");
var sdk = require('postman-collection');
// This script uses 2 variables.
//
// EPTSKey
// EPTSSecret
//
var method = pm.request.method;
var key = pm.variables.get("EPTSKey");
var secret = CryptoJS.enc.Base64.parse(pm.variables.get("EPTSSecret"));
var target = new sdk.Url(request.url).getPathWithQuery();
var timestamp = (new Date()).getTime();
var nonce = Math.random().toString(36).substring(7);
var body = "";
if( pm.request.body )
{
body = pm.request.body.raw;
}
var bodybase64 = crypto.MD5(body).toString(CryptoJS.enc.Base64);
var hmac = crypto.HmacSHA256(key + method + target + timestamp + nonce + bodybase64, secret);
var base64hmac = CryptoJS.enc.Base64.stringify(hmac);
var header = "epi-hmac " + key + ":" + timestamp +":" + nonce + ":" + base64hmac;
pm.request.headers.add(header, "Authorization")
Synchronize partial content type
Note
Refer to the API Reference on Partial content type update for more information.
You must call synchronize full content type before using this endpoint to update partial content type.
The Partial content type
endpoint lets you synchronize the partial content type to the service.
Example
{
"languages": [
"sv"
],
"contentTypes": {
"Product": {
"contentType": [
"Catalog"
],
"properties": {
"Id": {
"type": "String"
},
"Name": {
"type": "String",
"searchable": true
},
"Language":{
"type": "ProductLanguage"
},
"Quantity": {
"type": "Int"
},
"Size": {
"type": "Float"
},
"Color": {
"type": "String"
}
}
}
}
}
curl --location 'http://localhost:4000/api/content/v3/types?id=cms' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic V25KQmNtUlpSNTFYaDJuSmE1UWV5eEkwWWxOUVpFdWsxMDRWV1BYZkcydlcxZUluOkYwaWRhcDRPQ1ZOc0JSQTJmdVpCVDNtYXVoaVl1QWtRcDM5SHduazB2dW1XblpoZytjbmg4QnpHVU5VQlVIYTM=' \
--data '{
"languages": [
"sv"
],
"contentTypes": {
"Product": {
"contentType": [
"Catalog"
],
"properties": {
"Id": {
"type": "String"
},
"Name": {
"type": "String",
"searchable": true
},
"Language":{
"type": "ProductLanguage"
},
"Quantity": {
"type": "Int"
},
"Size": {
"type": "Float"
},
"Color": {
"type": "String"
}
}
}
}
}'
Updated about 1 month ago