How do the query parameters in Action URLs work for Onshape Extensions

Hello,

I've been working on getting an Onshape extension working and have now managed to have the auth working. My next question to tackle is how to determine the documentId, workspace/version Id, and element Id of the page from which the extension is launched. The "Create an Extension" Onshape tutorial indicates that this can be done by supplying the query parameters to your action URL, such as https://ourserver.com/bom?documentId=${documentid}&elementId=${elementid}&partId={$partId}&partNumber={$partNumber}
. This does not seem to be working for me, however, with the ${} variables not being filled in. Is this still the correct way to do this, and if so, is there more information on what the other "Context" selections can supply? I notice the image included in the "Create an Extension" tutorial seems to be a bit old, the current selections for "Context" in an extension are provided in the image below.

Screenshot 2025-02-07 at 4.04.36 PM.png

Best Answers

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 468 PRO
    Answer ✓

    This is still the correct method for passing context information.

    There is a full list of options in the Action URL section of this page:
    https://onshape-public.github.io/docs/app-dev/extensions/

    I think they might be case sensitive, so ${documentId} and ${documentid} are different, with the first one being what I use in my apps.

    www.smartbenchsoftware.com --- Renaissance --- Kestrel -- SmartLink
    Experts in Onshape Automation - Custom Features and Integrated Applications
  • robert_chiodi
    robert_chiodi Member Posts: 12 ✭
    Answer ✓

    Thank you very much, that works! For anyone that comes across this, note that as of today the "Create an Extension" tutorial is wrong. It has

    https://ourserver.com/bom?documentId=${documentid}&elementId=${elementid}&partId={$partId}&partNumber={$partNumber}
    

    Which has both wrong capitalization inside the ${} and also the $ should be inside, e.g., {$NAME}.

Answers

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 468 PRO
    Answer ✓

    This is still the correct method for passing context information.

    There is a full list of options in the Action URL section of this page:
    https://onshape-public.github.io/docs/app-dev/extensions/

    I think they might be case sensitive, so ${documentId} and ${documentid} are different, with the first one being what I use in my apps.

    www.smartbenchsoftware.com --- Renaissance --- Kestrel -- SmartLink
    Experts in Onshape Automation - Custom Features and Integrated Applications
  • robert_chiodi
    robert_chiodi Member Posts: 12 ✭

    Thank you for the quick response, that worked great! For anyone else that comes across this, at the time of posting, the "Create an Extension" tutorial is partly wrong, as it has

    https://ourserver.com/bom?documentId=${documentid}&elementId=${elementid}&partId={$partId}&partNumber={$partNumber}
    

    Note that it should be {$NAME}, not ${NAME}, as shown in that tutorial, and that the capatilization is wrong in the example URL as well.

  • robert_chiodi
    robert_chiodi Member Posts: 12 ✭
    Answer ✓

    Thank you very much, that works! For anyone that comes across this, note that as of today the "Create an Extension" tutorial is wrong. It has

    https://ourserver.com/bom?documentId=${documentid}&elementId=${elementid}&partId={$partId}&partNumber={$partNumber}
    

    Which has both wrong capitalization inside the ${} and also the $ should be inside, e.g., {$NAME}.