HomeDev guideRecipesAPI ReferenceGraphQL
Dev guideUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Synchronize content data

Describes how to synchronize customer content data via Optimizely GraphQL API

Optimizely Graph provides some endpoints to let customers manage content data on their site to the service.

Synchronize content data

πŸ“˜

Note

Refer to the Sync content data API reference for more information.

The sync content data endpoint lets you synchronize your content data to the service. The endpoint also lets you synchronize your content data through your content source registered.

Example

In this endpoint, we only support NdJSON format to index data to service:

{    "index": {        "_id": 1,        "language_routing": "sv"    }}
{    "Id": "1",    "Name": "Man shoes",    "Quantity": 10,    "size": 43,    "Color": "Black",    "Language": {        "DisplayName": "English",        "Name": "en"    },    "ContentType": [        "Catelog",        "Product"    ],"Status": "Published","RolesWithReadAccess":"Everyone"}
{    "index": {        "_id": 2,        "language_routing": "sv"    }}
{    "Id": "2",    "Name": "Women shoes",    "Quantity": 20,    "size": 38,    "Color": "Pink",    "Language": {        "DisplayName": "English",        "Name": "en"    },    "ContentType": [        "Catelog",        "Product"    ],"Status": "Published","RolesWithReadAccess": "Everyone"}
curl --location 'https://cg.optimizely.com/api/content/v2/data?id=com' \
--header 'Content-Type: text/plain' \
--header 'Authorization: Basic V25KQmNtUlpSNTFYaDJuSmE1UWV5eEkwWWxOUVpFdWsxMDRWV1BYZkcydlcxZUluOkYwaWRhcDRPQ1ZOc0JSQTJmdVpCVDNtYXVoaVl1QWtRcDM5SHduazB2dW1XblpoZytjbmg4QnpHVU5VQlVIYTM=' \
--data '{    "index": {        "_id": 1,        "language_routing": "sv"    }}
{    "Id": "1",    "Name": "Man shoes",    "Quantity": 10,    "size": 43,    "Color": "Black",    "Language": {        "DisplayName": "English",        "Name": "en"    },    "ContentType": [        "Catelog",        "Product"    ],"Status": "Published","RolesWithReadAccess":"Everyone"}
{    "index": {        "_id": 2,        "language_routing": "sv"    }}
{    "Id": "2",    "Name": "Women shoes",    "Quantity": 20,    "size": 38,    "Color": "Pink",    "Language": {        "DisplayName": "English",        "Name": "en"    },    "ContentType": [        "Catelog",        "Product"    ],"Status": "Published","RolesWithReadAccess": "Everyone"}'

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

The following example is a POST request to update content items.

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")

Purge content data

πŸ“˜

Note

Refer to the Purge content data API Reference for more information.

The purge content data endpoint lets you purge your data indexed to the service.

Example

curl --location --request DELETE 'https://cg.optimizely.com/api/content/v2/data?id=cms&languages=en&languages=sv' \
--header 'Authorization: Basic V25KQmNtUlpSNTFYaDJuSmE1UWV5eEkwWWxOUVpFdWsxMDRWV1BYZkcydlcxZUluOkYwaWRhcDRPQ1ZOc0JSQTJmdVpCVDNtYXVoaVl1QWtRcDM5SHduazB2dW1XblpoZytjbmg4QnpHVU5VQlVIYTM='
curl --location --request DELETE 'http://cg.optimizely.com/api/content/v2/data?id=cms&languages=en&languages=sv' \
--header 'Authorization: {{authHeader}}'

πŸ“˜

Note

authHeader = signed HMAC keys pair on the previous postman script example.