Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
stylenone

Create a Quote based on a RequestForQuote while choosing a custom price for the Quote-Lines

Use the Create a Quote based on a RequestForQuote endpoint. Make sure to use the correct service_id in the URL and requestForQuoteId in the request body. Provide an array of lines in the request body, where you will specify a custom unitPrice for each line.

Code Block
languagepy
import requests

data = {
    "requestForQuoteId": 1,
    "lines": [{"id": 1, "unitPrice": "12.34"}, {"id": 2, "unitPrice": "5.22"}],
}
url = "https://my-platform.com/api/v2.0/service-panel/services/1/quotes/"

requests.post(
    url,
    json=data,
    headers={"Authorization": "Token my-super-secure-token"},
)

Python Example

Upload an Internal Attachment

In this example, we will be uploading a Quote-Attachment, but you can get inspired by this example to upload Attachments for other Sales-Transactions.
Use the Create a Quote-Attachment endpoint. Make sure to use the correct service_id and quote_id in the URL. Attach the file, and add isInternal flag as a query parameter.

Code Block
languagepy
import requests

files = {
    "file": open("file.txt", "rb"),
}
params = {
    "isInternal": True,
}
url = "https://my-platform.com/api/v2.0/service-panel/services/1/quotes/1/attachments/"

requests.post(
    url,
    files=files,
    params=params,
    headers={"Authorization": "Token my-super-secure-token"},
)

Python Example

Edit a Quote

In order to edit a quote, you need to:

  1. Create a Basket from the desired Quote using the Create a Basket based on an Quote endpoint

  2. List the Basket-Lines using the List Basket-Lines endpoint

  3. Perform the desired changes to the Basket-Lines using the Update a Basket-Line endpoint

  4. Create a new Quote from the Basket using the Create a Quote based on a Basket (edit mode) endpoint

Code Block
languagepy
import requests

# 1. Create a Basket from the desired Quote
url = "https://my-platform.com/api/v2.0/service-panel/services/1/baskets/from-quote/1/"

created_basket = requests.post(
    url,
    headers={"Authorization": "Token my-super-secure-token"},
)
customer_id = created_basket.json()["customer"]["id"]
basket_id = created_basket.json()["id"]

# 2. List the Basket-Lines
# In this example, the desired line will be chosen using the filename
url = (
    f"https://my-platform.com/api/v2.0/service-panel/services/1/baskets/{basket_id}/lines/"
)

lines = requests.get(
    url,
    headers={"Authorization": "Token my-super-secure-token"},
)
desired_basket_line = next(
    (
        line
        for line in lines.json()
        if line["file"]["originalFileName"] == "Drone_V2_Print_Arm_A_x6.stl"
    )
)
desired_basket_line_id = desired_basket_line["id"]

# 3. Perform the desired changes to the Basket-Lines
# In this example, the unitPrice will be changed
data = {
    "unitPrintPrice": "46.50",
}
url = f"https://my-platform.com/api/v2.0/service-panel/services/1/baskets/{basket_id}/lines/{desired_basket_line_id}/"

requests.patch(
    url,
    json=data,
    headers={"Authorization": "Token my-super-secure-token"},
)

# 4. Create a new Quote from the Basket
data = {
    "basketId": basket_id,
    "userId": customer_id,
}
url = f"https://my-platform.com/api/v2.0/service-panel/services/1/edit-quote/"

requests.post(
    url,
    json=data,
    headers={"Authorization": "Token my-super-secure-token"},
)

Python Example

Below there are some examples, on how to edit some of the attributes of a Basket-Line.

How to change the price of a Basket-Line

Code Block
languagepy
data = {
    "unitPrintPrice": "46.50",
}
url = f"https://my-platform.com/api/v2.0/service-panel/services/1/baskets/1/lines/1/"

requests.patch(
    url,
    json=data,
    headers={"Authorization": "Token my-super-secure-token"},
)

Python Example

How to change the material of a Basket-Line

List the available Material-Offers using the List Material-Offers endpoint. Get the ID of the desired offer, and then use it in the payload body of the update request. Make sure to set autoSetPrice to True in the payload body, so that the price of the material is calculated.

Code Block
languagepy
# 1. List the available Material-Offers
# In this example, the desired material will be chosen using it's name
url = f"https://my-platform.com/api/v2.0/service-panel/services/1/offers/"

material_offers = requests.get(
    url,
    headers={"Authorization": "Token my-super-secure-token"},
)
desired_material_offer = next(
    (
        offer
        for offer in material_offers.json()
        if offer["materialName"] == "Accura Xtreme"
    )
)
desired_material_offer_id = desired_material_offer["id"]

# 2. Send the update request
data = {
    "offerId": desired_material_offer_id,
    "autoSetPrice": True,
}
url = f"https://my-platform.com/api/v2.0/service-panel/services/1/baskets/1/lines/1/"

requests.patch(
    url,
    json=data,
    headers={"Authorization": "Token my-super-secure-token"},
)

Python Example

How to change the post-processings of a Basket-Line

List the available Post-Processings for a material that is assigned to a given Basket-Line, using the List Post-Processings for a Material-Offer endpoint. Get the ID of the desired Post-Processing, and then use it in the payload body of the update request. Make sure to set autoSetPrice to True in the payload body, so that the price of the Post-Processing is calculated.

Code Block
languagepy
# 1. List the available Post-Processings
# In this example, the desired Post-Processing will be chosen using it's title
url = f"https://my-platform.com/api/v2.0/service-panel/services/1/offers/1/post-processings/"

post_processings = requests.get(
    url,
    headers={"Authorization": "Token my-super-secure-token"},
)
desired_post_processing = next(
    (
        post_processing
        for post_processing in post_processings.json()
        if post_processing["title"] == "Polishing"
    )
)
desired_post_processing_id = desired_post_processing["id"]

# 2. Send the request
data = {
    "postProcessings": [
        {"postProcessingId": desired_post_processing_id, "autoSetPrice": True}
    ],
}
url = f"https://my-platform.com/api/v2.0/service-panel/services/1/baskets/1/lines/1/"

response = requests.patch(
    url,
    json=data,
    headers={"Authorization": "Token my-super-secure-token"},
)

Python Example

Upload a File into a Basket

...