Forums/Developer Program/General discussion

Ponoko API curl call examples

david ten have
posted this on January 15, 2012 13:25

Our API documentation is fairly extensive, but over the holiday break I fielded a number of queries from people who weren't able to get things working. So I thought I would add another angle. Even though I have provided examples below, please remember that http://www.ponoko.com/app-gateway/api-documentation will always be the authoritative reference for API calls and will be updated more frequently.

One of the changes we made early on in the API development was to add a simple auth method. This method uses an app_key and a user_key. This method is simple enough that you can test the Ponoko API using command line tools, rather than code. Testing using the command line is great because you get to see errors immediately - where your coding rigs might be swallowing these (as was happening for one developer). Early in your development work I highly recommend that you use the command line to test your calls. At any point where you think things are behaving weirdly - drop out of your code and sanity check using the command line.

There are two tools you need to become familiar with:

curl is a must have tool and should ship with most *NIXs these days. jazor is a nice to have tool that formats the JSON output of the Ponoko API nicely in terminal. All the examples below will pipe the output into jazor, if you don't want the nice formatting remove the '| jazor' from the examples.

In the examples below I have used your_app_key and your_user_access_key as place holders. You will need to replace them with your keys.  I have also retained certain keys (e.g.  2e9d8c90326e012e359f404062cdb04a) - they are there as examples only and to improve readability. You will need to replace them with data that is relevant to your app/task.

 

List available nodes

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/nodes | jazor

Show node details

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/nodes/2e9d8c90326e012e359f404062cdb04a | jazor

List the material catalog for a node

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/nodes/material-catalog/2e9d8c90326e012e359f404062cdb04a | jazor

Create a product

curl -F "app_key=your_app_key" \
-F "user_access_key=your_user_access_key" \
-F "name=Mega Lamp: The Return" \
-F "notes=some long note about the design" \
-F "ref=43261" \
-F "designs[][ref]=54321" \
-F "designs[][file_name]=front-face.eps" \
-F "designs[][uploaded_data]=@../sample_designs/exclamation_lamp/front-face.eps" \
-F "designs[][quantity]=2" \
-F "designs[][material_key]=80cef7d40fd340b795497c8d64e7e5fb" \
-F "designs[][ref]=54321" \
-F "designs[][file_name]=side_x2.stl" \
-F "designs[][uploaded_data]=@../sample_designs/exclamation_lamp/side-clean_x2.stl" \
-F "designs[][quantity]=5" \
-F "designs[][material_key]=7042b0f72cb9bc1fa5b07229c3f09c9c" \
-F "designs[][units]=mm" \
https://sandbox.ponoko.com/services/api/v2/products | jazor

Add design to product

curl -F "app_key=your_app_key" \
-F "user_access_key=your_user_access_key" \
-F "ref=999" \
-F "quantity=1"\
-F "material_key=7042b0f72cb9bc1fa5b07229c3f09c9c"\
-F "file_name=side_x4.stl" \
-F "uploaded_data=@../sample_designs/exclamation_lamp/side-clean_x2.stl" \
-F "units=mm" \
https://sandbox.ponoko.com/services/api/v2/products/bb05d9d5e1338299857833b2e11c0ae9/add-design | jazor

Update the details for an existing design

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
-d "ref=777" \
-d "quantity=1"\
-d "material_key=1b356299dae86a94d61c5aca28e4bad0"\
https://sandbox.ponoko.com/services/api/v2/products/bb05d9d5e1338299857833b2e11c0ae9/update-design/7124442945be51bddb54c4955f94fe6f | jazor

Replace a file for an existing design

curl -F "app_key=your_app_key" \
-F "user_access_key=your_user_access_key" \
-F "ref=777" \
-F "quantity=1"\
-F "file_name=front-face.eps" \
-F "uploaded_data=@../sample_designs/exclamation_lamp/front-face.eps" \
-F "material_key=1b356299dae86a94d61c5aca28e4bad0"\
https://sandbox.ponoko.com/services/api/v2/products/bb05d9d5e1338299857833b2e11c0ae9/update-design/7124442945be51bddb54c4955f94fe6f | jazor

Update the material for an existing design

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
-d "material_key=95ec4d183340e606fef9c3e4d55eec90" \
https://sandbox.ponoko.com/services/api/v2/products/bb05d9d5e1338299857833b2e11c0ae9/update-design/7124442945be51bddb54c4955f94fe6f | jazor

Delete a design

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
https://sandbox.ponoko.com/services/api/v2/products/4ea4757063130ac649f3fc974ddb6974/delete-design/0d8a32e7cf925c7d33128ee8ca0ac6a0 | jazor

List your available products

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/products | jazor

Show the details for a product

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/products/13d7a7285d628c8fec99e602085a3064 | jazor

Get the available shipping options

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
-d "products[][key]=3b5bec8b260ee21c8a39019244cc618a" \
-d "products[][quantity]=2" \
-d "delivery_address[address_line_1]=27%20DixonStreet" \
-d "delivery_address[address_line_2]=Te%20Aro" \
-d "delivery_address[city]=Wellington" \
-d "delivery_address[state]=" \
-d "delivery_address[zip_or_postal_code]=6021" \
-d "delivery_address[country]=New%20Zealand" \
--get https://sandbox.ponoko.com/services/api/v2/orders/shipping-options | jazor

Make a product

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
-d "ref=426" \
-d "products[][key]=3b5bec8b260ee21c8a39019244cc618a" \
-d "products[][quantity]=2" \
-d "shipping_option_code=ups_worldwide_expedited" \
-d "delivery_address[first_name]=Bob" \
-d "delivery_address[last_name]=Builder" \
-d "delivery_address[address_line_1]=27%20Dixon%20Street" \
-d "delivery_address[address_line_2]=Te%20Aro" \
-d "delivery_address[city]=Wellington" \
-d "delivery_address[state]=" \
-d "delivery_address[zip_or_postal_code]=6021" \
-d "delivery_address[country]=New%20Zealand" \
-d "delivery_address[phone_number]=9843759835" \
https://sandbox.ponoko.com/services/api/v2/orders | jazor

Check the status of your order

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/orders/status/da62462e6a003579ddc80ec178430495 | jazor

Trigger the next event (sandbox only)

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/orders/trigger-next-event/da62462e6a003579ddc80ec178430495 | jazor

List your orders

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/orders | jazor

Show the details for an order

curl -d "app_key=your_app_key" \
-d "user_access_key=your_user_access_key" \
--get https://sandbox.ponoko.com/services/api/v2/orders/68dd98cb0f9a75e025d66c684d23bb3e | jazor