PHPackages                             jublonet/shapecode-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. jublonet/shapecode-php

ActiveLibrary[API Development](/categories/api)

jublonet/shapecode-php
======================

A Shapeways API library in PHP.

1.1.2(9y ago)0171LGPL-3.0+PHP

Since Feb 16Pushed 9y ago2 watchersCompare

[ Source](https://github.com/jublo/shapecode-php)[ Packagist](https://packagist.org/packages/jublonet/shapecode-php)[ Docs](http://www.jublo.net/projects/shapecode/php)[ RSS](/packages/jublonet-shapecode-php/feed)WikiDiscussions develop Synced 4d ago

READMEChangelog (5)Dependencies (2)Versions (8)Used By (0)

shapecode-php
=============

[](#shapecode-php)

*A Shapeways API library in PHP.*

Copyright (C) 2014-2016 Jublo Solutions

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see .

### Requirements

[](#requirements)

- PHP 5.5.0 or higher
- JSON extension
- OpenSSL extension

Authentication
--------------

[](#authentication)

To authenticate your API requests on behalf of a certain Shapeways user (following OAuth 1.0a), take a look at these steps:

```
require_once ('shapecode.php');
Shapecode::setConsumerKey('YOURKEY', 'YOURSECRET'); // static, see 'Using multiple Shapecode instances'

$sc = Shapecode::getInstance();
```

You may either set the OAuth token and secret, if you already have them:

```
$sc->setToken('YOURTOKEN', 'YOURTOKENSECRET');
```

Or you authenticate, like this:

```
session_start();

if (! isset($_SESSION['oauth_token'])) {
    // get the request token
    $reply = $sc->oauth1_requestToken(array(
        'oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
    ));

    // store the token
    $_SESSION['oauth_token'] = $reply->oauth_token;
    $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
    $_SESSION['oauth_verify'] = true;

    // redirect to auth website
    header('Location: ' . $reply->authentication_url);
    die();

} elseif (isset($_GET['oauth_verifier']) && isset($_SESSION['oauth_verify'])) {
    // verify the token
    $sc->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    unset($_SESSION['oauth_verify']);

    // get the access token
    $reply = $sc->oauth1_accessToken(array(
        'oauth_verifier' => $_GET['oauth_verifier']
    ));

    // store the token (which is different from the request token!)
    $_SESSION['oauth_token'] = $reply->oauth_token;
    $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;

    // send to same URL, without oauth GET parameters
    header('Location: ' . basename(__FILE__));
    die();
}

// assign access token on each page load
$sc->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
```

Usage examples
--------------

[](#usage-examples)

When you have an access token, calling the API is simple:

```
$sc->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); // see above

$reply = (array) $sc->api();
print_r($reply);
```

Adding a model to your cart is as easy as this:

```
$reply = $sc->orders_cart('modelId=480903');
```

For more complex parameters (see the [Shapeways API documentation](https://developers.shapeways.com/)), giving all parameters in an array is supported, too:

```
$params = array(
    'modelId' => '480903',
    'materialId' => 61,
    'quantity' => 3
);
$reply = $sc->orders_cart($params);
```

When **uploading files to Shapeways**, just give the file path:

```
$params = array(
    'file' => 'in-some-folder/there-is/the-model.stl',
    'fileName' => 'the-model.stl',
    'hasRightsToModel' => 1,
    'acceptTermsAndConditions' => 1,
    'title' => 'My great model',
    'description' => 'Lorem ipsum dolor sit amet',
    'isPublic' => 1,
    'isForSale' => 1,
    'isDownloadable' => 0,
    'tags' => array(
        'ideas',
        'miniatures',
        'stuff'
    )
);
$reply = $sc->models($params); // required HTTP POST is auto-detected
```

Mapping API methods to Shapecode function calls
-----------------------------------------------

[](#mapping-api-methods-to-shapecode-function-calls)

As you can see from the last example, there is a general way how the Shapeways API methods map to Shapecode function calls. The general rules are:

1. Omit the version info in the function name.

    Example: `/v1` is not part of the Shapecode function call.
2. For each slash in a Shapeways API method, use an underscore in the Shapecode function.

    Example: `orders/cart/v1` maps to `Shapecode::orders_cart()`.
3. For each underscore in a Shapeways API method, use camelCase in the Shapecode function.

    Example: `oauth1/request_token/v1` maps to `Shapecode::oauth1_requestToken()`.
4. For each parameter template in method, use UPPERCASE in the Shapecode function. Also don’t forget to include the parameter in your parameter list.

    Example:

    - `materials/{materialId}/v1` maps to `Shapecode::materials_MATERIALID('materialId=73')`.

HTTP methods (GET, POST, DELETE etc.)
-------------------------------------

[](#http-methods-get-post-delete-etc)

Never care about which HTTP method (verb) to use when calling a Shapeways API. Shapecode is intelligent enough to find out on its own. For the automatic detection to work, be sure to use the correct required parameters, as outlined in the [Shapeways API documentation](https://developers.shapeways.com/).

The only exception to the above is the `DELETE models/{modelId}` method. To call it, use the `delete=1` parameter. It will trigger the DELETE method, but is not sent to the API.

Response codes
--------------

[](#response-codes)

The HTTP response code that the API gave is included in any return values. You can find it within the return object’s `httpstatus` property.

To know whether your API call was successful, check the `$reply->result` string, which either reads `success` or `failure`.

Return formats
--------------

[](#return-formats)

The default return format for API calls is a PHP object. Upon your choice, you may also get PHP arrays directly:

```
$sc->setReturnFormat(SHAPECODE_RETURNFORMAT_ARRAY);
```

The Shapeways API natively responds to API calls in JSON (JS Object Notation). To get a JSON string, set the corresponding return format:

```
$sc->setReturnFormat(SHAPECODE_RETURNFORMAT_JSON);
```

Using multiple Shapecode instances
----------------------------------

[](#using-multiple-shapecode-instances)

By default, Shapecode works with just one instance. This programming paradigma is called a *singleton*.

Getting the main Shapecode object is done like this:

```
$sc = Shapecode::getInstance();
```

If you need to run requests to the Shapeways API for multiple users at once, Shapecode supports this as well. Instead of getting the instance like shown above, create a new object:

```
$sc1 = new Shapecode;
$sc2 = new Shapecode;
```

Please note that your OAuth consumer key and secret is shared within multiple Shapecode instances, while the OAuth request and access tokens with their secrets are *not* shared.

How Do I…?
----------

[](#how-do-i)

### …walk through paged results?

[](#walk-through-paged-results)

The Shapeways API utilizes a technique called ‘paging’ for large result sets. Pages separates results into pages of no more than 36 results at a time, and provides a means to move backwards and forwards through these pages.

Here is how you can walk through paged results with Shapecode.

1. Get the first result set of a paged method:

```
$page = 1;
$result1 = $sc->models();
```

2. To navigate forth, increment the `$page`:

```
$page++;
```

3. If `$nextCursor` is not 0, use this cursor to request the next result page:

```
    $result2 = $sc->models("page=$page");
```

It might make sense to use the pages in a loop. Watch out, though, not to send more than the allowed number of requests per rate-limit timeframe, or else you will hit your rate-limit.

### …know what cacert.pem is for?

[](#know-what-cacertpem-is-for)

Connections to the Shapeways API are done over a secured SSL connection. Shapecode-php checks if the Shapeways API server has a valid SSL certificate. Valid certificates have a correct signature-chain. The cacert.pem file contains a list of all public certificates for root certificate authorities. You can find more information about this file at .

### …set the timeout for requests to the Shapeways API?

[](#set-the-timeout-for-requests-to-the-shapeways-api)

For connecting to Shapeways, Shapecode uses the cURL library, if available. You can specify both the connection timeout and the request timeout, in milliseconds:

```
$sc->setConnectionTimeout(2000);
$sc->setTimeout(5000);
```

If you don't specify the timeout, Shapecode uses these values:

- connection time = 5000 ms = 5 s
- timeout = 2000 ms = 2 s

### …disable cURL?

[](#disable-curl)

Shapecode automatically detects whether you have the PHP cURL extension enabled. If not, the library will try to connect to the Shapeways API via socket. For this to work, the PHP setting `allow_url_fopen` must be enabled.

You may also manually disable cURL. Use the following call:

```
$sc->setUseCurl(false);
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~181 days

Recently: every ~223 days

Total

6

Last Release

3613d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6348321?v=4)[Joachim Rütter](/maintainers/mynetx)[@mynetx](https://github.com/mynetx)

---

Top Contributors

[![mynetx](https://avatars.githubusercontent.com/u/6348321?v=4)](https://github.com/mynetx "mynetx (107 commits)")[![anasAsh](https://avatars.githubusercontent.com/u/1830449?v=4)](https://github.com/anasAsh "anasAsh (1 commits)")

---

Tags

apiprintingmodeling3dshapeways

### Embed Badge

![Health badge](/badges/jublonet-shapecode-php/health.svg)

```
[![Health](https://phpackages.com/badges/jublonet-shapecode-php/health.svg)](https://phpackages.com/packages/jublonet-shapecode-php)
```

###  Alternatives

[jublonet/codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.

778880.2k10](/packages/jublonet-codebird-php)[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.5k10](/packages/helsingborg-stad-municipio)[printnode/printnode-php

Connect any printer to your application with PrintNode Client and easy to use JSON API

921.2M4](/packages/printnode-printnode-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
