Update featurescript parameters function using API

guillauem_d
guillauem_d Member Posts: 20 ✭✭

Hello there! 😀

I'm having trouble updating features using the API. I created a simple cube using a FeatureScript function

Now, I'd like to update the cube size using the API.

To do this, I tried using GET /partstudios/d/{did}/w/{wid}/e/{eid}/features to see what the feature payload looks like :

  "features": [
{
"type": 134,
"typeName": "BTMFeature",
"message": {
"featureType": "myFeature",
"featureId": "F1MLG2LKDU3BAgc_0",
"name": "My Feature 1",
"parameters": [
{
"type": 147,
"typeName": "BTMParameterQuantity",
"message": {
"units": "",
"value": 0.0,
"expression": "40 mm",
"isInteger": false,
"parameterId": "myLength",
"hasUserCode": false,
"nodeId": "ZFBzFaBd6ORWRpTF"
}
}
],
"suppressed": false,
"namespace": "ea5bb9f50cf0e2008a0791914::mbf9fb36657c1ca6e3a0387dd",
"subFeatures": [],
"returnAfterSubfeatures": false,
"suppressionState": {
"type": 0
},
"hasUserCode": false,
"nodeId": "tOEqMN8K4lG+dqq7"
}
}
],

However, when I tried updating the feature by submitting the payload to both:

  • POST /partstudios/d/{did}/w/{wid}/e/{eid}/features/updates
  • POST /partstudios/d/{did}/w/{wid}/e/{eid}/features/featureid/{fid}

It didn't work. I keep encountering errors, and I believe my main issue is related to the btType field—I'm not sure what value to use there.

Any help would be appreciated!

Answers

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 468 PRO

    btType is not required, but you are missing some other fields which are required:

    "serializationVersion": "string",
    "sourceMicroversion": "string"

    for custom features i think you also need libraryVersion, but I'm not 100% sure.

    It looks fine otherwise. When the request fails, usually there is an error message included with the response that can help solve theses kinds of issue.

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

    Thank you for your king help @Caden_Armstrong !

    So I tried this payload

      -d '{
    "feature": {
    "type": 134,
    "typeName": "BTMFeature",
    "message": {
    "featureType": "myFeature",
    "featureId": "F1MLG2LKDU3BAgc_0",
    "name": "My Feature 1",
    "parameters": [
    {
    "type": 147,
    "typeName": "BTMParameterQuantity",
    "message": {
    "units": "",
    "value": 0.0,
    "expression": "40 mm",
    "isInteger": false,
    "parameterId": "myLength",
    "hasUserCode": false,
    "nodeId": "ZFBzFaBd6ORWRpTF"
    }
    }
    ],
    "suppressed": false,
    "namespace": "ea5bb9f50cf0e2008a0791914::mbf9fb36657c1ca6e3a0387dd",
    "subFeatures": [],
    "returnAfterSubfeatures": false,
    "suppressionState": {
    "type": 0
    },
    "hasUserCode": false,
    "nodeId": "tOEqMN8K4lG+dqq7"
    }
    },
    "libraryVersion": 2491,
    "serializationVersion": "1.2.7",
    "sourceMicroversion": "8ed582034102bef1fc6bca42"
    }'

    I get

    {  "moreInfoUrl": "",  "message": "La fonction ne correspond pas.",  "code": 9999,  "status": 400}
    

    The message translated in english is "The function does not match".

    I also tried removing libraryVersion with no luck 😓