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.

401 error when Add Feature shape API is invoked

suma_raosuma_rao Member Posts: 4
Headers have access & secret key but when invoked through python code we receive 401. Please suggest.

Comments

  • Caden_ArmstrongCaden_Armstrong Member Posts: 169 PRO
    Can you post the API call body and URL? Hard to know the error without seeing what you are sending.

    Do other API calls work? Can you do a GET request?
    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • suma_raosuma_rao Member Posts: 4
    Endpoint : /api/partstudios/d/6f6d14f8facf0bba02184e88/w/66a5db71489c81f4893101ed/e/120c56983451157d26a7102d/features
    Payload: {'feature': {'type': 151, 'typeName': 'BTMSketch', 'message': {'entities': [{'message': {'entityId': '1', 'startPointId': '1.start', 'endPointId': '1.end', 'isConstruction': False, 'startParam': -0.01264495235582774, 'endParam': 0.02118421204388142, 'geometry': {'message': {'dirX': 1.0, 'dirY': 0.0, 'pntX': -0.0011842120438814163, 'pntY': 0.0}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'entityId': '4', 'startPointId': '4.start', 'endPointId': '4.end', 'isConstruction': False, 'startParam': -0.004046052694320679, 'endParam': 0.0009539473056793214, 'geometry': {'message': {'dirX': 0.0, 'dirY': 1.0, 'pntX': 0.020000000000000004, 'pntY': 0.004046052694320679}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'entityId': '7', 'startPointId': '7.start', 'endPointId': '7.end', 'isConstruction': False, 'startParam': -0.004906126279383902, 'endParam': 0.0050938737206161, 'geometry': {'message': {'dirX': -1.0, 'dirY': -1.224646799147353e-16, 'pntX': 0.015093873720616102, 'pntY': 0.004999999999999999}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'entityId': '10', 'startPointId': '10.start', 'endPointId': '10.end', 'isConstruction': False, 'startParam': -0.008136988243119975, 'endParam': 0.005692176156589183, 'geometry': {'message': {'dirX': -1.0, 'dirY': -1.2246467991473532e-16, 'pntX': -0.008136988243119975, 'pntY': 0.018000000000000002}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'entityId': '13', 'startPointId': '13.start', 'endPointId': '13.end', 'isConstruction': False, 'startParam': -0.003586958700345042, 'endParam': 0.004813041299654961, 'geometry': {'message': {'dirX': 1.2246467991473532e-16, 'dirY': -1.0, 'pntX': -0.013829164399709158, 'pntY': 0.01441304129965496}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'entityId': '16', 'startPointId': '16.start', 'endPointId': '16.end', 'isConstruction': False, 'startParam': -0.0016331166033130787, 'endParam': 0.008366883396686921, 'geometry': {'message': {'dirX': 1.0, 'dirY': 3.061616997868383e-16, 'pntX': -0.012196047796396079, 'pntY': 0.0096}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'entityId': '19', 'startPointId': '19.start', 'endPointId': '19.end', 'isConstruction': False, 'startParam': -0.009895742400450392, 'endParam': 0.00010425759954960437, 'geometry': {'message': {'dirX': -1.0, 'dirY': -1.2246467991473535e-16, 'pntX': -0.013724906800159552, 'pntY': 0.0063999999999999994}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'entityId': '22', 'startPointId': '22.start', 'endPointId': '22.end', 'isConstruction': False, 'startParam': -0.0031221635452005946, 'endParam': 0.0032778364547994014, 'geometry': {'message': {'dirX': 1.2246467991473532e-16, 'dirY': -1.0, 'pntX': -0.013829164399709156, 'pntY': 0.0032778364547994014}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'centerId': '25.center', 'entityId': '25', 'isConstruction': False, 'startParam': -2.745797307558978, 'endParam': 2.745797307558977, 'startPointId': '25.start', 'endPointId': '25.end', 'geometry': {'type': 115, 'typeName': 'BTCurveGeometryCircle', 'message': {'xCenter': 0.0, 'yCenter': 0.008, 'xDir': 1.0, 'yDir': 0.0, 'radius': 0.00415, 'clockwise': False}}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'message': {'entityId': '29', 'startPointId': '29.start', 'endPointId': '29.end', 'isConstruction': False, 'startParam': -0.0009999999999999992, 'endParam': 0.001999999999999999, 'geometry': {'message': {'dirX': 0.0, 'dirY': 1.0, 'pntX': 0.010000000000000002, 'pntY': 0.0059999999999999975}, 'type': 117, 'typeName': 'BTCurveGeometryLine'}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}, {'type': 158, 'typeName': 'BTMSketchPoint', 'message': {'entityId': '32', 'isConstruction': False, 'x': 0.00415, 'y': 0.007999999999999997}}, {'message': {'centerId': '33.center', 'entityId': '33', 'isConstruction': False, 'startParam': -3.4694469519536137e-16, 'endParam': 1.5707963267948966, 'startPointId': '33.start', 'endPointId': '33.end', 'geometry': {'type': 115, 'typeName': 'BTCurveGeometryCircle', 'message': {'xCenter': 0.0, 'yCenter': 0.008, 'xDir': 1.0, 'yDir': 0.0, 'radius': 0.010000000000000002, 'clockwise': False}}}, 'type': 155, 'typeName': 'BTMSketchCurveSegment'}], 'constraints': [], 'featureType': 'newSketch', 'name': 'No_Constraints_Sketch', 'parameters': [{'type': 148, 'typeName': 'BTMParameterQueryList', 'message': {'queries': [{'type': 138, 'typeName': 'BTMIndividualQuery', 'message': {'geometryIds': ['JEC'], 'hasUserCode': False}}], 'parameterId': 'sketchPlane', 'hasUserCode': False}}], 'suppressed': False, 'namespace': '', 'subFeatures': [], 'returnAfterSubfeatures': False, 'suppressionState': {'type': 0}, 'hasUserCode': False}}, 'serializationVersion': '1.1.18', 'sourceMicroversion': '57c52f87718e8008cce43b47', 'rejectMicroversionSkew': False, 'microversionSkew': False, 'libraryVersion': 1324}
    Headers: {'Authorization': 'Bearer XXX...:YYY..', 'Content-Type': 'application/json'}

  • Paul_J_PremakumarPaul_J_Premakumar Member, Onshape Employees Posts: 214
    Hi @suma_rao

     From the header it looks like you are using OAuth. I am not sure if this is your intent. If you haven't already checked it, please refer the API documentation on Authorization : https://onshape-public.github.io/docs/auth/apikeys/ . You can also use this Python client to manage the authentication : https://github.com/onshape-public/apikey

  • Caden_ArmstrongCaden_Armstrong Member Posts: 169 PRO
    I don't see anything at sticks out.

    - Is the sourceMicroversion correct? You can check it:
    https://cad.onshape.com/glassworks/explorer/#/Document/getCurrentMicroversion

    - You're doing a POST request right?

    - the document, workspace, and element ids are correct?

    - you have write permissions for that document?

    - your api keys have write permissions enabled in the dev portal?


    Is there more to the error message than just a 401 response? Usually there is a response message that gives a bit more detail.
    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
Sign In or Register to comment.