客戶重設API

瞭解如何在Adobe Commerce as a Cloud Service中使用新的客戶REST API。 此教學課程非常適合想要有效整合及最佳化API解決方案的架構師和開發人員。

這部影片是給誰看的?

  • 負責建置Adobe Commerce整合功能的後端開發人員
  • 技術架構師為Headless商務實施設計客戶管理工作流程

視訊內容

  • 使用伺服器對伺服器憑證向Adobe IMS進行驗證以取得API請求的存取權杖
  • 對Commerce as a Cloud Service使用正確的REST API端點格式
  • 以程式設計方式使用POST和PUT請求,搭配適當的JSON負載,建立並更新客戶帳戶

程式碼範例

開始之前,請先從Experience CloudAdobe Developer Console收集所有必要的值。 準備好這些值可確保順利的設定程式。

NOTE
確定您是在正確的組織內工作。 您的組織選擇會影響哪些例項和環境可在Experience Cloud和Developer Console中看到。

執行個體詳細資訊 — experience.adobe.com

執行個體詳細資料包含您的執行個體ID、GraphQL端點、憑證等內容。

開發人員詳細資訊 — https://developer.adobe.com/console/

Developer Console是您管理API憑證的地方,包括使用者端ID、使用者端密碼和存取權杖。 您也可以建立新的認證型別,例如伺服器對伺服器或原生應用程式驗證。

先決條件

專案
其中是此值
執行個體ID
<instance_id>
experience.adobe.com
REST端點
<rest_endpoint>
experience.adobe.com
使用者端ID
<client_id>
developer.adobe.com/console
使用者端密碼
<client_secret>
developer.adobe.com/console

步驟1:取得存取Token (伺服器對伺服器驗證)

IMPORTANT
此範例中所示的變數無效。 使用專案認證中的<client_id>和<client_secret>。
curl -X POST 'https://ims-na1.adobelogin.com/ims/token/v3' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>&scope=openid,AdobeID,email,additional_info.projectedProductContext,profile,commerce.aco.ingestion,commerce.accs,org.read,additional_info.roles'

範例回應:

{
  "access_token": "eyJhbGciOiJSUzI1NiIs...",
  "token_type": "bearer",
  "expires_in": 86399
}

步驟2:建立客戶

IMPORTANT
此範例提供的URL無效。 使用您的REST基底url。 將「<rest_endpoint>」與您的URL交換。 它看起來類似於此https://na1-sandbox.api.commerce.adobe.com/AbCYab34cdEfGHiJ27123
此端點沒有/rest/做為URL的一部分。 包括此專案會導致錯誤。

端點: POST /V1/customers

curl -X POST \
  "<rest_endpoint>/V1/customers" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <ACCESS_TOKEN>" \
  -d '{
    "customer": {
      "email": "john.doe@example.com",
      "firstname": "John",
      "lastname": "Doe",
      "store_id": 1,
      "website_id": 1
    },
    "password": "TempPa55word!"
  }'

回應:

{
  "id": 5,
  "group_id": 1,
  "created_at": "2026-01-23 20:40:15",
  "updated_at": "2026-01-23 20:40:15",
  "created_in": "Default Store View",
  "email": "john.doe@example.com",
  "firstname": "John",
  "lastname": "Doe",
  "store_id": 1,
  "website_id": 1,
  "addresses": [],
  "disable_auto_group_change": 0
}

步驟3:更新客戶

IMPORTANT
此範例提供的URL無效。 使用您的REST基底url。 將「<rest_endpoint>」與您的URL交換。 它看起來類似於此https://na1-sandbox.api.commerce.adobe.com/AbCYab34cdEfGHiJ27123

The number 5 in the following example is the ID from the previously created customer using POST "id": 5,. Be sure to change5 to whatever id was returned in your request.

端點: PUT /V1/customers/{customerId}

curl -X PUT \
  "<rest_endpoint>/V1/customers/5" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <ACCESS_TOKEN>" \
  -d '{
    "customer": {
      "id": 5,
      "email": "john.doe@example.com",
      "firstname": "John",
      "lastname": "Doe-Updated"
    }
  }'

回應:

{
  "id": 5,
  "group_id": 1,
  "created_at": "2026-01-23 20:40:15",
  "updated_at": "2026-01-23 20:40:30",
  "created_in": "Default Store View",
  "email": "john.doe@example.com",
  "firstname": "John",
  "lastname": "Doe-Updated",
  "store_id": 1,
  "website_id": 1,
  "addresses": []
}

Complete script (all-in-one)

IMPORTANT
此範例中所示的變數無效。 Use the client ID and client secret from your project credentials. 使用您的REST基底url。 Exchange '<rest_endpoint>' with your REST endpoint URL from experience.adobe.com. It looks similar to this https://na1-sandbox.api.commerce.adobe.com/AbCDefGHiJ1234567.
#!/bin/bash

# Configuration be sure to update these with your projects unique values
CLIENT_ID="<client_id>"
CLIENT_SECRET="<client_secret>"
REST_ENDPOINT="<rest_endpoint>"

# Step 1: Get Access Token
echo "Getting access token..."
ACCESS_TOKEN=$(curl -s -X POST 'https://ims-na1.adobelogin.com/ims/token/v3' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d "grant_type=client_credentials&client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&scope=openid,AdobeID,email,additional_info.projectedProductContext,profile,commerce.aco.ingestion,commerce.accs,org.read,additional_info.roles" | jq -r '.access_token')

echo "Token obtained: ${ACCESS_TOKEN:0:50}..."

# Step 2: Create Customer
echo ""
echo "Creating customer..."
CREATE_RESPONSE=$(curl -s -X POST \
  "${REST_ENDPOINT}/V1/customers" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -d '{
    "customer": {
      "email": "john.doe@example.com",
      "firstname": "John",
      "lastname": "Doe",
      "store_id": 1,
      "website_id": 1
    },
    "password": "TempPa55word!"
  }')

echo "Create Response:"
echo "$CREATE_RESPONSE" | jq .

# Extract customer ID
CUSTOMER_ID=$(echo "$CREATE_RESPONSE" | jq -r '.id')
echo "Customer ID: $CUSTOMER_ID"

# Step 3: Update Customer
echo ""
echo "Updating customer..."
curl -s -X PUT \
  "${REST_ENDPOINT}/V1/customers/${CUSTOMER_ID}" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -d "{
    \"customer\": {
      \"id\": ${CUSTOMER_ID},
      \"email\": \"john.doe@example.com\",
      \"firstname\": \"john\",
      \"lastname\": \"Doe-Updated\"
    }
  }" | jq .

Important notes about this tutorial

  1. URL Path: Use https://<server>.api.commerce.adobe.com/<tenant-id>/V1/customersNOT https://<host>/rest/<store-view-code>/V1/customers
  2. Authentication: This tutorial used Server-to-Server (client_credentials grant type)
  3. Required Scope: commerce.accs
  4. Token Expiry: 86400 seconds (24 hours)

References

recommendation-more-help
commerce-learn-help-home