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.

Is there an example of a Request Body for the Update Element Metadata API method?

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)
{
  "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

Best Answers

  • gary_clough057gary_clough057 Member Posts: 7
    Answer ✓
    Hi @mthiesmeyer,

    Thanks for the quick reply and working like a dream.   Makes it much easier to get/set Custom properties now...

    Thanks again,
    -Gary

Answers

  • gary_clough057gary_clough057 Member Posts: 7
    Answer ✓
    Hi @mthiesmeyer,

    Thanks for the quick reply and working like a dream.   Makes it much easier to get/set Custom properties now...

    Thanks again,
    -Gary
  • Kirankumar_ThimmegowdaKirankumar_Thimmegowda Member Posts: 28 PRO
    @mthiesmeyer ,
    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 ",
    "items.0.properties.0.value": "newname"
  • mthiesmeyermthiesmeyer Onshape Employees Posts: 115
    edited March 2020
    Hi @Kin,

    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
  • Kirankumar_ThimmegowdaKirankumar_Thimmegowda Member Posts: 28 PRO
    Hi Mike,
    It means other items(encircled below) are not mandatory in post body?

  • Kirankumar_ThimmegowdaKirankumar_Thimmegowda Member Posts: 28 PRO
    Hi Mike, Your suggestion works. Thank you.
  • Rafael_HefeleRafael_Hefele Member Posts: 1
    Hi all,
    I would like to change a property of a configured part. 
    So lets say I have configurations "klein" (small) and "gross" (large) for part JHD of a partstudio. I would like to assign each configuration an individual value for a custom property. I was trying "Update part metadata" like this:


    with body

    body = {
        "properties": [{"schemaId": "5e4178745afc7614fdff9c7b", "propertyId": "5e417874eb42121401baa1d5", "value": "A-test"}]  
    }

    to set the property for "klein".

    Unfortunately that didn't work. I also tried several other options but I could not get it to do what I want.

    I would appreciate any help, since I have been struggling with that for quite a bit.

    Thanks!

    Best,
    Rafael


Sign In or Register to comment.