Movatterモバイル変換


[0]ホーム

URL:


Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog InCross-platform products
Dev guide
All
Pages
Start typing to search…

Synchronize content types for external data

With custom content sources, you can add custom data to Optimizely Graph and query using the GraphQL API.

Optimizely Graph provides endpoints to let you define the GraphQL schema of your content source. The schema is important for the data youupload to the Optimizely Graph service.

🚧

Important

This feature is not enabled by default for your account. Contact Optimizely with a request to get additional sources.

Synchronize full content definition

📘

Note

The schema does not work if several content types have the same name across sources. You must have unique names on the content types from external sources that do not conflict with content types in CMS.

For information, refer to theFull content type update API reference.

Thefull content type API endpoint lets you sync the full definition of your content to the service.

curl --location --request PUT 'https://dev.cg.optimizely.com/api/content/v3/types?id=src2' \--header 'Content-Type: application/json' \--header 'Authorization: Basic V25KQmNtUlpSNTFYaDJuSmE345UWV5eEkwWWxOUVpFhjkdWsxMDRWV1BYZkcydlcxZUluOlduSkJjbVJaUjUxWGgybkphNVFleXhJMFlsTlFaRXVrMTA0VldQWGZHMnZXMWVJbg==' \--data '{ "languages": ["en"], "contentTypes":{   "test": {     "contentType": [],     "properties": {       "Name": {        "type": "String"       }     }   } }}
var client = new HttpClient();var request = new HttpRequestMessage(HttpMethod.Put, "https://dev.cg.optimizely.com/api/content/v3/types?id=,quang");request.Headers.Add("Authorization", "Basic V25KQmNtUlpSNTFYaDJuSmEghjU0WdgV5eEkwWWxOUVpFdWsxMDRWV1BYZkcydlcxZUluOlduSkJjbVJaUjUxWGgybkphNVFleXhJMFlsTlFaRXVrMTA0VldQWGZHMnZXMWVJbg==");var content = new StringContent("{\n \"languages\": [\"en\"],\n \"contentTypes\":{\n   \"test\": {\n     \"contentType\": [],\n     \"properties\": {\n       \"Name\": {\n        \"type\": \"String\"\n       }\n     }\n   }\n }\n}", null, "application/json");request.Content = content;var response = await client.SendAsync(request);response.EnsureSuccessStatusCode();Console.WriteLine(await response.Content.ReadAsStringAsync());
  • id=src2 – Source name, max 4 characters
  • languages – Required and not empty.
  • contentTypes – Required and not empty.
  • test – Content type name.
  • contentType – Required.
  • properties – Required and not empty.

The above request creates asrc2 datasource and a GraphQL schema that matches the content type.

🚧

Important

If you upload a full content definition using thefull content type API endpoint, all data in the content source is deleted.

Example

The following example shows how to define property types, languages, and content types for a content source containing product information. It shows the use of simple data types in addition to theProductLanguage property type.

{    "propertyTypes": {        "ProductLanguage": {            "properties": {                "DisplayName": {                    "name": "DisplayName",                    "type": "String"                },                "Name": {                    "name": "Name",                    "type": "String"                }            }        }    },    "label": "Commerce",    "languages": [        "en"    ],    "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"                }            }        }    }}

The followingcurl command issues aPUT request with the definition using the IDcom, which is the name of the content source. If the content source does not exist already, it is created.

🚧

Important

If you create more content sources than your account lets you, the call will fail, and the content source will not be created.

curl --location --request PUT 'https://cg.optimizely.com/api/content/v3/types?id=com' \--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 isBasic andepi-hmac:

Basic:

  • Username – AppKey
  • Password – Secret

Both the username and password must be encoded by the base64 algorithm, so the header isAuthorization: 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 theAPI Reference on Partial content type update for information.

You must callsynchronize full content type before using this endpoint to update partial content type.

ThePartial content type endpoint lets you sync the partial content type to the service.

Example

The following example changes theName to be searchable by addingsearchable to theName property :
"Name": { "type": "String", "searchable": true }

{    "languages": [        "en"    ],    "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"                }            }        }    }}

Again, the data is being sent to thetypes endpoint but usingPOST instead ofPUT. It uses thecom ID to specify the target content source.

curl --location 'https://cg.optimizely.com/api/content/v3/types?id=com' \--header 'Content-Type: application/json' \--header 'Authorization: Basic V25KQmNtUlpSNTFYaDJuSmE1UWV5eEkwWWxOUVpFdWsxMDRWV1BYZkcydlcxZUluOkYwaWRhcDRPQ1ZOc0JSQTJmdVpCVDNtYXVoaVl1QWtRcDM5SHduazB2dW1XblpoZytjbmg4QnpHVU5VQlVIYTM=' \--data '{    "languages": [        "en"    ],    "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 2 months ago



[8]ページ先頭

©2009-2025 Movatter.jp