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.
Updating Variables through Python API
alex_kagay
Member Posts: 2 ✭
in General
Hi,
I have started a project where I would like to do a GET to get the variables of a part, do a mathematical operation, and then POST the updated variables. I have gotten the GET and the mathematical operation, and am struggling to actually POST. My document is linked here.
I have obtained the url from the Glassworks API Explorer, but I am not sure what to use for the Request body or how to pass that into the POST statement.
When I use just the Glassworks API explorer, I get an error 404, not found.
My code for posting is:
I have started a project where I would like to do a GET to get the variables of a part, do a mathematical operation, and then POST the updated variables. I have gotten the GET and the mathematical operation, and am struggling to actually POST. My document is linked here.
I have obtained the url from the Glassworks API Explorer, but I am not sure what to use for the Request body or how to pass that into the POST statement.
When I use just the Glassworks API explorer, I get an error 404, not found.
My code for posting is:
fixed_url = '/api/v6/variables/d/did/w/wid/e/eid/variables'
fixed_url = self.fix_url(fixed_url,self.element.did,self.element.wvmid,self.element.eid,999)
params = {}
headers = {'Accept': 'application/vnd.onshape.v1+json; charset=UTF-8;qs=0.1', 'Content-Type': 'application/json'}
vars = json.loads(response.content)
value1 = "1.5 meter"
vars[0]["variables"][0]["value"] = value1
payload = {"content":vars}
response = requests.post(self.base+fixed_url,
params=params,
auth=self.api_keys,
headers=headers,
payload=payload)
I would appreciate any insight to what I am doing wrong, thank you!
I would appreciate any insight to what I am doing wrong, thank you!
0
Comments
To update variable features, I think you need to use the features endpoint.
https://cad.onshape.com/api/partstudios/d/{DID}/w/{WID}/e/{EID}/features/featureid/{FID}