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.

Options

Assigning variables through the API Calls always results in 404 error

I am trying to use the API to assign a variable value through the API.
Even when using the api exporer (https://cad.onshape.com/glassworks/explorer/#/) I always get the following error:

{
  "message": "Not found.",
  "moreInfoUrl": "",
  "status": 404,
  "code": 0
}

I get get all the variables, and I have double checked that I have the correct name, and that I send valid JSON:
 [{
        "description":"The box depth",
        "name": "BoxDepth",
        "expression": "150 mm",
        "type":"LENGTH"
        }]

If I send invalid JSON, then I get a invalid JSON so I know that I am "in" and its not an authentication error.
Here is the generated curl, but with the ids changed

curl -X 'POST' \
  'https://cad.onshape.com/api/v6/variables/d/did/w/wid/e/eid/variables' \
  -H 'accept: application/json;charset=UTF-8; qs=0.09' \
  -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \
  -H 'X-XSRF-TOKEN: 9PisF02hcnhB/D6Dy2xurQ==' \
  -d '[
  {
    "description":"The box depth",
        "name": "BoxDepth",
        "expression": "150 mm",
        "type":"LENGTH"
  }
<span>]'</span>

Answers

  • Options
    Matt_ShieldsMatt_Shields Member Posts: 251 PRO
    What endpoint are you using?  I think you can only do POST requests to the variables endopoint for Variable Studios.  
  • Options
    caden_armstrong2caden_armstrong2 Member, User Group Leader Posts: 127 ✭✭✭
    When you make the call, are you replacing the did/wid/eid with the actual ids of your variable studio?
    Are you an enterprise user with a different url than cad.onshape? 
  • Options
    philip_kristoffersenphilip_kristoffersen Member Posts: 5
    I found the problem here. The EID (which I still don't know what is) is different if you are looking at designing a part and if you are in variable studio. By changing the EID to be the one for variable studio I am able to set variables.
  • Options
    Matt_ShieldsMatt_Shields Member Posts: 251 PRO
    Correct.  When you are in an Onshape document, the URL will look something like:

    https://cad.onshape.com/documents/123456789abcdef123456abc/w/123456789abcdef123456abc/e/123456789abcdef123456abc

    The 24-character string after /documents/ is the unique identifier for that document.
    The 24-character string after /w/ is the unique identifier for the workspace you are in.
    The 24-character string after /e/ is the unique identifier for the element (tab) you are in.
Sign In or Register to comment.