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.

Performing a search query through the API

shawn_crockershawn_crocker Member, OS Professional Posts: 865 PRO
When I do this, I have been able to get this end point to work.

https://cad.onshape.com/api/v5/documents?nodeId=1&q=_all:P0803&resourceType=filter

This seems to search through all of onshape and not just in my company or "my onshape".  Also, I cannot seem to get any other q parameters to work.  I try using state, or when and I get no items returned.  Is there a better endpoint to be using for this.  I'm also finding that the returned items do not really contain useful information like id's to construct a url or a premade url.  Anyone able to enlighten me on this.  I am not seeing anything about this in the glassworks browser.
Tagged:

Best Answer

  • pmdpmd Member, Developers Posts: 63 PRO
    Answer ✓
    I looked at some python code I wrote a few years ago using the old (pre-v5) API and it did:
     dest = f"/api/documents?q={searchterm}&filter=7&owner={company_id}"
    The old API Explorer explained that filter=7 meant restrict to company docs but the new glassworks browser does not seem to show this info.

Answers

  • pmdpmd Member, Developers Posts: 63 PRO
    Answer ✓
    I looked at some python code I wrote a few years ago using the old (pre-v5) API and it did:
     dest = f"/api/documents?q={searchterm}&filter=7&owner={company_id}"
    The old API Explorer explained that filter=7 meant restrict to company docs but the new glassworks browser does not seem to show this info.
  • shawn_crockershawn_crocker Member, OS Professional Posts: 865 PRO
    I was just supplied this link by @lougallo.  https://cad.onshape.com/glassworks/explorer/#/Document/search.  I'm not sure why I wasn't seeing this before when I was searching through the explorer.  I think I was accidentally assuming I was looking for GET requests.  Looks like parameters can be supplied into the body.

    {
      "documentFilter": 0,
      "foundIn": "ALL",
      "limit": 0,
      "luceneSyntax": true,
      "offset": 0,
      "ownerId": "string",
      "parentId": "string",
      "rawQuery": "string",
      "sortColumn": "string",
      "sortOrder": "string",
      "type": "string",
      "when": "ALL"
    }

    I haven't had time yet to experiment but I am getting strong feelings "ownerId": "string", is where the companies ID is to go.
  • shawn_crockershawn_crocker Member, OS Professional Posts: 865 PRO
    I have been experimenting and I have run into a problem.  Seems the return JSON contains an array called "items".  I'm not positive but it seems like each item is a document.  Each item contains an array called "searchHits".  I seems each search hit is an element/part in the document.  The problem I am not able to get around is, when I supply a string to the "rawQuery" part of the request body, I only getting results returned that contain that string in the element/part name.  I am trying to figure out how to get the search to return results from the element/part name and also from the part number.  Does anyone know how to accomplish this?  @caden_armstrong?
  • shawn_crockershawn_crocker Member, OS Professional Posts: 865 PRO
    So it seems I may have just messed around and discovered the answer.  in the rawQuery string, I put "_all:" and the search string I want and it seems to compare the string to everything.
Sign In or Register to comment.