API Testing is now enabled for you to practice API testing using Magento 2 store.
Setup:
- Create a customer using API
- Create a customer Token using API
- Use customer API to practice various API end points.
Credentials:
Important credentials to be used while making a call.
Consumer Key: u5gkmvsnxvc5w6qxoy2iwx98mkc1j30d Consumer Secret: brpz2fvopf9fcdlkqh6dlbh8ui5lqow6 Access Token: cdxf96vcah8pbivc3zzrshd8t15ikua5 Access Token Secret: lkqssgly3qw0eel6pcaug1s9203v2pwn
Create a customer account using API in Magento 2
To create a customer account, admin permissions are required.
Endpoint
POST https://magento.softwaretestingboard.com/rest/default/V1/customers
Headers
Content-Type application/json
Authorization Bearer <use mentioned Toke here>
Payload
You should substitute the value of the email parameter with a real email address. As if you do that, you can receive all notifications.
Note: Make sure to use unique email ID every time in below sample.
Code sample
{
"customer": {
"email": "[email protected]",
"firstname": "Jane",
"lastname": "Doe",
"addresses": [{
"defaultShipping": true,
"defaultBilling": true,
"firstname": "Jane",
"lastname": "Doe",
"region": {
"regionCode": "NY",
"region": "New York",
"regionId":43
},
"postcode": "10755",
"street": ["123 Oak Ave"],
"city": "Purchase",
"telephone": "512-555-1111",
"countryId": "US"
}]
},
"password": "Password1"
}
Response
This user id value of 125342 is assigned by Magento.
Code sample
{
"id":125342,
"group_id":1,
"default_billing":"25386",
"default_shipping":"25386",
"created_at":"2024-02-10 07:05:44",
"updated_at":"2024-02-10 07:05:44",
"created_in":"Default Store View",
"email":"[email protected]",
"firstname":"Jane",
"lastname":"Doe",
"store_id":1,
"website_id":1,
"addresses":[
{
"id":25386,
"customer_id":125342,
"region":{
"region_code":"NY",
"region":"New York",
"region_id":43
},
"region_id":43,
"country_id":"US",
"street":[
"123 Oak Ave"
],
"telephone":"512-555-1111",
"postcode":"10755",
"city":"Purchase",
"firstname":"Jane",
"lastname":"Doe",
"default_shipping":true,
"default_billing":true
}
],
"disable_auto_group_change":0,
"extension_attributes":{
"is_subscribed":false
}
}
You can use the username [email protected] and the password Password1 to log in to the Luma store.
Create a customer Token using API
Note: By default, a customer token is valid for 1 hour
Endpoint
POST https://magento.softwaretestingboard.com/rest/default/V1/integration/customer/token/
Headers:
Content-Type application/json
Payload
Use email ID you used to create the account above.
{
"username": "[email protected]",
"password": "Password1"
}
Response:
"io6p4tdah33bnicvtiggev52er8xgy29"
Use the generated token to access the customer information.
Use customer API end points for your practice
Ref: https://developer.adobe.com/commerce/webapi/rest/quick-reference/
Endpoint
GET https://magento.softwaretestingboard.com/rest/default/V1/customers/me
Headers
Content-Type application/json
Authorization Bearer <use generated Token above>
Response
{
"id":125342,
"group_id":1,
"default_billing":"25386",
"default_shipping":"25386",
"created_at":"2024-02-10 07:05:44",
"updated_at":"2024-02-10 07:31:37",
"created_in":"Default Store View",
"email":"[email protected]",
"firstname":"Jane",
"lastname":"Doe",
"store_id":1,
"website_id":1,
"addresses":[
{
"id":25386,
"customer_id":125342,
"region":{
"region_code":"NY",
"region":"New York",
"region_id":43
},
"region_id":43,
"country_id":"US",
"street":[
"123 Oak Ave"
],
"telephone":"512-555-1111",
"postcode":"10755",
"city":"Purchase",
"firstname":"Jane",
"lastname":"Doe",
"default_shipping":true,
"default_billing":true
}
],
"disable_auto_group_change":0,
"extension_attributes":{
"is_subscribed":false
}
}
If you have any technical questions, use https://stackoverflow.com/. To report an issue, drop us an email.
