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

What's a complete API call to /partstudios/../featurescript look like?

johnsoggjohnsogg Member, Developers Posts: 14
edited December 2016 in FeatureScript
I think I have all the puzzle pieces for making an authenticated api call to evaluate a featurescript function, but I'm having trouble with cryptic error messages like "Error in input". I get the same error if I make the call via the API Explorer (using API key/secret) or from command line (using OAuth).

Here's the raw request with oauth key scrubbed (I can confirm it works using GET requests). I am hitting https://cad.onshape.com.

POST /api/partstudios/d/491cd510f26b33c86c3b1079/w/138c990145cb0318d3d0b43a/e/6c93e73cf1134e1ede7ece51/featurescript HTTP/1.1
Authorization: bearer <scrubbed>
Content-Type: application/json
Cookie: _u=websvc-c1ee691a
Host: cad.onshape.com
Connection: close
User-Agent: Paw/3.0.14 (Macintosh; OS X/10.12.1) GCDHTTPRequest
Content-Length: 167

{
  "script": "scribble",
  "queries": "",
  "serializationVersion": "1.1.9",
  "sourceMicroversion": "8ac4dc66d1e60d79bec44977",
  "rejectMicroversionSkew": "false"
I've tried variations on the queries field (using [] and {}, for example). I'm using the feature name "scribble" (see below) and the serializationVersion and sourceMicroversion out of the results of GET /partstudios/../features.

I have a FeatureScript installed on that document (as confirmed by GET /partstudios/../features). In case there's something wrong with the FS, here it is:

<div></div>
<div></div>
FeatureScript 455;
import(path : "onshape/std/geometry.fs", version : "455.0");

annotation { "Feature Type Name" : "scribble" }
export const scribble = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        // Define the parameters of the feature type
    }
    {
        return "42";
    });


The response from making the featurescript API call is:

HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 12 Dec 2016 18:23:03 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 91
Connection: close
On-Version: 1.55.16903.482b9b8ea9c5
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block

{
  "moreInfoUrl" : "",
  "code" : 9999,
  "message" : "Error in input",
  "status" : 400
}

Any ideas?

(Apologies for the formatting. The 'code' format doesn't work on render...)
Tagged:

Comments

  • Options
    mark_noyesmark_noyes Member, Onshape Employees, Developers Posts: 21
    First, you can find examples of complete featurescript evaluation calls in the developer portal help section (https://dev-portal.onshape.com/help) in the Feature list API section. In summary, the "script" field is expected to be a function definition where the functions arguments must be a Context and a map. The "queries" field in the post body is a list of topology references, which are supplied to the function in the map argument.

    Second, you appear to be trying to call a feature, but FeatureScript evaluation calls have no persistent side-effects, so you can't use this to alter your model. You can only call these functions to extract information, though you can feed that information back into features.

    Lastly, in your example you are making reference to custom featurescript code. That is not currently supported, but whatever logic you need can be supplied in the FeatureScript that you pass in. So, although your example is presumably not what you are really trying to achieve, the working example for your test case is:

    {
      "script" : "function (context is Context, queries is map) { return \"42\"; }",
      "queries" : [ ]
    }

  • Options
    johnsoggjohnsogg Member, Developers Posts: 14
    Thanks. I was treating this as more of an RPC thing (sending the function *name*) rather than sending the function *definition*. Yesterday I did try sending something similar to what you wrote, but it failed with the message "Error in input". Most likely I had some unescaped character, a newline maybe.
Sign In or Register to comment.