查詢範本端點
API呼叫範例
以下小節說明您可以使用進行的各種API呼叫 Query Service API。 每個呼叫都包含一般API格式、顯示必要標題的範例要求以及範例回應。
請參閱 UI查詢範本檔案 以取得有關透過Experience Platform UI建立範本的資訊。
擷取查詢範本清單
您可以透過向以下網站發出GET請求,擷取貴組織的所有查詢範本清單: /query-templates
端點。
API格式
GET /query-templates
GET /query-templates?{QUERY_PARAMETERS}
{QUERY_PARAMETERS}
&
)。 可用的引數列示如下。查詢引數
以下是列出查詢範本的可用查詢引數清單。 所有這些引數都是選用的。 在不使用引數的情況下呼叫此端點將會擷取您的組織可用的所有查詢範本。
orderby
created
和 updated
. 例如, orderby=created
將依建立的順序遞增排序結果。 新增 -
建立之前(orderby=-created
)會依建立的遞減順序來排序專案。limit
start
ISO時間戳記允許在日期和時間有不同的詳細程度等級。 基本ISO時間戳記採用以下格式:
2020-09-07
以表示日期2020年9月7日。 更複雜的範例將寫為 2022-11-05T08:15:30-05:00
和對應2022年11月5日、8:15:美國東部標準時間上午30點。 時區可以提供UTC時差,並以「Z」字尾表示(2020-01-01T01:01:01Z
)。 如果未提供時區,則預設為零。property
name
和 userId
. 唯一支援的運運算元是 ==
(等於)。 例如, name==my_template
將傳回名稱為的所有查詢範本 my_template
.要求
以下請求會擷取為您組織建立的最新查詢範本。
curl -X GET https://platform.adobe.io/data/foundation/query/query-templates?limit=1
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-sandbox-name: {SANDBOX_NAME}'
回應
成功的回應會傳回HTTP狀態200,其中包含指定組織的查詢範本清單。 下列回應會傳回為您組織建立的最新查詢範本。
{
"templates": [
{
"sql": "SELECT *\nFROM\n accounts\nLIMIT 10\n",
"name": "Test",
"id": "f7cb5155-29da-4b95-8131-8c5deadfbe7f",
"updated": "2019-11-21T21:50:01.469Z",
"userId": "{USER_ID}",
"created": "2019-11-21T21:50:01.469Z",
"_links": {
"self": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/f7cb5155-29da-4b95-8131-8c5deadfbe7f",
"method": "GET"
},
"delete": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/f7cb5155-29da-4b95-8131-8c5deadfbe7f",
"method": "DELETE"
},
"update": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/f7cb5155-29da-4b95-8131-8c5deadfbe7f",
"method": "PUT",
"body": "{\"sql\": \"new sql \", \"name\": \"new name\"}"
}
}
}
],
"_page": {
"orderby": "-created",
"start": "2019-11-21T21:50:01.469Z",
"next": "2019-11-21T21:50:01.469Z",
"count": 1
},
"_links": {
"next": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates?orderby=-created&start=2019-11-21T21:50:01.469Z"
},
"prev": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates?orderby=-created&start=2019-11-21T21:50:01.469Z&isPrevLink=true"
}
},
"version": 1
}
_links.delete
至 刪除您的查詢範本.建立查詢範本
您可以透過向以下網站發出POST請求來建立查詢範本: /query-templates
端點。
API格式
POST /query-templates
要求
curl -X POST https://platform.adobe.io/data/foundation/query/query-templates
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-sandbox-name: {SANDBOX_NAME}'
-d '{
"sql": "SELECT account_balance FROM user_data WHERE user_id='$user_id';",
"name": "Sample query template",
"queryParameters": {
user_id : {USER_ID}
}
}'
sql
$
. 例如, $key
,並提供SQL中使用的引數,作為 queryParameters
欄位。 此處傳遞的值將是範本中使用的預設引數。 如果您想要覆寫這些引數,必須在POST請求中覆寫它們。name
queryParameters
回應
成功的回應會傳回HTTP狀態202 (已接受)以及您新建立的查詢範本的詳細資料。
{
"sql": "SELECT account_balance FROM user_data WHERE user_id='$user_id';",
"name": "Sample query template",
"id": "0094d000-9062-4e6a-8fdb-05606805f08f",
"updated": "2020-01-09T00:20:09.670Z",
"userId": "{USER_ID}",
"created": "2020-01-09T00:20:09.670Z",
"_links": {
"self": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "GET"
},
"delete": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "DELETE"
},
"update": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "PUT",
"body": "{\"sql\": \"new sql \", \"name\": \"new name\"}"
}
}
}
_links.delete
至 刪除您的查詢範本.擷取指定的查詢範本
您可以向以下網站發出GET要求,擷取特定的查詢範本: /query-templates/{TEMPLATE_ID}
端點並在請求路徑中提供查詢範本的ID。
API格式
GET /query-templates/{TEMPLATE_ID}
{TEMPLATE_ID}
id
您要擷取的查詢範本值。要求
curl -X GET https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-sandbox-name: {SANDBOX_NAME}'
回應
成功的回應會傳回HTTP狀態200以及您指定查詢範本的詳細資料。
{
"sql": "SELECT * FROM accounts;",
"name": "Sample query template",
"id": "0094d000-9062-4e6a-8fdb-05606805f08f",
"updated": "2020-01-09T00:20:09.670Z",
"userId": "A5A562D15E1645480A495CE1@techacct.adobe.com",
"created": "2020-01-09T00:20:09.670Z",
"_links": {
"self": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "GET"
},
"delete": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "DELETE"
},
"update": {
"href": "https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "PUT",
"body": "{\"sql\": \"new sql \", \"name\": \"new name\"}"
}
}
}
_links.delete
至 刪除您的查詢範本.更新指定的查詢範本
您可以透過向以下專案發出PUT請求,更新特定的查詢範本: /query-templates/{TEMPLATE_ID}
端點並在請求路徑中提供查詢範本的ID。
API格式
PUT /query-templates/{TEMPLATE_ID}
{TEMPLATE_ID}
id
您要擷取的查詢範本值。要求
curl -X PUT https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-sandbox-name: {SANDBOX_NAME}'
-d '{
"sql": "SELECT account_balance FROM user_data WHERE user_id='$user_id';",
"name": "Sample query template",
"queryParameters": {
user_id : {USER_ID}
}
}'
sql
$
. 例如, $key
,並提供SQL中使用的引數,作為 queryParameters
欄位。 此處傳遞的值將是範本中使用的預設引數。 如果您想要覆寫這些引數,必須在POST請求中覆寫它們。name
queryParameters
回應
成功的回應會傳回HTTP狀態202 (已接受),其中包含指定查詢範本的更新資訊。
{
"sql": "SELECT * FROM accounts LIMIT 20;",
"name": "Sample query template",
"id": "0094d000-9062-4e6a-8fdb-05606805f08f",
"updated": "2020-01-09T00:29:20.028Z",
"lastUpdatedBy": "{USER_ID}",
"userId": "{USER_ID}",
"created": "2020-01-09T00:20:09.670Z",
"_links": {
"self": {
"href": "https://platform.adobe.io/data/foundation/query/query_templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "GET"
},
"delete": {
"href": "https://platform.adobe.io/data/foundation/query/query_templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "DELETE"
},
"update": {
"href": "https://platform.adobe.io/data/foundation/query/query_templates/0094d000-9062-4e6a-8fdb-05606805f08f",
"method": "PUT",
"body": "{\"sql\": \"new sql \", \"name\": \"new name\"}"
}
}
}
_links.delete
至 刪除您的查詢範本.刪除指定的查詢範本
您可以向以下網站發出DELETE請求,刪除特定的查詢範本: /query-templates/{TEMPLATE_ID}
並在請求路徑中提供查詢範本的ID。
API格式
DELETE /query-templates/{TEMPLATE_ID}
{TEMPLATE_ID}
id
您要擷取的查詢範本值。要求
curl -X DELETE https://platform.adobe.io/data/foundation/query/query-templates/0094d000-9062-4e6a-8fdb-05606805f08f
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-sandbox-name: {SANDBOX_NAME}'
回應
成功的回應會傳回HTTP狀態202 (已接受)並出現以下訊息。
{
"message": "Deleted",
"statusCode": 202
}