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

Performing a search query through the API

shawn_crockershawn_crocker Member, OS Professional Posts: 900 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: 64 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: 64 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: 900 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: 900 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: 900 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.
  • Christopher_Ace_CaoileChristopher_Ace_Caoile Member Posts: 8 PRO

    Hi Shawn,

    let payload = {    "documentFilter": 0,    "foundIn": "ALL",    "limit": 20,    "offset": 0,    "ownerId": {ownerId},    "parentId": "ALL",  "rawQuery": {myRawQuery},    "sortColumn": "modifiedAt",    "sortOrder": "desc",   "type": "document",    "when": "ALL"};

    Do you happen to know how do I modify this payload so that the search is based only on a specific date range?

  • shawn_crockershawn_crocker Member, OS Professional Posts: 900 PRO

    I did a bit of looking and I'm not certain this is possible. I do think it could be useful. Ask support if there might be some additional parameters that are not fully documented. I would probably just rely on my application logic to filter out what isn't needed. You can pull in 1000 items at a time which is a significant amount of results. The system does give a next code as well. You could run a little process that pulls a thousand results, then it filters for the items it needs and stores them to an array. Then it pulls and filters the next 1000 items and adds them into your storage variable. That's what I would do if I needed to process bulk amounts of search results between two modifiedOn dates. 😊

  • nick_brown567nick_brown567 Member Posts: 12

    To filter by a specific date range, replace "when": "ALL" [URL=https://eldfall-chronicles.com/en-si/collections/wargame-miniatures]tabletop miniatures[/URL]

  • shawn_crockershawn_crocker Member, OS Professional Posts: 900 PRO

    @nick_brown567 So, what is being used as the value for the "when" key? My understanding was that "when" referred to version types. So you can use "all" and the search will look for results within all available document versions. If you use "latest" it will only look for result within the most recent document versions. I could be wrong.

Sign In or Register to comment.