{"id":19491098,"url":"https://github.com/jublo/shapecode-php","last_synced_at":"2026-05-13T01:32:36.167Z","repository":{"id":13852170,"uuid":"16549696","full_name":"jublo/shapecode-php","owner":"jublo","description":"A Shapeways API library in PHP.","archived":false,"fork":false,"pushed_at":"2016-08-10T00:10:34.000Z","size":283,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2026-04-01T08:36:18.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.jublo.net/projects/shapecode/php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jublo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-05T16:04:24.000Z","updated_at":"2016-08-10T00:10:33.000Z","dependencies_parsed_at":"2022-08-30T08:31:28.046Z","dependency_job_id":null,"html_url":"https://github.com/jublo/shapecode-php","commit_stats":null,"previous_names":["jublonet/shapecode-php"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/jublo/shapecode-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jublo%2Fshapecode-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jublo%2Fshapecode-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jublo%2Fshapecode-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jublo%2Fshapecode-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jublo","download_url":"https://codeload.github.com/jublo/shapecode-php/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jublo%2Fshapecode-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32963877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-12T23:30:32.555Z","status":"ssl_error","status_checked_at":"2026-05-12T23:30:18.191Z","response_time":102,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T21:15:45.107Z","updated_at":"2026-05-13T01:32:36.146Z","avatar_url":"https://github.com/jublo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"shapecode-php\n=============\n*A Shapeways API library in PHP.*\n\nCopyright (C) 2014-2016 Jublo Solutions \u003csupport@jublo.net\u003e\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n\n### Requirements\n\n- PHP 5.5.0 or higher\n- JSON extension\n- OpenSSL extension\n\n\nAuthentication\n--------------\n\nTo authenticate your API requests on behalf of a certain Shapeways user\n(following OAuth 1.0a), take a look at these steps:\n\n```php\nrequire_once ('shapecode.php');\nShapecode::setConsumerKey('YOURKEY', 'YOURSECRET'); // static, see 'Using multiple Shapecode instances'\n\n$sc = Shapecode::getInstance();\n```\n\nYou may either set the OAuth token and secret, if you already have them:\n```php\n$sc-\u003esetToken('YOURTOKEN', 'YOURTOKENSECRET');\n```\n\nOr you authenticate, like this:\n\n```php\nsession_start();\n\nif (! isset($_SESSION['oauth_token'])) {\n    // get the request token\n    $reply = $sc-\u003eoauth1_requestToken(array(\n        'oauth_callback' =\u003e 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']\n    ));\n\n    // store the token\n    $_SESSION['oauth_token'] = $reply-\u003eoauth_token;\n    $_SESSION['oauth_token_secret'] = $reply-\u003eoauth_token_secret;\n    $_SESSION['oauth_verify'] = true;\n\n    // redirect to auth website\n    header('Location: ' . $reply-\u003eauthentication_url);\n    die();\n\n} elseif (isset($_GET['oauth_verifier']) \u0026\u0026 isset($_SESSION['oauth_verify'])) {\n    // verify the token\n    $sc-\u003esetToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);\n    unset($_SESSION['oauth_verify']);\n\n    // get the access token\n    $reply = $sc-\u003eoauth1_accessToken(array(\n        'oauth_verifier' =\u003e $_GET['oauth_verifier']\n    ));\n\n    // store the token (which is different from the request token!)\n    $_SESSION['oauth_token'] = $reply-\u003eoauth_token;\n    $_SESSION['oauth_token_secret'] = $reply-\u003eoauth_token_secret;\n\n    // send to same URL, without oauth GET parameters\n    header('Location: ' . basename(__FILE__));\n    die();\n}\n\n// assign access token on each page load\n$sc-\u003esetToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);\n```\n\nUsage examples\n--------------\n\nWhen you have an access token, calling the API is simple:\n\n```php\n$sc-\u003esetToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); // see above\n\n$reply = (array) $sc-\u003eapi();\nprint_r($reply);\n```\n\nAdding a model to your cart is as easy as this:\n\n```php\n$reply = $sc-\u003eorders_cart('modelId=480903');\n```\n\nFor more complex parameters (see the [Shapeways API documentation](https://developers.shapeways.com/)),\ngiving all parameters in an array is supported, too:\n\n```php\n$params = array(\n    'modelId' =\u003e '480903',\n    'materialId' =\u003e 61,\n    'quantity' =\u003e 3\n);\n$reply = $sc-\u003eorders_cart($params);\n```\n\nWhen **uploading files to Shapeways**, just give the file path:\n\n```php\n$params = array(\n    'file' =\u003e 'in-some-folder/there-is/the-model.stl',\n    'fileName' =\u003e 'the-model.stl',\n    'hasRightsToModel' =\u003e 1,\n    'acceptTermsAndConditions' =\u003e 1,\n    'title' =\u003e 'My great model',\n    'description' =\u003e 'Lorem ipsum dolor sit amet',\n    'isPublic' =\u003e 1,\n    'isForSale' =\u003e 1,\n    'isDownloadable' =\u003e 0,\n    'tags' =\u003e array(\n        'ideas',\n        'miniatures',\n        'stuff'\n    )\n);\n$reply = $sc-\u003emodels($params); // required HTTP POST is auto-detected\n```\n\nMapping API methods to Shapecode function calls\n-----------------------------------------------\n\nAs you can see from the last example, there is a general way how the Shapeways\nAPI methods map to Shapecode function calls. The general rules are:\n\n1. Omit the version info in the function name.\n\n    Example: ```/v1``` is not part of the Shapecode function call.\n\n2. For each slash in a Shapeways API method, use an underscore in the Shapecode function.\n\n    Example: ```orders/cart/v1``` maps to ```Shapecode::orders_cart()```.\n\n3. For each underscore in a Shapeways API method, use camelCase in the Shapecode function.\n\n    Example: ```oauth1/request_token/v1``` maps to ```Shapecode::oauth1_requestToken()```.\n\n4. For each parameter template in method, use UPPERCASE in the Shapecode function.\n    Also don’t forget to include the parameter in your parameter list.\n\n    Example:\n    - ```materials/{materialId}/v1``` maps to ```Shapecode::materials_MATERIALID('materialId=73')```.\n\nHTTP methods (GET, POST, DELETE etc.)\n-------------------------------------\n\nNever care about which HTTP method (verb) to use when calling a Shapeways API.\nShapecode is intelligent enough to find out on its own.\nFor the automatic detection to work, be sure to use the correct required parameters,\nas outlined in the [Shapeways API documentation](https://developers.shapeways.com/).\n\nThe only exception to the above is the `DELETE models/{modelId}` method.\nTo call it, use the `delete=1` parameter. It will trigger the DELETE method,\nbut is not sent to the API.\n\nResponse codes\n--------------\n\nThe HTTP response code that the API gave is included in any return values.\nYou can find it within the return object’s ```httpstatus``` property.\n\nTo know whether your API call was successful, check the ```$reply-\u003eresult``` string,\nwhich either reads ```success``` or ```failure```.\n\nReturn formats\n--------------\nThe default return format for API calls is a PHP object.\nUpon your choice, you may also get PHP arrays directly:\n\n```php\n$sc-\u003esetReturnFormat(SHAPECODE_RETURNFORMAT_ARRAY);\n```\n\nThe Shapeways API natively responds to API calls in JSON (JS Object Notation).\nTo get a JSON string, set the corresponding return format:\n\n```php\n$sc-\u003esetReturnFormat(SHAPECODE_RETURNFORMAT_JSON);\n```\n\nUsing multiple Shapecode instances\n----------------------------------\n\nBy default, Shapecode works with just one instance. This programming paradigma is\ncalled a *singleton*.\n\nGetting the main Shapecode object is done like this:\n\n```php\n$sc = Shapecode::getInstance();\n```\n\nIf you need to run requests to the Shapeways API for multiple users at once,\nShapecode supports this as well. Instead of getting the instance like shown above,\ncreate a new object:\n\n```php\n$sc1 = new Shapecode;\n$sc2 = new Shapecode;\n```\n\nPlease note that your OAuth consumer key and secret is shared within\nmultiple Shapecode instances, while the OAuth request and access tokens with their\nsecrets are *not* shared.\n\nHow Do I…?\n----------\n\n### …walk through paged results?\n\nThe Shapeways API utilizes a technique called ‘paging’ for\nlarge result sets. Pages separates results into pages of no more than\n36 results at a time, and provides a means to move backwards and\nforwards through these pages.\n\nHere is how you can walk through paged results with Shapecode.\n\n1. Get the first result set of a paged method:\n```php\n$page = 1;\n$result1 = $sc-\u003emodels();\n```\n\n2. To navigate forth, increment the ```$page```:\n```php\n$page++;\n```\n\n3. If ```$nextCursor``` is not 0, use this cursor to request the next result page:\n```php\n    $result2 = $sc-\u003emodels(\"page=$page\");\n```\n\nIt might make sense to use the pages in a loop.  Watch out, though,\nnot to send more than the allowed number of requests\nper rate-limit timeframe, or else you will hit your rate-limit.\n\n### …know what cacert.pem is for?\n\nConnections to the Shapeways API are done over a secured SSL connection.\nShapecode-php checks if the Shapeways API server has a valid SSL certificate.\nValid certificates have a correct signature-chain.\nThe cacert.pem file contains a list of all public certificates for root\ncertificate authorities. You can find more information about this file\nat http://curl.haxx.se/docs/caextract.html.\n\n### …set the timeout for requests to the Shapeways API?\n\nFor connecting to Shapeways, Shapecode uses the cURL library, if available.\nYou can specify both the connection timeout and the request timeout,\nin milliseconds:\n\n```php\n$sc-\u003esetConnectionTimeout(2000);\n$sc-\u003esetTimeout(5000);\n```\n\nIf you don't specify the timeout, Shapecode uses these values:\n\n- connection time = 5000 ms = 5 s\n- timeout = 2000 ms = 2 s\n\n### …disable cURL?\n\nShapecode automatically detects whether you have the PHP cURL extension enabled.\nIf not, the library will try to connect to the Shapeways API via socket.\nFor this to work, the PHP setting `allow_url_fopen` must be enabled.\n\nYou may also manually disable cURL.  Use the following call:\n\n```php\n$sc-\u003esetUseCurl(false);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjublo%2Fshapecode-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjublo%2Fshapecode-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjublo%2Fshapecode-php/lists"}