Kundens REST API
Lär dig använda nya REST API:er för kunder i Adobe Commerce as a Cloud Service. Den här självstudiekursen är perfekt för arkitekter och utvecklare som vill integrera och optimera API-lösningar effektivt.
Vem är den här videon till?
- Utvecklare som ansvarar för integreringen med Adobe Commerce
- Tekniska arkitekter som utformar arbetsflöden för kundhantering för headless commerce-implementationer
Videoinnehåll
- Autentisera med Adobe IMS med autentiseringsuppgifter för server-till-server för att få en åtkomsttoken för API-begäranden
- Använd rätt REST API-slutpunktsformat för Commerce as a Cloud Service
- Skapa och uppdatera kundkonton programmatiskt med POST- och PUT-begäranden med rätt JSON-nyttolaster
Kodexempel
Innan du startar samlar du in alla värden som krävs från Experience Cloud och Adobe Developer Console. Med dessa värden klara får du en smidig konfigurationsprocess.
Instansinformation - experience.adobe.com
Instansinformationen innehåller saker som ditt Instance ID, GraphQL-slutpunkter och autentiseringsuppgifter.
Information om utvecklare - https://developer.adobe.com/console/
I Developer Console hanterar du dina API-autentiseringsuppgifter, inklusive klient-ID:n, klienthemligheter och åtkomsttoken. Du kan också skapa nya autentiseringstyper, till exempel Server-till-server- eller Native App-autentisering.
Förutsättningar
<instance_id><rest_endpoint><client_id><client_secret>Steg 1: Hämta åtkomsttoken (server-till-server-autentisering)
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'
Exempelsvar:
{
"access_token": "eyJhbGciOiJSUzI1NiIs...",
"token_type": "bearer",
"expires_in": 86399
}
Steg 2: Skapa en kund
https://na1-sandbox.api.commerce.adobe.com/AbCYab34cdEfGHiJ27123.Slutpunkt: 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!"
}'
Svar:
{
"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
}
Steg 3: Uppdatera en kund
https://na1-sandbox.api.commerce.adobe.com/AbCYab34cdEfGHiJ27123.Numret 5 i följande exempel är ID:t från den tidigare skapade kunden med POST "id": 5,. Ändra 5 till det ID som returnerades i din begäran.
Slutpunkt: 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"
}
}'
Svar:
{
"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": []
}
Fullständigt skript (allt-i-ett)
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 .
Viktiga anteckningar om den här självstudien
- URL-sökväg: Använd
https://<server>.api.commerce.adobe.com/<tenant-id>/V1/customers— NOThttps://<host>/rest/<store-view-code>/V1/customers - Autentisering: I den här självstudiekursen användes Server-till-server (
client_credentialsanslagstyp) - Obligatoriskt scope:
commerce.accs - Token förfaller: 86400 sekunder (24 timmar)