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.
Is there an example of a Request Body for the Update Element Metadata API method?
gary_clough057
Member Posts: 7 ✭
I am refactoring some of our code to remove the deprecated Elements methods with the new MetaData methods and I'm having trouble figuring out the format of the JSON for the Request Body. The API Explorer has the following definition but it's not clear to me how to set these JSON Values. I've been able to successfully Get the Element Metadata, just not Update it using the new method(s).
Request Body Template for Update Element Metadata (/metadata/d/:did/[wv]/:wv/e/:eid)
Request Body Template for Update Element Metadata (/metadata/d/:did/[wv]/:wv/e/:eid)
{
"items": "Object[]",
"items.0": "Object",
"items.0.href": "String",
"items.0.properties": "Object[]",
"items.0.properties.0": "Object",
"items.0.properties.0.propertyId": "String",
"items.0.properties.0.value": "Object"
}
Thanks in advance for any help and/or sample code.
-Gary
Thanks in advance for any help and/or sample code.
-Gary
0
Best Answers
-
mthiesmeyer Onshape Employees Posts: 115Hi @gary_clough057,
An example sequence of calls would be:
Get the metadata for the relevant element with /metadata/d/:did/[wv]/:wv/e/:eid. That call will return something of the form{"properties":[{"name":"Title 2","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d617","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":null,"maxLength":10000,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null},{"name":"Title 3","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d618","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":null,"maxLength":10000,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null},{"name":"Name","schemaId":"5ca34222b6be8f3d7cf36741","propertyId":"57f3fb8efa3416c06701d60d","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":1,"maxLength":256,"pattern":null},"editable":true,"editableInUi":true,"required":true,"defaultValue":null,"propertySource":0,"value":"Assembly 1"},{"name":"Exclude from BOM","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d61e","valueType":"BOOL","editable":true,"editableInUi":true,"required":false,"defaultValue":"false","validator":null,"uiHints":null,"propertySource":0,"value":false},{"name":"Description","schemaId":"5ca34222b6be8f3d7cf36741","propertyId":"57f3fb8efa3416c06701d60e","valueType":"STRING","uiHints":{"multiline":true},"validator":{"minLength":null,"maxLength":10000,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null},{"name":"Not revision managed","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d61d","valueType":"BOOL","editable":true,"editableInUi":true,"required":false,"defaultValue":"false","validator":null,"uiHints":null,"propertySource":0,"value":false},{"name":"Part number","schemaId":"5ca34c05b6be8f3d7cf36f4f","propertyId":"57f3fb8efa3416c06701d60f","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":null,"maxLength":50,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null},{"name":"Title 1","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d616","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":null,"maxLength":10000,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null},{"name":"Project","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d613","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":null,"maxLength":10000,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null},{"name":"Product line","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d614","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":null,"maxLength":10000,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null},{"name":"State","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d611","valueType":"ENUM","enumValues":[{"label":"In progress","value":"0"},{"label":"Pending","value":"1"},{"label":"Released","value":"2"},{"label":"Obsolete","value":"3"},{"label":"Rejected","value":"4"},{"label":"Discarded","value":"5"}],"editable":false,"required":true,"defaultValue":"0","validator":null,"uiHints":null,"propertySource":0,"value":"0"},{"name":"Vendor","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d612","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":null,"maxLength":10000,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null},{"name":"Revision","schemaId":"5ca1b68bd6edad03bba15676","propertyId":"57f3fb8efa3416c06701d610","valueType":"STRING","uiHints":{"multiline":false},"validator":{"minLength":null,"maxLength":10000,"pattern":null},"editable":true,"editableInUi":true,"required":false,"defaultValue":null,"propertySource":0,"value":null}],"href":"http://localhost.dev.onshape.com:8080/api/metadata/d/124c39f91fefea90caeb793a/w/9825a5f55dc0c2af0fd513d2/e/0366396ff2b7b90538166c91?configuration=default","elementType":1,"elementId":"0366396ff2b7b90538166c91","mimeType":"onshape/assembly"}
Now lets say you want to update the Assembly's name and description with metadata/d/:did/:wv/:wvId/e/:eid. An example json body would be:{ "items": [ { // designates which "thing" you want to update metadata for "href": "http://localhost.dev.onshape.com:8080/api/metadata/d/124c39f91fefea90caeb793a/w/9825a5f55dc0c2af0fd513d2/e/0366396ff2b7b90538166c91?configuration=default",<br> "properties": [ { "propertyId": "57f3fb8efa3416c06701d60d", "value": "My new Value" }, { "propertyId": "57f3fb8efa3416c06701d60e", "value": "My new Description" } ] } ] }
5 -
gary_clough057 Member Posts: 7 ✭Hi @mthiesmeyer,
Thanks for the quick reply and working like a dream. Makes it much easier to get/set Custom properties now...
Thanks again,
-Gary0
Answers
An example sequence of calls would be:
Get the metadata for the relevant element with /metadata/d/:did/[wv]/:wv/e/:eid. That call will return something of the form
Now lets say you want to update the Assembly's name and description with metadata/d/:did/:wv/:wvId/e/:eid. An example json body would be:
Thanks for the quick reply and working like a dream. Makes it much easier to get/set Custom properties now...
Thanks again,
-Gary
To be specific,to rename an element name in part studio do we need to have all fields updated in the requested body?
I tried to put the data(got from "get element metadata" in the requested body except "items.0.properties.0.value": "newname" and the server respon bad request. Later I tried with request body below & got response as Bad request & "properties" required. Please let me know if i am missing something to rename element name.
"items.0.properties.0.propertyId": "property id of name ",
I think you are getting confused due to our API documentation structure. The ".0" notation is just a way of saying "this is an array of things (usually objects), and if we take the first one as an example, this is what those things should look like". So "items.0.properties.0.value" is saying that "items" is an array of objects, where each object should have a field "properties" that is also an array of objects. Each object in that array should have a "propertyId" and "value" field.
So a post body to rename an element would look like:
{ "items": [ { "href": "https://cad.onshape.com/api/metadata/d/:did/w/:wid/e/:eid?configuration=default", "properties": [ { "propertyId": "57f3fb8efa3416c06701d60d",
"value": "newname" } ] } ]}
Does that make sense?
Best,
Mike
It means other items(encircled below) are not mandatory in post body?