身份驗證
建立 API 金鑰
要將應用程式連接到商店,你需要一個 API 金鑰。在管理後台選擇權限,指定應用程式可以讀取哪些資料,以及可以修改哪些內容。
你也可以指定應用程式存取 API 時使用的 IP 位址。填寫後,金鑰只能從這些位址使用。完成設定後建立 API 金鑰。
取得存取權杖
使用存取權杖傳送請求時,不必在每個請求中傳遞 API 金鑰。不再需要權杖時,可以將其撤銷。
取得權杖時,也會收到商店可用的權限和 API 請求速率限制。
POST
/api/v1/auth/tokencURL 請求
curl --disable --globoff --fail-with-body --silent --show-error \
--proto '=https' --connect-timeout 5 --max-time 30 \
--request POST \
--url https://shop.onshopently.com/api/v1/auth/token \
--header 'Authorization: ApiKey EXAMPLE_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{"ttl_seconds":1800}'
回應
{
"data": {
"access_token": "EXAMPLE_ACCESS_TOKEN",
"expires_at": "2026-01-01T12:15:00Z",
"expires_in": 1800,
"permissions": [
"orders.order:read"
],
"rate_limits": {
"auth_per_minute": 1,
"read_per_minute": 2,
"write_per_minute": 15
},
"token_type": "Bearer",
"warnings": []
},
"meta": {
"request_id": "example"
}
}
傳送 API 請求
傳送 API 請求時,請使用取得的權杖。不要超過商店的請求限制。能否存取各項操作也取決於方案包含的權限。
如果需要為請求選擇語言或市場,請取得商店情境。回應會提供可用的語言和市場,以及各自的代碼與識別碼。
撤銷權杖
撤銷權杖是選擇性操作。如果僅用於一次性工作,建議在工作完成後撤銷。如果不手動撤銷,權杖會持續有效至設定的期限結束。之後將無法再使用。
POST
/api/v1/auth/revokecURL 請求
curl --disable --globoff --fail-with-body --silent --show-error \
--proto '=https' --connect-timeout 5 --max-time 30 \
--request POST \
--url https://shop.onshopently.com/api/v1/auth/revoke \
--header 'Authorization: ApiKey EXAMPLE_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{"access_token":"EXAMPLE_ACCESS_TOKEN"}'
回應
{
"data": {
"revoked": true
},
"meta": {
"request_id": "example-request"
}
}