Help Center

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



1. To upload 3D model files, you should specify these requests:

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

affiliate_price - price

affiliate_currency - currency

files - 3d model files (.stl)

location[country] - (not required) - specify country. 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.

Request Examples

POST Request to upload file

CURL Example:
curl -F "files[]=@robots.stl" -F affiliate_price=1 -F affiliate_currency=USD -F location[ip]=8.8.8.8  https://www.treatstock.com/api/v2/printable-packs?private-key=<api-token>
OR
curl -F "files[]=@robots.stl" -F affiliate_price=1 -F affiliate_currency=USD -F location[country]=USA  https://www.treatstock.com/api/v2/printable-packs?private-key=<api-token>
or using files URL
curl -F "file-urls[]=http://mysite.com/MyModel.stl" -F affiliate_price=1 -F affiliate_currency=USD https://www.treatstock.com/api/v2/printable-packs?private-key=<api-token>
OR
GET https://www.treatstock.com/api/v2/printable-packs/create-by-url?private-key=YOURPRIVATEKEY&file-urls[]={url})

PHP Example:

$cFile = curl_file_create(realpath('./robots.stl'));
$post = ['affiliate_currency' => 'USD', 'affiliate_price' => '1', 'files[]' => $cFile, 'location[country]' => 'USA'];
$apiToken = '<api-token>'; // @todo replace with real api token$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.treatstock.com/api/v2/printable-packs?private-key=' . $apiToken);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);

$err = curl_error($ch);
curl_close($ch);
if ($err) {
    echo"cURL Error #:" . $err;
} else {
    print_r(json_decode($result, true));
}

Result Examples

Result for POST request is in JSON format:
{
   "success": true,
   "id": 1,
   "redir": "https://www.treatstock.com/api/v2/printable-packs?packPublicToken=1b43d75",
   "widgetUrl" : "https://www.treatstock.com/api/v2/printable-pack-widget/?apiPrintablePackToken=6914b",
   "widgetHtml": "<iframe width=100% height=650 src='https://www.treatstock.com/api/v2/printable-pack-widget/?apiPrintablePackToken=6914b' frameborder=0></iframe>",

}

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 insert into iframe with custom settings.

widgetHtml - please insert this code into html page to display Treatstock widget.

Result for POST request with error example:

{
    "success": false, 
    "errors": {
        "file": [
            "No file" 
        ], 
        "affiliate_price": [
            "Affiliate Price cannot be blank." 
        ]
   }
}

2. Retrieve minimum price for uploaded 3D model files:

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

where <id> is the identification from the upload response

PHP Example:

$privateKey = "<private-api-key>";
$packId = 5;
$result = json_decode(file_get_contents('https://www.treatstock.com/api/v2/printable-packs/' . $packId . '?private-key=' . $privateKey));
// or using public-upload-key$result = json_decode(file_get_contents('https://www.treatstock.com/api/v2/printable-packs/' . $packId . '?public-upload-key=' . $privateKey));
var_dump($result);

Result Example:

{
  "id": 30,
  "model3d_id": 141,
  "created_at": "2016-11-07 10:54:24",
  "affiliate_price": "12.0000",
  "affiliate_currency": "USD",
  "calculated_min_cost": {
    "materialGroup": "Plastic2",
    "color": "White",
    "cost": 2.53
  },  "scaleUnit": "mm",
  "largestPartSize": {
    "length": 827.202,
    "width": 1657.223,
    "height": 1657.248,
    "measure": "mm",
  },
}

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

Set scaling factors to API printable pack

Set scale unit to inches:

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>

 

where <id> is the identification from the upload response

PHP Example:

$post = ['scaleUnit' => 'in'];
$apiToken = '<api-token>'; // @todo replace with real api token$printablePackId = '<printable-pack-id>'; // @todo place here answer from create printable pack id$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.treatstock.com/api/v2/printable-packs/'.$printablePackId.'?private-key=' . $apiToken);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);

$err = curl_error($ch);
curl_close($ch);
if ($err) {
    echo"cURL Error #:" . $err;
} else {
    print_r(json_decode($result, true));
}

Result Example:

{
  "success": true,
}

3. Retrieve prices for different materials and colors:

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

CURL Example:

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

or

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

or

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

PHP Example:

$privateKey = "<private-api-key>";
$packId = 5;
$result = json_decode(file_get_contents('https://www.treatstock.com/api/v2/printable-pack-costs/?printablePackId=' . $packId . '&private-key=' . $privateKey));
var_dump($result);

Result Example:

[
    {
        "printablePackId": 59281,
        "materialGroup": "Resin",
        "printer": "Fuzion Code: Form 2",
        "providerId": 3163,
        "color": "White",
        "price": 120.04,
        "deliveryPrice": 0,
        "url": "....." 
    },
    {
        "printablePackId": 59281,
        "materialGroup": "Nylon",
        "printer": "3D Maker Duck: Wanhao i3 Duplicator",
        "providerId": 2822,
        "color": "Transparent",
        "price": 58.22,
        "deliveryPrice": 0,
        "url": "....." 
    } 
]

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


 

4. Set some params 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>

where <id> is the identification from the upload response

PHP Example:

<?php// Example: Change scale factor$post = ['scaleUnit' => 'in'];

// Example: Change Quantity$post = [
    'qty' => [
        'MP:417070' => 2
    ]
];
// Example: Change color and material for all model files$post = [
    'modelTextureInfo' => [
        'isOneMaterialForKit' => 1,
        'modelTexture'        => [
            'color'         => 'Green',
            'materialGroup' => 'Resin'
        ]
    ]
];
// Example: Change color and material for model3d part// Use https://www.treatstock.com/api/v2/material-group-colors/?private-key=<PRIVATE_KEY> to get material groups and colors list codes$post = [
    'modelTextureInfo' => [
        'isOneMaterialForKit' => 0,
        'partsMaterial'       => [
            'MP:417072' => [
                'color'         => 'Red',
                'materialGroup' => 'PLA'
            ]
        ]
    ]
];

$apiToken = '55c45f43e76a20beacfeae731cbc27dc'; // @todo replace with real api token$printablePackId = '59284'; // @todo place here answer from create printable pack id$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.treatstock.com/api/v2/printable-packs/'.$printablePackId.'?private-key=' . $apiToken);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);

$err = curl_error($ch);
curl_close($ch);
if ($err) {
    echo'cURL Error #:' . $err;
} else {
    var_dump($result);
}

Result Example:

{
  "success": true,
}

5. Additional API calls

Retrieve information about materials and colors:

Request Example:

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

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" 
      }
    ]
  }
]

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


5. Retrieve prices for Resin material without support calculations (based on area, volume, and width, height, length):

Required parameters:

country - country ISO code. For example US, GB, FR, DE etc.

private-key - your private key

width - 3D model width

height - 3D model height

length - 3D model length

volume - 3D model volume

area - 3D model surface area

color - specify color to be used

materialCode - (not required, default Resin) - material. (other examples: PLA, ABS, Nylon)

Request Example:

curl https://www.treatstock.com/api/v2/printable-pack-costs/price-initial?private-key=<private-key>&country=US&width=46&height=57&length=25&volume=15000&area=6000&color=Blue

If the color is not defined, White is used (you can change colors using code from availableMaterialsColors.colors.code).

If you want to switch from the default Resin material, specify parameter, for example:


curl https://www.treatstock.com/api/v2/printable-pack-costs/price-initial?private-key=<private-key>&country=US&width=46&height=57&length=25&volume=15000&area=6000&materialCode=PLA

Material code examples: PLA, ABS etc.

Response Example (offers sorted by price with printer information and price):

{
   "offers":[
      {
         "psPrinter":{
            "id":5,
            "title":"Wanhao i3 Duplicator",
            "positional_accuracy":"0.300" 
         },
         "userPrice":{
            "amount":53.13,
            "currency":"USD" 
         }
      }, ...
   ],
   "model3d":{
      "printerColor":{
         "id":1,
         "code":"Green",
         "rgbHex":"00cc33",
         "title":"Green" 
      },
      "printerMaterialGroup":{
         "id":5,
         "code":"Resin",
         "title":"Resin" 
      }
   },
   "availableMaterialsColors":[
      {
         "materials":[
            {
               "id":5,
               "code":"Resin",
               "title":"Resin" 
            }
         ],
         "colors":[
            {
               "id":1, "code" : "Green",
               "title":"Green",
               "rgb":"0,204,51" 
            },
            {
               "id":2, "code" : "Blue",
               "title":"Blue",
               "rgb":"0,102,204" 
            },
            {
               "id":92, "code": "Black",
               "title":"Black",
               "rgb":"63,63,63" 
            }
         ]
      }
   ]
}

 

Please note that these prices do not include support calculations.

The next step is to use the API to upload model and use "redir" link to redirect customer to treatstock.com, or use the widget html to show the embed iframe on your website.

6. 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:59281
printerMaterialGroup:Resin
providerId:3163
printerColor:White
location[country]:US
shippingAddress[zip]:20003
shippingAddress[city]:WASHINGTON
shippingAddress[state]:DC
shippingAddress[street]:13 3TH ST SE
shippingAddress[street2]:
shippingAddress[lastName]: Demos
shippingAddress[firstName]: Amerigos
shippingAddress[email]:customer@gmail.com
shippingAddress[company]:
shippingAddress[phone]:
comment: my comment

Response:

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

Possible Errors:

The reply for non-valid delivery address:

{
    "validateErrors": {
        "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,
        "firstName": "User name",
        "lastName": "Last 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." 
}

 


Public API Wrapper for PHP

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

Start example: php ./CreatePrintablePack.php

Need help? Contact technical support

Was this article helpful?