Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Using API key gives me '401 Unauthenticated API request' message
Pratik_Bajracharya
Member Posts: 10 ✭
Hi everyone, I am using my API key to use the Onshape API. I read the documents and saw few example so i was able to get successful response in few API. The weird thing is when is use the User API (i.e. /users/settings or users/sessioninfo) I get the response, but when I use any other API like get parts, I get a '401 Unauthenticated API' request message.
I have checked my API key scope and I have all the scope, does anyone know what I am doing wrong?
P.S i am using c#
Thank you,
Pratik
I have checked my API key scope and I have all the scope, does anyone know what I am doing wrong?
P.S i am using c#
Thank you,
Pratik
0
Comments
chadstoltzfus@premiercb.com
I'd use your credentials and the api explorer working 1st, then get your server code working. The api explorer only works on your stuff.
I have read this documentation, I will read it once again; see what I missed.
I have read this documentation, I will read it once again; see what I missed.
I have successfully get a response by using API key. The previous problem was because of my nonce and header, once I fixed this I got proper response.
Sadly I have stumble upon another problem; while using the 'Upload file to new element' API (/blobelements/d/:did/w/:wid) I get the same 401 message. It is a document that I have created, so not sure if it is permission problem.
Does POST method require any extra steps to generate the signature, something to do with the request body maybe?
It sounds like it's a post header configuration problem.
I'll look at my post request and see if there are others. Post headers are more than get headers.
It looks like content type is always added to header for either post or get, that makes sense.
My example code has one header for both post & get.
Does this look familiar to you, is this the example code you're using?
Yes I have seen something similar, but isn't it only if the Content-Type in header is empty? the api i am using requires the content type to be multipart/form-data. I am currently looking at: https://github.com/onshape-public/apikey/blob/master/python/apikey/client.py#L187 ; but still haven't got any success.
Here's the entire function
I remember going through this line by line.
I did debug this function and left the console output in the code.
This is nodejs or javascript.
Thanks a lot, I will try this and tell you if there is any progress.
Hey Billy I got an update,
1) I tired the upload Blob with API key using the nodeJs and it works fine!! the content type is kept as:
"multipart/form-data; boundary=<boundary_key>".
But when I try to replicate this with C# i get a 400 'bad request' error, I suspect my headers and signature are correct, its the matter of post body or the file I'm sending. I am sending a small STL file (same file is used for nodeJs method)
2) I tried the same Upload blob api; used the same code the only difference is that I used Oauth instead of the signature, this also works fine! So I am much more confused as to why I can't do the same thing with my API key method...
Thank you in advance