Getting started

Get up and running with our API to start developing your own Shapeways integrations. Once you have registered and verified your Shapeways account you are ready to create your first app.


Create your first app

Create a new app to generate the API keys you’ll use to authenticate your API requests. You can access all apps associated with your account from the Manage apps page on the Shapeways Developers site.

Note: From the Manage apps screen, you can create, edit, or delete your applications.

Create an App


API user account authorization

Your application will need access to users’ Shapeways accounts to upload models and place orders. To get started, you’ll need to decide what type of access your app will need as the user authorization process is different.

Note: The Shapeways API uses 0Auth 2.0 to authenticate users. Learn more about OAuth 2.0.


1. How many accounts will need access to the API?

This is the simplest way to get started using the API. Choose this option if the API only needs access to your Shapeways account.

2. Requesting the API Access Tokens

In Manage apps > (Your App) copy your Client ID and Client Secret. Add them to the code below and make a POST request. Save this Access Token & Refresh Token (only for multiple user accounts flow) in a safe place.

  // Add your Client ID & Client Secret to the following code examples:
  $clientId = 'YOUR_CLIENT_ID';  // replace this
  $clientSecret = 'YOUR_CLIENT_SECRET';  // replace this
  $url = 'https://api.shapeways.com/oauth2/token';
  $params = ['grant_type' => 'client_credentials'];
  try {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_USERPWD, $clientId . ':' . $clientSecret);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    // showing response on screen
    print_r($response);

  } catch (\Exception $e) {
    // printing error on screen
    echo 'Exception: '. $e->getMessage();
  }
            
// Example API response
{
 "access_token": "ACCESS_TOKEN",
  "token_type": "bearer",
  "expires_in": 3600
}
          

Make an API test request

Let’s see if you can make a successful request from the API using our Materials endpoint.

// Add your access token to the code example
$accessToken = 'YOUR_ACCESS_TOKEN';
$url = 'https://api.shapeways.com/materials/v1';

try {
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HTTPHEADER,
    ['Authorization: Bearer ' . $accessToken,
     'Content-type: application/json']);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $response = curl_exec($ch);
  curl_close($ch);
  // printing API response on screen
  print_r($response);

} catch (\Exception $e) {
  // printing error on screen
  echo 'Exception: ' . $e->getMessage();
}

            
// Example API response
{
 "result":"success",
  "Materials":{
       "6":{
         "materialId":"6",
         "title":"White Natural Versatile Plastic",
         "supportsColorFiles":"0",
         "printerId":"5",
         "swatch":"https:\/\/www.shapeways.com\/rrstatic\/img\/materials\/plastic_wsf_white.jpg",
         "Restrictions":null
      },
...
  },
  "nextActionSuggestions":[]
}
          

Congratulations! Your ready to start integrating with the Shapeways API endpoints.


About refresh tokens

After an access token expires, using it to make a request from the API will result in an "Invalid Token Error". Your refresh token can be used to request a fresh access token from the authorization server.

// Add your Refresh token, Client id, & Client Secret to the following code examples:
$clientId = 'YOUR_CLIENT_ID';
$clientSecret = 'YOUR_CLIENT_SECRET';
$refreshToken = 'YOUR_REFRESH_TOKEN';

$url = 'https://api.shapeways.com/oauth2/token';
$headers[] = 'Authorization: Basic ' . $clientSecret;
$params = array(
 'grant_type' => 'refresh_token',
 'refresh_token' => $refreshToken,
 'client_id' => $clientId
);
try {
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  $response = curl_exec($ch);
  curl_close($ch);
  // printing API response on screen
  print_r($response);
} catch (\Exception $e) {
  // printing error on screen
  echo 'Exception: ' . $e->getMessage();
}