查詢資料Adobe Commerce Optimizer
瞭解如何在Adobe Commerce Optimizer執行個體上使用GraphQL查詢資料。
這部影片是給誰看的?
- Commerce解決方案架構師與開發人員
視訊內容
- 使用GraphQL查詢資料
- 使用jq讓json更易於閱讀
程式碼範例
請確定將{{insert-your-graphql-endpoint-url}}
、{{insert-your-ac-view-id}}
和{{your-search-query-string}}
等值與查詢所需的值交換。
基本範例查詢
curl '{{insert-your-graphql-endpoint-url}}' \
-H 'Content-Type: application/json' \
-H 'AC-View-ID: {{insert-your-ac-view-id}}' \
-d '{"query": "query ProductSearch($search: String!) { productSearch( phrase: $search, page_size: 10, current_page: 2) { items { productView { sku name description shortDescription images { url } ... on SimpleProductView { attributes { label name value } price { regular { amount { value currency } } roles } } } } } }", "variables": { "search": "{{your-search-query-string}}"}}'
使用jq
以美化列印輸出的基本範例查詢
curl '{{insert-your-graphql-endpoint-url}}' \
-H 'Content-Type: application/json' \
-H 'AC-View-ID: {{insert-your-ac-view-id}}' \
-d '{"query": "query ProductSearch($search: String!) { productSearch( phrase: $search, page_size: 10, current_page: 2) { items { productView { sku name description shortDescription images { url } ... on SimpleProductView { attributes { label name value } price { regular { amount { value currency } } roles } } } } } }", "variables": { "search": "{{your-search-query-string}}"}}' | jq .
3a5f7e19-f383-4af8-8983-d01154c1402f