25
loading...
This website collects cookies to deliver better user experience
webapi.xml
configuration file. This file is used to register our API routes and specify the rights, such as:GET
, POST
, SAVE
, and so on);anonymous
, self
);Type of User | Available Resources |
Administrator or Integration | Resources with admin or integrator authorization. Suppose administrators are entitled to the Magento_Customer::manage resource. It means they can make a PUT /V1/customers/:customerId call.
|
Customer | Access to resources with anonymous or self permission
|
Guest user |
anonymous permission
|
Authorization
request header as proof of your identity on web API calls.Integration \
**It doesn’t have time restrictions, and the access granted by the merchant lasts forever **until it is manually revoked. \
Admin \
The merchant determines an admin user’s access to Magento resources, lasting four hours. \
Customer \
**Such tokens are valid for **one hour. Users with anonymous
or self
authorization get access to resources from Magento. These options are not editable by merchants.
Access the Integrations page. Log in to Admin and go to System *> **Extensions *> **Integrations. \
To access the New Integration page, click Add New Integration. \
Proceed to the Name **field and give the integration a unique name. Type your admin password in the **Your Password section. Don’t fill in other fields. \
Navigate to the API tab, where you can choose the access to Magento resources for the integration (all resources or a custom list). \
After saving your modifications by clicking the **Save **button, return to the Integrations page. \
Find the grid of the newly-created integration, click the Activate **link, and select **Allow.
anonymous
permission level using the Magento web API architecture.POST /V1/integration/customer/token
integrationCustomerTokenServiceV1
Authorization
request header with the Bearer
HTTP authorization scheme to establish your identity. As I’ve mentioned, an admin token is valid for four hours by default, while a customer token remains operative for one hour. You can change the default settings from the Admin menu like this: resource
to which the request is addressed. \
\
Let’s take this endpoint as an example: \
POST <host>/rest/<store_code>/V1/integration/customer/token
. \
Here, the server is magento.host/index.php/
, the web service is rest
, and the resource is /V1/integration/customer/token
.\
Content type
It concerns the request body. There are two options to set this value: "Content-Type:application/json"
or "Content-Type:application/xml"
. \
Credentials \
This is a Magento account’s username and password. Include code in the call to specify these credentials in a JSON request body: {"username":"<USER-NAME>;", "password":"<PASSWORD>"}
. \
\
If you need to indicate these credentials in XML, use this code in the call: <login><username>customer1</username><password>customer1pw</password></login>
.
curl
command to request a token for an admin account:curl -H "Content-Type: application/json" \
--request "POST" \
--data '{"username":"<username>","password":"<password>"}' \
https://<magento_host>/index.php/rest/V1/integration/admin/token
6yivz6jrmo147x4skq0xt1ights6siob
Authorization: Bearer <authentication token>
curl -X GET https://<magento_host>/index.php/rest/V1/customers/29171 \
-H "Authorization: Bearer 6yivz6jrmo147x4skq0xt1ights6siob"
self
permissions. The following code explains how to use a customer token to make a web API call:curl -X GET https://<magento_host>/index.php/rest/V1/customers/me \
-H "Authorization: Bearer 6yivz6jrmo147x4skq0xt1ights6siob"
It starts by generating a request token. \
This token is usable for a short time and must be exchanged for an access token.
Access tokens have a lengthy lifespan and expire only when the merchant revokes the application access.
Creating an integration from Admin. The merchant builds an integration, while Magento generates a consumer key and a consumer secret. \
The next step is activating the integration, which starts the OAuth process. Magento uses HTTPS post to transmit the following attributes to the external application: \
These credentials go to the page indicated in the Callback Link field in Admin.
The integrator receives the activation information and saves it to ask for tokens. </p>
Magento accesses the application login page specified in the Admin Identity Link field. </p>
The merchant logs in to the third-party application, which will integrate with Magento. The application returns to the call location in case of a successful login. The login page doesn’t participate in this process. </p>
The application asks for a request token. It uses the REST API POST /oauth/token/request
. The consumer key and other details are included in the Authorization
header. </p>
The application** receives a request token and a request token secret** from Magento. </p>
The application asks for an access token using the REST API POST /oauth/token/access
. The request token and other details are included in the Authorization
header. </p>
Magento delivers an access token and an **access token secret **if the request is successful. </p>
The application can operate the store resources. All requests submitted to Magento must include the entire set of request parameters in the Authorization
header.
store_base_url
(for example, http://magento-store-example.com);oauth_verifier
;oauth_consumer_key
;oauth_consumer_secret
.oauth_consumer_key
. And to get an access token, they use the oauth_verifier
.POST /oauth/token/request
Authorization
header of the call:oauth_consumer_key
;oauth_signature_method
;oauth_signature
;oauth_nonce
;oauth_timestamp
;oauth_version
.oauth_token
, the token to request an access token;oauth_token_secret
, a secret value that identifies who owns the token.oauth_token=6rq0x917xdzkhjlru0n4m2r6z2vvj66r&oauth_token_secret=4d85786q9yxisfjoh0d2xgvsard8j0zj
POST /oauth/token/access
Authorization
header contains the same request parameters as for the request token, plus:oauth_token
, or the request token;oauth_verifier
, a verification code transmitted as part of the initial POST transaction.oauth_token=6rdpi1d4qypjpcdxcktef35kmmqxw6b1&oauth_token_secret=fcufgnt83chiljiftg2uj7nty6vvfzgo
oauth_token
, which enables third-party applications to access protected resources;oauth_token_secret
.GET /rest/V1/addresses/3112
Authorization
request header in the call must be:oauth_consumer_key
;oauth_nonce
;oauth_signature_method
;oauth_signature
;oauth_timestamp
;oauth_token
.Authorization
header includes the signature of every OAuth handshake and Web API requests. How do you generate the OAuth signature? The signature base string is created by connecting the following set of URL-encoded attributes and parameters with the ampersand (&) character:oauth_nonce
;oauth_signature_method
;oauth_timestamp
;oauth_version
;oauth_consumer_key
;oauth_token
.self
API, the following method retrieves the details:GET /rest/V1/customers/me
.webapi.xml
file.