Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

help getting started with api

alan_baljeualan_baljeu Member, User Group Leader Posts: 111 ✭✭


I cannot find the API Explorer.  I found it in the store, subscribed, and it says it should be in OnShape in the + menu.  


Creating knowledge-driven design automation software, for molds, etc.
www.virtualmold.com

Comments

  • adrian_wasikadrian_wasik Member Posts: 6
    Hi Alan,

    you need to open a document first. Then follow the screenshot below:

  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    After you get the API explorer installed, you'll need to get a an access key and a secret key by registering through the dev portal 

    https://dev-portal.onshape.com/



  • alan_baljeualan_baljeu Member, User Group Leader Posts: 111 ✭✭
    Thank you.

    Is this by clicking "Create new OAuth Application"?  Do I want to make up form answers for a temporary/test application, and then I will get those two keys?  Do I need to pick an url on my website to get started?

    Once I get the keys how do I get a test page running to prove the system is available?
    Creating knowledge-driven design automation software, for molds, etc.
    www.virtualmold.com

  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    edited May 2020
    Without your own server, use the api explorer. With a server, have your client tell your server to authenticate with the onshape server. Have your client tell your server to request an onshape object and then have your server send it back to the client. Is this a mess? It's the rest api protocol used everywhere.

    There's 3 computers involved and you have to keep the code seperated for each computer. All the computers have a task. 

    I'm using nodejs, so it's really confusing, is it client code, server code or is it an onshape json object.

    Sounds like I need to create a video.


  • bill_schnoebelenbill_schnoebelen OS Professional, Developers, User Group Leader, csevp Posts: 109 PRO
    I started by getting the node examples working from the command line using Visual Studio Code: https://github.com/onshape-public/apikey

    There are two example sets; one Javascript and one python. I chose to use the node javascript vs the python. I did not know either language. Javascript is similar to featurescript. Javascript will also will help you in building a front end. Get this working and this will be the engine of your middleware.

    You can use node express as a middleware server. For example; to run getDocuments.js though a local middleware server. You make calls to the node express server [ https://www.youtube.com/watch?v=lY6icfhap2o] which then calls getDocuments.js which then calls app.js which then calls onshape.js. 

    To develop I initially use API Keys in Onshape. I then use 'REST Client' which is an add-on to Code to test my calls. Once everything is working I add them into my front end code. 

    Hopefully this does not totally confuse you! Just remember you need three things: 1. Client 2. Middleware (explained above) 3. Backend (onshape)
  • alan_baljeualan_baljeu Member, User Group Leader Posts: 111 ✭✭
    Thanks, I am understanding the concepts you lay out, but the details are another matter.  The video seems helpful.  Looks like I need to figure out how to get a middleware server running with node.js to make this happen.
    Creating knowledge-driven design automation software, for molds, etc.
    www.virtualmold.com

  • FdaFda Member Posts: 42 ✭✭
    I would like to know if someone uses the AWS (Amazon Web Services) Free Tier services to test the Onshape API?

    What if using "Ec2 instance" is the most appropriate?
  • bill_schnoebelenbill_schnoebelen OS Professional, Developers, User Group Leader, csevp Posts: 109 PRO

    I think the easiest way to test is run a node.js server locally.


    AWS gets very tricky quickly. Once your free tier runs out, AWS pricing is very hard to follow. After getting charged a large bill, I only use it for S3 now.


    If you need online testing, move your local server to heroku, digital ocean, or one of the other many hosts. Digital Ocean gives you server, static, and a mongodb for around $5/month. I push to git locally and pull from git on digital ocean.

  • FdaFda Member Posts: 42 ✭✭

    I think the easiest way to test is run a node.js server locally.


    AWS gets very tricky quickly. Once your free tier runs out, AWS pricing is very hard to follow. After getting charged a large bill, I only use it for S3 now.


    If you need online testing, move your local server to heroku, digital ocean, or one of the other many hosts. Digital Ocean gives you server, static, and a mongodb for around $5/month. I push to git locally and pull from git on digital ocean.

    Thank you @bill_schnoebelen

    I think I will use DigitalOcean.

    What I would like to do is create something like this http://configurator.cae.tech/

  • alan_baljeualan_baljeu Member, User Group Leader Posts: 111 ✭✭
    edited October 2020
    -
    Creating knowledge-driven design automation software, for molds, etc.
    www.virtualmold.com

  • bill_schnoebelenbill_schnoebelen OS Professional, Developers, User Group Leader, csevp Posts: 109 PRO
    They are doing that with Angular for the client and Java for the server. I never used either Angular nor Java so it is out of my wheel house. 

    My hunch is you can get it all running on a local machine. You don't need anything else. The client (Angular) would run at http://localhost:3000/ The server (Java) would run at  http://localhost:8080 The instructions on the git page should work. There is a lot of knowledge assumed in each instruction!

    What is your experience level?










  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    edited October 2020
    I'm using digitalocean, pretty straight forward and would recommend it. There's no voice support, only email, but it's good. I've only used email about 3 times and got meaningful answers, I was actually communicating with a knowledgeable person who understood my questions. They're knowledge base is very good and finding solutions to problems is straight forward. I've read 1,000's of articles on servers. Start a droplet and load ubuntu. I started with a prompt with nothing else. A blank slate.

    I also use amazon for email & pay. It's not as easy, not organized from beginning to end. Where do you start? It's easy to get lost and hard to find an answer.

    Bill, can you run nodejs from a local computer and talk to onshape? I thought you needed a secure socket otherwise onshape won't talk to you. I'm using let's encrypt on my server droplet which let's me talk to onshape securely (https). How are you encrypting your local computer? I've never really thought about encrypting my local computer.

    I'm running nginx which handles let's encrypt. , I run a nodejs instance over 127.0.0.0. Doing this allows nginx server caching.

    When I was researching this a few years ago, I went with:
    -digital ocean
    -unbuntu
    -nginx
    -nodejs

    And this came out:https://rustyshed.com/

    Can you get responses back from onshape with a computer running nodejs?
     


  • bill_schnoebelenbill_schnoebelen OS Professional, Developers, User Group Leader, csevp Posts: 109 PRO
    The short answer is Yes. 

    Here is where I started: https://github.com/onshape-public/apikey/tree/master/Node

    It took me a while to get it to work, but the instructions are actually straight forward. Just like riding a bike... I can do a video if you would like.

    I am not 100% sure how encryption is handled? It does use "crypto" to send the secret key.

    From there I took a MERN Stack class and placed the Onshape calls behind a secure Express server. I went with MERN because this keeps everything javascript which is also Featurescript. A MEAN Stack should do the same.



  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    I used the same code to request information from onshape except it's running on my server.

    I think you're right, crypto & https build that crypto-nonce allowing communication.

    It's interesting that it'll work with a local client/server & onshape.

    If you have the time, please put together a video on how you built up your local client/server. I'm interested.


  • bill_schnoebelenbill_schnoebelen OS Professional, Developers, User Group Leader, csevp Posts: 109 PRO
    Here you go: https://www.youtube.com/watch?v=eFIMKjFxMes

    If you don't want to type it all out, just download both githubs and npm install...
  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    Just finished your video, thanks so much for uploading. It's good to see a different way to do it.

    I've been working with amazon pay lately, which is the same thing as what Bill's doing with Onshape. One thing to note for those who are interested in what Bill is doing above, it's a new paradigm for programming the cloud and worth learning. Learning the Onshape API opens up a new world for engineers. A modern world.


  • bill_schnoebelenbill_schnoebelen OS Professional, Developers, User Group Leader, csevp Posts: 109 PRO
    I agree with the whole new world. Think custom niche products. The learning curve, however, is a whole lot steeper than featurescript. There are +3 language paths to do one thing each with a 6 month learning curve.

    What I have at the end is a boilerplate ERN Stack for the Onshape API. Express for server, React for client (this forum is React), Node for backend which talks to Onshape. I think this is the easiest starting point for someone new since everything is javascript. 

     


  • FdaFda Member Posts: 42 ✭✭
    Here you go: https://www.youtube.com/watch?v=eFIMKjFxMes

    If you don't want to type it all out, just download both githubs and npm install...



    Hi @bill_schnoebelen I wanted to congratulate you on the video. It helped me to understand the API a little more.

    But I wonder how to make the model be seen in the frontend of the web.
    ((( https://www.thingiverse.com/thing:33327 )))




    If it's not too much trouble and you have time, you could make a video...
  • bill_schnoebelenbill_schnoebelen OS Professional, Developers, User Group Leader, csevp Posts: 109 PRO
    Thanks Fda. I don't have time for a video right now.

    For that I would use a gltf. Separate it into three problems. 

    1. Display gltf in client. Use a threejs library. I like model-viewer. At this stage manually save a gltf and load it in the client.
    2. Export the glft from Onshape. You have to make three calls. 1. Get gltf ready 2. Is it ready? I just loop until I get a yes answer. 3. Download. This is explained in the Onshape documentation
    3. Bring it all together. Make a call from the client to the server to download gltf. You can follow export stl. You may have to change it to a post depending on how your getting the file. 

    You could also just use the stl file, but I have found these to be a pita for web display. gltf seems to be the dominant choice.



Sign In or Register to comment.