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.
Why do I get 401 as API response when adding query string to request url?
lebenito
Member Posts: 15 ✭
I am using the client.api_client.request(method, url=url, query_params=params, headers=headers, body=payload) from the python client.
Other API get and post calls work just fine.
When I try to export an stl or get the mass properties of a part studio it works just fine until I put a query string in the request url for example the configuration,
but other query parameters also do not work. It says "message":"Unauthenticated API request", "status":401
Here is an example of a not working request url: https://cad.onshape.com/api/partstudios/d/c3c64dc4cc39570a7e58f079/w/cc1d338579f170714f7a792d/e/9266a7733c2327e4f1ab87c6/massproperties?massAsGroup=true&configuration=rad1=2inch
This works though when I put the link manually in my browser where I am logged into my Onshape account.
But my shadedView api call works with a query string. The query strings are formatted and encoded the exact same way, so I do not understand why this call works with query parameters but stl and mass properties do not.
For the stl I already got told a work around with translations, but I cant find such work around for the massproperties.
Why is that happening or is there maybe also a work around for the mass properties?
0
Answers
-
You are passing a poorly encoded string https://cad.onshape.com/api/partstudios/d/c3c64dc4cc39570a7e58f079/w/cc1d338579f170714f7a792d/e/9266a7733c2327e4f1ab87c6/massproperties?massAsGroup=true&configuration=rad1=2inch (removed the `amp;` portion and encoded the equals after the param string.)Lou Gallo
Sr. Director of Product Definition. UX and Support0 -
@lougallo I actually don't know how this & came in there but it was not actually in my api call ...My encoding works for the shaded View call and when I put it manually in my browser. But I still tried it now with this encoding:This call also gives me back 401 but works when I put it manually in the browser, So the encoding does not seem to be the issue right?
0 -
?configuration=rad1=1inch
is not a valid query string. Query strings need to follow the pattern <key>=<value>. For configurations to work properly, the configuration needs to be URI encoded.
Try?configuration=rad1%3D1inch
Jake RamsleyDirector of Quality Engineering & Release Manager onshape.com0 -
Hey @jakeramsley, Thank you for your answer.Yes that is exactly what I was trying before which also does not workEven when I just try ?massAsGroup=true or any other correct query string it won't work.

It works just without the query string.But for massProperties or stl (which I got told a work around already so is of no more worries) doesn't:This does not work (Only when I put it manually in my browser): https://cad.onshape.com/api/partstudios/d/c3c64dc4cc39570a7e58f079/w/cc1d338579f170714f7a792d/e/9266a7733c2327e4f1ab87c6/massproperties?configuration=rad1=2inch
0


