REST API
Overview
EasyQuote 1.7.5 adds 11 REST routes, all declared in etc/webapi.xml. Eight are admin routes for integrations and back-office tools. Three are customer routes that act on the signed-in customer's own quotes.
| Method | Route | Who calls it | Service method |
|---|---|---|---|
| GET | /V1/easyquote/quote/:id | Admin or integration | QuoteRepositoryInterface::getDataById |
| GET | /V1/easyquote/quote/:id/items | Admin or integration | QuoteRepositoryInterface::getItemsDataById |
| GET | /V1/easyquote/quote/quotes | Admin or integration | QuoteRepositoryInterface::getQuotesData |
| GET | /V1/easyquote/request/:id | Admin or integration | RequestRepositoryInterface::getDataById |
| GET | /V1/easyquote/customer/:id/requests | Admin or integration | RequestRepositoryInterface::getRequestsDataByCustomerId |
| GET | /V1/easyquote/requests | Admin or integration | RequestRepositoryInterface::getRequestsData |
| POST | /V1/easyquote/request/customer/:id/submit | Admin or integration | RequestRepositoryInterface::submitByCustomerId |
| POST | /V1/easyquote/request/cart/:id/submit | Admin or integration | RequestRepositoryInterface::submitByCartId |
| POST | /V1/easyquote/quotes/:quoteId/addToCart | Customer | QuoteManagementInterface::addToCart |
| GET | /V1/easyquote/quotes/:quoteId/items | Customer | QuoteManagementInterface::getItems |
| GET | /V1/easyquote/quotes | Customer | QuoteManagementInterface::getQuotes |
Watch the singular and the plural: /V1/easyquote/quote/… is the admin family, /V1/easyquote/quotes/… is the customer family. No route creates, edits, approves or sends a quote. Those actions exist only as PHP service contracts.
Authentication
Admin routes and customer routes
| Routes | ACL resource in webapi.xml | Token to send |
|---|---|---|
The three quote admin routes | MageMe_EasyQuote::manage_quotes (Sales → EasyQuote → Quotes) | Admin token, or an integration token whose resources include it |
The five request, requests and submit admin routes | MageMe_EasyQuote::manage_requests (Sales → EasyQuote → Requests) | Admin token, or an integration token whose resources include it |
The three quotes customer routes | self | Customer token (POST /V1/integration/customer/token) |
The admin routes check only these parent resources. No REST route checks the child Actions resources, such as Approve or Create Order. A customer token on an admin route gets Magento's standard 401 "The consumer isn't authorized to access %resources."
An integration access token works as a bearer token only when Stores → Configuration → Services → OAuth → Consumer Settings → Allow OAuth Access Tokens to be used as standalone Bearer tokens is Yes. Otherwise sign the call with OAuth 1.0a, or use an admin token (POST /V1/integration/admin/token). This is Magento behaviour, not EasyQuote's. Admin role setup is on Roles and permissions.
Parameters taken from the token
The customer routes declare customerId (all three) and cartId (addToCart) with force="true". Magento fills them from the customer token and ignores any value in the path, query or body.
| Parameter | Filled with | When it can't be filled |
|---|---|---|
customerId | The ID of the customer the token belongs to | An admin token, or an integration token with access to all resources, gets 400 "%fieldName" is required. Enter and try again. for customerId; on addToCart it's 400 "One or more input exceptions have occurred." for cartId and customerId. An integration token with selected resources gets 401 "The consumer isn't authorized to access %resources.", with the resource self. |
cartId | The customer's active cart | 404 "Current customer does not have an active cart." Create one first with POST /V1/carts/mine. |
So a customer can read, and add to the cart, only their own quotes. Older examples that send cartId or customerId in the body have no effect.
Operations
All responses are JSON. A quote object holds every column named in Api/Data/QuoteInterface, plus shipping_method, shipping_description, original_subtotal and discount. Item and address objects hold the columns of QuoteItemInterface and QuoteAddressInterface, without product_options_serialized. A request object holds the columns of RequestInterface, without products_serialized; products is included.
Every route that returns data answers with a JSON array, also for a single quote or request. The service methods name their results quote, request, items or error, but Magento's REST layer drops those names. The shape of each route is given below.
GET /V1/easyquote/quote/:id
Returns one quote by its entity ID (quote_id, not the quote number).
| Parameter | In | Type | Default | Notes |
|---|---|---|---|---|
id | path | int | required | Entity ID |
addItems | query | bool | false | Adds items: all lines, child lines included |
addAddresses | query | bool | false | Adds billing_address and shipping_address, only when the quote has shipping configured (is_shipping_configured = 1) |
Response: an array with one quote object, [{"quote_id": "12", …}]. Numbers come back as strings, such as "12" and "150.0000", except original_subtotal and discount, which are numbers. With addItems=true the object gets an items array. Not found: HTTP 200 with the message as the only array element, ["Unable to find quote with ID \"12\""].
GET /V1/easyquote/quote/:id/items
Returns the lines of one quote. A found quote returns its lines as an array inside the array, [[{…}, …]], like the customer route. Not found: HTTP 200 with [{"error": "…"}], an object inside the array, unlike the route above.
GET /V1/easyquote/quote/quotes
Returns every quote that matches the filters, with no paging.
| Parameter | In | Type | Default | Notes |
|---|---|---|---|---|
addItems | query | bool | false | As above |
addAddresses | query | bool | false | As above |
filter | query | string | none | JSON object of column and value. All pairs must match. A value with % is a LIKE match; any other value is an exact match. |
orderId | query | int | none | Only quotes linked to this Magento order ID |
Response: an array of one-key objects, [{"quote_12": {…}}, {"quote_15": {…}}]. The key is quote_ plus the entity ID. No match returns [].
A value can be a from and to range object for a few columns. On quotes these are the dates created_at, updated_at, reminder_date and expiry_date (whole days, both ends included) and the numbers quote_id, increment_id, customer_id, items_count and grand_total. On requests they are created_at, request_id, increment_id, customer_id and quote_id. Example: filter={"grand_total":{"from":100,"to":500}}. For any other column pass a flat value; an object, such as {"status": {"from": "a"}}, gets HTTP 400 with a PHP type error. Both ends of a range are included.
GET /V1/easyquote/request/:id
Returns one quote request by its entity ID. Response: an array with one request object, [{"request_id": "7", …}]. The object also holds a key named custom_field_#ID#, set to null. Not found: HTTP 200 with the message as the only array element, ["Unable to find request with ID \"7\""].
GET /V1/easyquote/customer/:id/requests
Returns all requests of one customer, by customer ID. Response: [{"request_7": {…}}, …].
GET /V1/easyquote/requests
Returns every request that matches filter, in the same format as for quotes, with no paging. Response: [{"request_7": {…}}, …].
POST /V1/easyquote/request/customer/:id/submit
Creates a quote request from the active cart of customer :id, then works like the cart route below. Without request[email] or request[customer_id], it answers HTTP 400 {"message": "Email field is required."}. A customer with no active cart gets HTTP 200 ["No such entity with customerId = 5"], or [] when the deprecated fields[…] is sent.
POST /V1/easyquote/request/cart/:id/submit
Creates a quote request from cart :id. That's the numeric cart ID, not a masked guest cart ID.
From 1.7.5 on, the service reads the form fields from the request parameter request through Magento's getParam(), so send them in the URL query: ?request[email]=…&request[message]=…. The older name fields[…] is still read when request[…] is absent, but it is deprecated, see below. The fields:
| Field | Used for |
|---|---|
request[email] | Required, unless the cart already belongs to a customer and request[customer_id] is also sent. Must be a valid address, otherwise "Invalid email." For a guest cart, finds the customer by email or creates an account. |
request[firstname], request[lastname] | Name of an account created for a guest cart, and the name on the request when the customer account has none. Required for a guest cart whose email has no account yet: without them the call gets HTTP 400, and no account and no request are created. |
request[company] | Company of the request |
request[message] | The request message |
request[phone], request[custom_field_1] to request[custom_field_3] | Checked against the Required settings of the request form and stored on the request. The request routes return a custom field as it was stored, the option value, not the option text the admin shows. |
A JSON body isn't read. A call that sends the fields only in a JSON body gets HTTP 400 with {"message": "Email field is required."}.
A successful call answers HTTP 200 with the stored request:
curl -s -X POST -H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" -d '{}' \
"https://example.com/rest/V1/easyquote/request/cart/88/submit?request%5Bemail%5D=buyer%40example.com&request%5Bmessage%5D=Please%20quote"
[{ "request_id": "7", "increment_id": "1000000007", "customer_email": "buyer@example.com", "message": "Please quote" }]
The object is shortened here. A validation error answers HTTP 400 in Magento's error format. One error comes as {"message": "Invalid email."}. A message with a placeholder brings its parameters, and several errors come in errors:
{
"message": "One or more input exceptions have occurred.",
"errors": [
{ "message": "%1 is required.", "parameters": ["First Name"] },
{ "message": "%1 is required.", "parameters": ["Last Name"] }
]
}
With the deprecated fields[…], a successful call still answers HTTP 200 with [], although the request is stored. Magento's REST layer reads a parameter named fields as its own response filter, and an array there empties the response. Validation errors come back as HTTP 400 with either name.
From 1.7.5 on, the request stores the customer's email, first and last name, customer group, company, phone and custom fields: the values of the customer account first, then the request[…] values. The notification emails go out with the next cron run, like those of a request from the storefront. For example, a customer cart submitted with an email, a message, a company and a phone stored a request with the name from the account and the company and phone as sent, and both emails went out with the next cron run. On a guest cart with a new email, the call with request[firstname] and request[lastname] creates the account, moves the cart to it and stores the request.
POST /V1/easyquote/quotes/:quoteId/addToCart
Adds the lines of an Approved quote to the customer's active cart at the quoted prices. Response: true.
| Refusal (HTTP 400) | Cause |
|---|---|
| "EasyQuote has been disabled." | Enable is No |
| "Access denied." | Not the customer's quote, a Draft quote or an internal quote |
| "The quote is not approved." | Any status other than Approved |
| "The quote has expired." | Expiry Date has passed |
| "This quote includes products that are no longer available: %1. Contact us to update the quote." | A quoted product was deleted |
| "The quote is already added to the cart." | A line of this quote is already in the cart |
From 1.7.5 on, the quote lines become their own cart lines even when the same product is already in the cart as an ordinary line. The ordinary line keeps its own price.
GET /V1/easyquote/quotes/:quoteId/items
Returns the lines of one of the customer's own quotes, as an array inside the array: [[{…}, …]]. A Pending quote returns its lines too. A Draft, internal or foreign quote returns 400 "Access denied."
GET /V1/easyquote/quotes
Returns the customer's own quotes, except Draft and internal quotes. From 1.7.5 on, the quote objects leave out the fields meant for your team: internal_comments, managed_by, status_user_id, is_admin_notified and cc_email. Takes addItems and addAddresses as above, both false by default. Response: [{"quote_12": {…}}, …].
Errors
| Route family | Not found or invalid input | Business rule refused |
|---|---|---|
| Admin routes | HTTP 200 with the message in an array, ["…"]. On quote/:id/items it's [{"error": "…"}]. Submit validation: HTTP 400, {"message": "…"}, such as {"message": "Email field is required."}. | HTTP 200, in the same forms. |
| Customer routes | HTTP 400, Magento error body {"message": "…"} | HTTP 400, {"message": "…"}. When Enable Extension is No, all three customer routes answer 400 "EasyQuote has been disabled." |
| Any route, wrong token | HTTP 401, Magento error body. On the customer routes an admin token gets HTTP 400, see Parameters taken from the token. | Not applicable |
Apart from submit validation, the admin routes report errors with HTTP 200. Check the first array element before you read it: an object means data, while a string, an array of strings or an object with an error key means an error. A successful submit call with the deprecated fields[…] returns [], as described under the cart submit route.
Examples
Read one quote with its lines, with an admin or integration token:
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \
"https://example.com/rest/V1/easyquote/quote/12?addItems=true"
[
{
"quote_id": "12",
"increment_id": "1000000012",
"customer_id": "5",
"customer_email": "buyer@example.com",
"status": "approved",
"quote_currency_code": "USD",
"subtotal": "150.0000",
"grand_total": "150.0000",
"is_internal": "0",
"shipping_method": "",
"original_subtotal": 150,
"discount": 0,
"items": [
{ "quote_item_id": "31", "quote_id": "12", "sku": "24-MB01", "qty": "5.0000", "price": "30.0000", "row_total": "150.0000" }
]
}
]
The quote and item objects are shortened here; the real ones have every key listed under Operations.
List the quotes in one status, with an admin or integration token:
curl -s -G -H "Authorization: Bearer $ADMIN_TOKEN" \
--data-urlencode 'filter={"status":"awaiting_review"}' \
"https://example.com/rest/V1/easyquote/quote/quotes"
[ { "quote_15": { "quote_id": "15", "status": "awaiting_review" } } ]
Add an approved quote to the customer's cart, with a customer token:
curl -s -X POST -H "Authorization: Bearer $CUSTOMER_TOKEN" \
-H "Content-Type: application/json" -d '{}' \
"https://example.com/rest/V1/easyquote/quotes/12/addToCart"
true
The same call on a quote that waits for the customer's review:
{ "message": "The quote is not approved." }
What's next
- GraphQL: read the same quote data in one query, with an admin or integration token.
- Service contracts: approve, send or duplicate quotes from PHP, which REST can't do.
- Roles and permissions: give an admin or integration role the Quotes and Requests resources.