Центр помощи

API Documentation

To work with our API you will need an <api token>. There are two types of API tokens: private-key and public-upload-key. The private-key provides full access to the API and should not be disclosed to users because they will then have the ability to retrieve confidential data about 3D model uploads of other users. The public-upload-key is restricted to the upload of new models only. Our API supports the following 3D printing file formats: STL, PLY and 3MF. Need help? Contact technical support.

Get API tokens



To upload your 3D model file you should specify these requests:

POST https://www.treatstock.com/api/v2/printable-packs/?private-key=<api-key>

with post parameters

files - 3d model files (stl)
location[country] - (not required) - specify country iso code https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2. If you want to get a print price, you should set one of these location parameters: country or ip.
location[ip] - (not required) - specify client ip.

Edit

Request Examples

POST Request to upload file

CURL Example:

curl -F "files[]=@robots.stl" -F location[ip]=83.69.106.68  https://www.treatstock.com/api/v2/printable-packs?private-key=<api-token>


or

curl -F "files[]=@robots.stl" -F location[ip]=83.69.106.68 -F description="Some model description" https://www.treatstock.com/api/v2/printable-packs?private-key=<api-

or

curl -F "files[]=@robots.stl" -F location[country]=US  https://www.treatstock.com/api/v2/printable-packs?private-key=<api-token>

or

curl -F "files-urls[]=https://mysite.com/my-model.stl" -F location[country]=US  https://www.treatstock.com/api/v2/printable-packs?private-key=<api-token>

Result for POST request are in JSON format:

{
    "success": true,
    "id": 223672,
    "redir": "https://www.treatstock.com/catalog/model3d/preload-printable-pack?packPublicToken=e6c2f63-60815dd-2f91e10",
    "widgetUrl": "https://www.treatstock.com/api/v2/printable-pack-widget/?apiPrintablePackToken=e6c2f63-60815dd-2f91e10",
    "widgetHtml": "<!-- ApiWidget: e6c2f63-60815dd-2f91e10 --><link href='https://www.treatstock.com/css/embed-user.css' rel='stylesheet' /><iframe class='ts-embed-userwidget' width='100%' height='650px' src='https://www.treatstock.com/api/v2/printable-pack-widget/?apiPrintablePackToken=e6c2f63-60815dd-2f91e10' frameborder='0'></iframe>",
    "parts": {
        "MP:1815136": {
            "uid": "MP:1815136",
            "name": "test.stl",
            "qty": 1,
            "hash": "7e02f089e3e508459c967de27c10d45c" 
        }
    }
}

id - is created printable pack identification

redir - is a link to access the created 3D model (a key is used for personal access). Note that this 3D model will only be valid for 24 hours.

widgetUrl - may be used to unsert into iframe with custom settings

widgetHtml - please insert this code into html page to show treatstock widget

Result for POST request with error example:

{
    "success": false, 
    "errors": {
        "file": [
            "No file" 
        ], 
   }
}

Edit

Retrieve minimum price for uploaded 3D model files

curl https://www.treatstock.com/api/v2/printable-packs/<id>?private-key=<api-token>

where <id> is the identification from the upload response

Result Example:

{
    "id": 223674,
    "model3d_id": 2965969,
    "created_at": "2019-07-29 10:33:03",
    "affiliate_price": "0.0000",
    "affiliate_currency": "USD",
    "calculated_min_cost": {
        "materialGroup": "PLA",
        "color": "White",
        "cost": 5.74
    },
    "success": true,
    "scaleUnit": "mm",
    "largestPartSize": {
        "length": 32.567,
        "width": 65.245,
        "height": 65.246,
        "measure": "mm" 
    },
    "parts": {
        "MP:1815145": {
            "uid": "MP:1815145",
            "name": "test.stl",
            "qty": 1,
            "hash": "7e02f089e3e508459c967de27c10d45c",
            "size": {
                "length": 32.567,
                "width": 65.245,
                "height": 65.246,
                "measure": "mm" 
            },
            "originalSize": {
                "length": 32.567,
                "width": 65.245,
                "height": 65.246,
                "measure": "mm" 
            },
            "weight": 27.5,
            "texture": {
                "color": "White",
                "materialGroup": "PLA" 
            }
        }
    }
}

Calculated cost is the minimum price for PLA material and White color.

Edit

Set scaling factors or quantity to API printable pack

Set scale unit Inch:

curl -X PUT -d scaleUnit=in https://www.treatstock.com/api/v2/printable-packs/<id>?private-key=<api-token>

 

or Cm:

curl -X PUT -d scaleUnit=cm https://www.treatstock.com/api/v2/printable-packs/<id>?private-key=<api-token>

 

or Mm:

curl -X PUT -d scaleUnit=mm https://www.treatstock.com/api/v2/printable-packs/<id>?private-key=<api-token>

 

change quantity:

curl -X PUT -d qty["MP:1815155"]=7 https://www.treatstock.com/api/v2/printable-packs/<id>?private-key=<api-token>

 

where <id> is the identification from the upload response

Result Example:

{
  "success": true,
}
Edit

Receive prices for different materials.

If you set printable package location, you can receive prices for different materials.

CURL Example:

curl  "https://www.treatstock.com/api/v2/printable-pack-costs/?printablePackId=<id>&private-key=e48b318e6dfa95718ef7f79e82af9de2" 

or

curl  "https://www.treatstock.com/api/v2/printable-pack-costs/?printablePackId=<id>&private-key=e48b318e6dfa95718ef7f79e82af9de2&location[ip]=83.69.106.68" 

or

curl  "https://www.treatstock.com/api/v2/printable-pack-costs/?printablePackId=<id>&private-key=e48b318e6dfa95718ef7f79e82af9de2&location[country]=US" 

or

curl  "https://www.treatstock.com/api/v2/printable-pack-costs/?printablePackId=<id>&private-key=e48b318e6dfa95718ef7f79e82af9de2&location[country]=US&&printerMaterialGroup=Pla&printerColor=Black" 

Result Example:

[
  {
    "printablePackId": 30,
    "materialGroup": "Plastic2",
    "printer": "US PS: Ditto-pro",
    "color": "Blue",
    "price": 4,
    "url":"https://www.treatstock.com/model3d/preload-printable-pack?packPublicToken=0...e&printerMaterialGroupId=6&printerColorId=90" 
  },
  {
    "printablePackId": 30,
    "materialGroup": "Plastic2",
    "printer": "US 6: MakerBot Replicator",
    "color": "White",
    "price": 2.53,
    "url":"https://www.treatstock.com/model3d/preload-printable-pack?packPublicToken=0...e&printerMaterialGroupId=7&printerColorId=91" 
  }
]

 

If you get {"reason": "not_calculated_yet", "success": false}, try the attempt again.

Edit

Place an order

To place an order you need to get providerId from "printable-pack-costs" API request.
POST request

POST https://www.treatstock.com/api/v2/place-order/create?private-key=746189ff56c6b27

with POST params:

{
    "printablePackId": "223682",
    "providerId": "1371",
    "comment": "Please print it as fast as possible.",
    "location": {
        "email": "test@company.com",
        "company": "Big company" 
    },
    "shippingAddress": {
        "country": "US",
        "zip": "20003",
        "city": "WASHINGTON",
        "state": "DC",
        "street": "727 C ST SE",
        "firstName": "Bill",
        "lastName": "Jobs" 
    },
    "modelTextureInfo": {
        "isOneMaterialForKit": "1",
        "modelTexture": {
            "color": "Green",
            "materialGroup": "PLA" 
        }
    }
}

 

Response:

{
    "orderId": 26448,
    "total": 132.02,
    "url": "https://www.treatstock.com/workbench/order/view/26448" 
}

 

Edit

Possible Errors:

The reply for non-valid delivery address:

{
    "errors": {
        "deliveryform-street": "This address is not supported by Treatstock Delivery Service. Please select another address. Reason:  Address not found." 
    }
}

 

The reply in case the system suggest its own (validated) variant of address instead of the given one:

{
    "validatedAddress": {
        "id": 58214,
        "contact_name": "User name",
        "country": "US",
        "state": "DC",
        "city": "WASHINGTON",
        "street": "10 4TH ST SE",
        "street2": null,
        "zip": "20003",
        "comment": null,
        "phone": null,
        "email": "test@test.com",
        "company": null
    }
}

 

The reply in case of 3D printing service is not able to print:

{
    "success": false,
    "message": "Specified provider cannot print with given details" 
}

 

The reply that informs about invalid request to API:

{
    "success": false,
    "message": "Please specify printablePackId." 
}

 

Edit

Receive possible printer material groups and colors.

If you need full list of possible material groups and colors. You can use this request.

CURL Example:

curl  "https://www.treatstock.com/api/v2/material-group-colors/?private-key=e48b318e6dfa95718ef7f79e82af9de2" 

Result Example:

[
  {
    "code": "Metals and Alloys",
    "description": "Aluminum, stainless steel, titanium, nickel and cobalt chromium are the available materials which are industrial grade metals that are laser sintered from metal powder.",
    "colors": [
      {
        "code": "Silver",
        "rgb": "230,232,230" 
      },
      {
        "code": "Gray",
        "rgb": "190,190,190" 
      }
    ]
  }
]

 

Edit

Limits

Limits for one api key.

7 connections at one time for GET
15 connections at one time for POST
30 connections at one time for PUT

One connection type independently with other types.

Edit

PHP examples

You can use api wrapper for our api: https://github.com/ceo-treatstock/apiv2

 

Need help? Contact technical support

Помогла ли вам эта информация?