This API allows to upload a 3D design file to the i.materialise server and returns a link to the 3D Print Lab to which your application can redirect your customers. Your customers will see the model in the 3D Print Lab. There they can select the material, finish, size, and quantity as well as get an instant price.
The 3D Print Lab Connection API is for users who have an application or website that creates 3D models. This API allows your application to upload directly the file to the i.materialise site, where your customers can order a 3D print then.
Do you have questions about how your server should upload a 3D model? Visiting our demo page will help you out.
We’ve developed a sandbox server, which is an isolated server (not hooked up to a payment system or production environment, allowing you to test the service without getting billed) to try out your code and integration with us. As the sandbox server is an isolated server, it requires different credentials than the production site.
The demo page of 3D Print Lab Connection API on sandbox server:
https://imatsandbox.materialise.net/api/demo/3d-print-lab-connection-api.htm
The sandbox and production server contain API demo pages which send well-formed API requests to our site.
The demo page of 3D Print Lab Connection API on production server:
https://i.materialise.com/api/demo/3d-print-lab-connection-api.htm
Try out your toolID on the demo page. Make sure you don’t mix up the toolIDs of the sandbox and the production site.
When using the 3D Print Lab Connection API, your application/website uploads a 3D model to the i.materialise web server using the HTTP POST method. Our server returns an HTTP response with a 302 status code. Your application/server then parses the Location header of this response and returns this URI (Uniform Resource Identifier) to the browser of your customer. The browser redirects the customer to either the 3D Print Lab page or to the error page in case of error.
The request should be done by using the HTTPS POST method using multipart/form-data encoding.
To post the request to production environment, enter this URL:
https://i.materialise.com/upload
To use API of the sandbox, use this link:
https://imatsandbox.materialise.net/upload
When you posts the request, our server sends a response with a 302 HTTP status code. The location header will contain an URL to which the user’s browser should be redirected. The URL will look like:
http://i.materialise.com/UploadRouter?modelID=1234-5678-1234-12345678&finishID=...
Your application forwards this link to the browser of your customer. Therefore, please make sure that the HTTP client is set up in such way that it doesn’t follow redirects sent back from the server in order to retrieve the correct URL.
The browser redirects the customer to the i.materialise 3D Print Lab. The link that will be shown in his/her browser will look like:
http://i.materialise.com/3Dprintlab/instance/<instance id>
In case an embedded version of the 3D Print Lab was requested, the URL in the customer’s browser will be slightly different.
To upload 3D models, you should be familiar with server side technologies like PHP, .NET or others, or using AJAX. You can also make requests to HTTP servers if the client is using HTTP.
In the request you should specify:
Parameter | Type | Required | Explanation |
---|---|---|---|
useAjax | Boolean | Yes | If checked, CORS requests are allowed. This checkbox corresponds to supportCors parameter in examples. |
forceEmbedding | Boolean | Yes | Parameter allows iframe embedding. |
plugin | String (36), required format: GUID | Yes | The toolID you received from us. |
file | File stream | Yes (if file URL is not specified) | Model file location path. |
fileUrl | Link to file | Yes (if File is not specified) | Model file location URL. |
scale | Decimal, separated by a period | No | Model scale factor, %. If parameter is not specified, scale =100 will be used by default. |
materialID | String (36), required format: GUID | No | ID of the model material. Can be found in the response of Materials catalog API. |
finishID | String (36), required format: GUID | No | ID of the model finishing. Can be found in the response of Materials catalog API. |
member_ID | String | No | It can be unique user’s ID in your application. Parameter allows us to login your customer automatically when he/she is redirected to our site for the second time. |
reference | String | No | Your Model reference. |
chkHideButtonsPanel | Boolean | No | Specify visibility for buttons panel with links: “Share your model”, “Upload a new model” and “Add from previously uploaded models”. |
currency | String (3) | No | Allows you to specify default currency.
Following currencies are supported: EUR/USD/JPY/GBP. |
languageCode | String (3) | No | Language of the site pages:
en/de/fr Default is EN. |
materialID
and finishID
can be found in the Materials Catalog API response.
The request parameter table shows that either you upload the file to the i.materialise server or you specify a URL where the server will download the file from.
<?php class ThreeDLabConnectionAPIClient { private $_uploadUrl = "https://i.materialise.com/upload"; private $postData; private $postFile; public function __construct($toolId) { $this->postData = array("plugin"=>$toolId); } public function upload($filePath=null, $fileUrl=null, $materialId=null, $finishId=null, $reference=null, $scale = null, $forceEmbedding=null, $supportCors=null) { if(isset($filePath) && isset($fileUrl)) throw new Exception("Please provide url or absolute path of the model file."); if (!isset($filePath) && !isset($fileUrl)) throw new Exception("Should provide only url or absolute path of the model file."); $request = $this->createRequest(); if(isset($filePath)) { $this->registerModel($filePath); } else { $this->registerFileUrl($fileUrl); } if(isset($scale)) { $this->registerScale($scale); } if(isset($reference)) { $this->registerReference($reference); } if(isset($materialId)) { $this->registerMaterial($materialId); } if(isset($finishId)) { $this->registerFinish($finishId); } if(isset($forceEmbedding)) { $this->registerForceEmbeddingFlag($forceEmbedding); } if(isset($supportCors)) { $request->addHeader(“X-Request-With”, “XMLHttpRequest”); } $url = $this->requestRedirectionUrl($request); return $url; } private function createRequest() { $request = new HttpRequest($this->_uploadUrl, HttpRequest::METH_POST); //...turning off autoredirects $request->setOptions(array("redirect" => 0)); return $request; } private function registerModel($file) { $this->postFile = $file; } private function registerFileUrl($fileUrl) { $this->postData["fileUrl"] = $fileUrl; } private function registerScale($scale) { $this->postData["scale"] = $scale; } private function registerReference($reference) { $this->postData["reference"] = $reference; } private function registerMaterial($materialId) { $this->postData["materialID"] = $materialId; } private function registerForceEmbeddingFlag($forceEmbedding) { $this->postData[“forceEmbedding”] = $forceEmbedding; } private function registerFinish($finishId) { $this->postData["colourID"] = $finishId; } private function requestRedirectionUrl($request) { if(isset($this->postFile)) { $request->addPostFile("file", $this->postFile); } $request->addPostFields($this->postData); $response = $request->send(); $url = $response->getHeader("location"); return $url; } } $client = new ThreeDLabConnectionAPIClient("[your ProductTypeID goes here]"); // ... url of the model file $modelFileUrl = "http://localhost:27018/Box.stl"; $redirectToUrl = $client->upload(null, $modelFileUrl); echo($redirectToUrl); ?>
using System; using System.IO; using System.Net.Http; using System.Net.Http.Headers; namespace iMaterialseSimpleUploadClient { public class ThreeDLabConnectionAPIClient { string _uploadUrl = "https://i.materialise.com/upload"; MultipartFormDataContent _uploadContent = new MultipartFormDataContent(); Guid _productTypeID; public ThreeDLabConnectionAPIClient(Guid productTypeID) { _productTypeID = productTypeID; } public string Upload(string filePath = null, string fileUrl = null, Guid? materialID = null, Guid? finishID = null, string reference = null, int? scale = null, bool forceEmbedding = false, bool supportCors = false) { if(filePath == null && fileUrl == null) throw new ArgumentNullException("Please provide url or absolute path of the model file."); if (filePath != null && fileUrl != null) throw new ArgumentException("Should provide only url or absolute path of the model file."); string uri; using (var client = CreateHttpClient()) { var uploadContent = new MultipartFormDataContent(); RegisterProductType(uploadContent, _productTypeID); if (filePath!=null) { RegisterModelFile(uploadContent, filePath); } else { RegisterFileUrl(uploadContent, fileUrl); } if (materialID.HasValue) { RegisterMaterial(uploadContent, materialID.Value); if (finishID.HasValue) { RegisterFinish(uploadContent, finishID.Value); } } if (reference != null) { RegisterReference(uploadContent, reference); } if (scale.HasValue) { RegisterScale(uploadContent, scale.Value.ToString()); } RegisterForceEmbeddingFlag(uploadContent, forceEmbedding); if(supportCors) { client.Headers.Add(“X-Request-With”, “XMLHttpRequest”); } uri = RequestRedirectionUrl(client, uploadContent); } return uri; } private string RequestRedirectionUrl(HttpClient client, HttpContent content) { var response = client.PostAsync(_uploadUrl, content).Result; return response.Headers.Location.ToString(); } private void RegisterScale(MultipartFormDataContent uploadContent, string reference) { AddStringContentToRequest("scale", reference, uploadContent); } private void RegisterReference(MultipartFormDataContent uploadContent, string reference) { AddStringContentToRequest("reference", reference, uploadContent); } private void RegisterProductType(MultipartFormDataContent uploadContent, Guid productTypeID) { AddStringContentToRequest("plugin", productTypeID.ToString(), uploadContent); } private void RegisterFinish(MultipartFormDataContent uploadContent, Guid finishID) { AddStringContentToRequest("finishID", finishID.ToString(), uploadContent); } private void RegisterForceEmbeddingFlag(MultipartFormDataContent uploadContent, bool forceEmbedding) { AddStringContentToRequest(“forceEmbedding”, forceEmbedding.ToString(), uploadContent); } private void RegisterMaterial(MultipartFormDataContent uploadContent, Guid materialID) { AddStringContentToRequest("materialID", materialID.ToString(), uploadContent); } private void RegisterFileUrl(MultipartFormDataContent uploadContent, string fileUrl) { AddStringContentToRequest("fileUrl", fileUrl, uploadContent); } private void RegisterModelFile(MultipartFormDataContent uploadContent, string filePath) { var fileStream = File.OpenRead(filePath); var streamContent = new StreamContent(fileStream); streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); uploadContent.Add(streamContent, "\"file\""); streamContent.Headers.ContentDisposition.FileName = "\"" + Path.GetFileName(filePath) + "\""; } private void AddStringContentToRequest(string contentKey, string contentValue, MultipartFormDataContent uploadContent) { var content = new StringContent(contentValue); content.Headers.ContentType = null; uploadContent.Add(content, string.Format("\"{0}\"", contentKey)); } private HttpClient CreateHttpClient() { var httpClient = new HttpClient( new HttpClientHandler { //...disabling autoredirects AllowAutoRedirect = false }); return httpClient; } } }
If you try to upload model with wrong toolID you’ll be redirected to error page with message :
Sorry. Error occured while processing your upload request.
If your model couldn’t be processed you’ll see message :
A processing error prevents us from offering an online price. Check our FAQs for possible solutions. If a solution can’t be found, request the price. We will check your model manually and contact you with an offline price.
and you’ll have possibility to create request for model checking and offline price calculation.