Snippets
Quote API
URL
Relations
Quote
has many Quote Setions
Quote Section
belongs to Quote
Quote Section
has many Quote Items
Quote Item
belongs to Quote
Quote Item
belongs to Quote Section
Steps
- Create Quote
- Create Quote Item
- Get Agency Providers
- Get Provider Price List
- Create Quote Item (Package)
- Get Provider Package
- Create Quote Item (Custom)
- Create Quote Item (Bundle)
- Get Order Bundle
- Create Quote Item (Publication)
Create Quote
To create a quote, you will need the campaign that you want to add it to.
For example we will use campaign_id
: 227
Request:
curl -X POST "api/v2/campaign_quotes.json" \
-H "x-api-token: API_KEY" \
-d 'campaign_id=227'
It will create a campaign quote with default values, and a default quote section:
Response:
{
...,
"title": "Quote #{quote_id}",
"total": 0,
"recipient_address": "#{campaign_address}",
"recipient_name": "#{first_contact_name}",
"recipient_email": "#{first_contact_email}",
"recipient_phone": "#{first_contact_phone}",
"sections": [
{
...,
"id": "#{campaign_section_id}",
"campaign_quote_id": "#{quote_id},
"title": "Marketing",
},
],
}
Get Agency Providers
Before we can create a quote item, we need to get the available services for the agency's the providers. You can use the include params to get the provider details.
Parameter | Default | Required | Description |
---|---|---|---|
include_agency_provider_provider | false | No | Provider detail information |
Notes
service
in the JSON object will list all the products
that belong to this service. If you need to filter by product, the filter value is service_product_id
.
Request
curl -X GET \
'/api/v2/agency_providers.json?include_agency_provider_provider=true' \
-H "x-api-token: API_KEY" \
Return
[
{
"id": 204,
"agency_id": 1,
"provider_id": 1,
"service_id": 6,
"identity_code": "",
"provider_price_list_id": 12,
"provider": {
"id": 1,
"accounts_email": "accounts@sprintmedia.com",
"accounts_phone": "02 9980 0085",
"active": true,
"address_line_1": "52/49-51 Mitchell Road",
"address_line_2": "",
"address_postcode": "2100",
"address_region": "Brookvale",
"address_state": "NSW",
"business_number": "80 119 533 807",
"email": "signs@sprintmedia.com.au",
"order_api": "vfx",
"phone": "02 0000 0700",
"shipping_address": "SprintMedia Signs\n52/49-51 Mitchell Road\nBrookvale NSW 2100",
"short_name": "SprintSigns",
"title": "SprintMedia Signs",
"website": "www.sprintmedia.com",
...,
},
"service": {
"id": 6,
"title": "Print",
"short_name": "print",
"options": null,
"products": [
{
"id": 17,
"options": null,
"orderable": true,
"reference_title": null,
"service_id": 6,
"title": "A4 Brochures"
},
{...},
{...},
]
}
},
{...},
{...},
]
Get Provider Price List
Once we have a list of providers we can use the provider price list id from the response to get the price list items, products and options.
Notes
items
: price_list_items
items->options
: provider_price_list_item_options
items->options->values
: provider_price_list_item_option_value
- User selects the service
- User selects the product from service, and filters
items
by usingservice_product_id
-
User selects an
item
or quantity- Each
item
has manyoptions
- Each
option
has manyvalues
- Each
-
User selects a
value
for eachoption
Request:
curl -X GET \
http://localhost:3000/api/v2/provider_price_lists/12.json \
-H "x-api-token: API_KEY" \
Response:
{
"id": 12,
"default": true,
"provider_id": 1,
"service_id": 6,
"soft_match_codes": false,
"title": "Print Services 2016",
"active_product_ids": [17,18,19,20,23,24,33],
"items": [
{
"id": 122,
"provider_price_list_id": 12,
"service_product_id": 17,
"quantity": 50,
"price": 65,
"hidden": false,
"options": [
{
"id": 95,
"provider_price_list_item_id": 122,
"title": "Finish",
"values": [
{
"id": 130,
"provider_price_list_item_option_id": 95,
"title": "Satin",
"price": 0
},
{
"id": 131,
"provider_price_list_item_option_id": 95,
"title": "Gloss Laminated DS",
"price": 45
},
{...},
{...},
]
},
{
"id": 96,
"provider_price_list_item_id": 122,
"title": "Paper Weight",
"values": [
{
"id": 135,
"provider_price_list_item_option_id": 96,
"title": "200GSM",
"price": 0
},
{
"id": 136,
"provider_price_list_item_option_id": 96,
"title": "250GSM",
"price": 5
},
{...},
]
},
{...},
]
},
{...},
{...},
]
}
Get Agency Price
Before we create a quote item, we need the price for the selected product and option combination.
Query Parameters
Parameter | Default | Required | Description |
---|---|---|---|
provider_price_list_item_id | null | Yes | The items/quantities of the price list. |
campaign_id | null | Yes | The price base for the campaign. |
item_options | null | No | An array from price list options and option values. Please follow the format below. |
item_options:
[
{
"id": provider_price_list_option_id,
"title": provider_price_list_option_title,
"value": {
"id": option_value_id,
"title": option_value_title,
"price": option_value_price,
},
},
{...},
{...},
]
Example One
Retrieve agency price for price list item without any options
Request:
curl -X GET "http://localhost:3000/api/v2/provider_price_list_items/122/agency_price.json?campaign_id=227" \
-H "x-auth-token: API_KEY"
Response:
{
"price": 65,
}
Example Two
Retrieve agency price for price list item with one option
Request:
curl -X GET "api/v2/provider_price_list_items/122/agency_price.json?item_options=[{%22id%22:95,%22title%22:%22Finish%22,%22value%22:{%22id%22:130,%22title%22:%22Satin%22,%22price%22:0}}]&campaign_id=227" \
-H "x-auth-token: API_KEY"
item_options example
[
{
"id": 95,
"title": "Finish",
"value": {
"id": 130,
"title": "Satin",
"price": 0,
}
},
]
Response:
{
"price": 65,
}
Example Three
Retrieve agency price for price list item with two options
Request:
curl -X GET "http://localhost:3000/api/v2/provider_price_list_items/122/agency_price.json?item_options=[{%22id%22:%2095,%20%22title%22:%20%22Finish%22,%22value%22:%20{%20%22id%22:%20130,%22title%22:%22Satin%22,%22price%22:%200}},{%22id%22:%2096,%22title%22:%20%22Paper%20Weight%22,%22value%22:%20{%22id%22:%20136,%22title%22:%20%22250GSM%22,%22price%22:%205}}]&campaign_id=227" \
-H "x-auth-token: API_KEY"
item_options example
[
{
"id": 95,
"title": "Finish",
"value": {
"id": 130,
"title": "Satin",
"price": 0,
}
},
{
"id": 96,
"title": "Paper Weight",
"value": {
"id": 136,
"title": "250GSM",
"price": 5,
}
}
]
Response:
{
"price": 70,
}
Create Quote Item
To create a quote item, you need to GET agency provider
to get all the services. Secondly, using provider_price_list_id
to GET provider price lists
and options. Then GET agency price
base on user selected product and options. Finally POST create quote item
to create a quote item.
If we want to create a quote item to Campaign Quote #201 and Section #166 with below data:
Service: Print (id: 6)
Service Product: A4 Brochures (service_product_id: 17)
Price List item: - id: 122 - quantity: 50 - price: 65
Option One:
- title: Finish (id: 95)
- value:
- title: Satin (id: 130)
- price: 0
Option Two:
- title: Paper Weight (id: 96)
- value:
- title: 250GSM (id: 136)
- price: 5
Request:
curl -X POST "http://localhost:3000/api/v2/campaign_quotes/201/sections/166/items.json" \
-H "x-auth-token: API_KEY" \
-F 'title=Test Title' \
-F item_type=orderable \
-F order_type=item \
-F price_list_item_id=122 \
-F 'options=[{"id":95,"title":"Finish","value":{"id":130,"title":"Satin","price":0}},{"id":96,"title":"Paper Weight","value":{"id":136,"title":"250GSM","price":5}}]'
Response:
{
"id": 770,
"campaign_quote_id": 201,
"campaign_quote_section_id": 166,
"compulsory": false,
"data": {},
"description": null,
"display_options": null,
"display_title": "50 x A4 Brochures/Satin/250GSM",
"item_type": "orderable",
"locked": false,
"options": [
{
"id": 95,
"title": "Finish",
"value": {
"id": 130,
"title": "Satin",
"price": 0
}
},
{
"id": 96,
"title": "Paper Weight",
"value": {
"id": 136,
"title": "250GSM",
"price": 5
}
}
],
"options_string": "/Satin/250GSM",
"order_bundle_id": null,
"package_id": null,
"price": 70,
"price_override": 77,
"price_type": "fixed",
"processing_fee": 7,
"provider_id": 1,
"provider_price_list_item_id": 122,
"publication_edition_id": null,
"publication_id": null,
"publication_package_id": null,
"quantity": 50,
"row_title": null,
"selected": true,
"service_id": 6,
"service_product_id": 17,
"sort": null,
"title": "A4 Brochures",
"user_id": 10,
"dates": {
"required": {
"date": ""
}
}
}
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.