API: Find document by Part Number

How can i find a document by a provided part number? How would an api call look like?
thanks for any information

Answers

  • matthew_mueller537
    matthew_mueller537 Member Posts: 25 EDU
    Hello. This Github hosted python notebook should give a general solution using API keys - search for a list of documents, then search for all parts in each document for a matching part number. https://colab.research.google.com/github/PTC-Education/PTC-API-Playground/blob/main/Search_Documents_for_Part_ID.ipynb
  • shawn_crocker
    shawn_crocker Member, OS Professional Posts: 1,053 PRO
    @matthew_mueller537
    I too am trying to figure out why my api calls only seem to be returning results of items that have the rawQuery string in there name.  I am struggling to get the search endpoint to include results from name and from part number.  In the onshape search, if you type in a part number, the search results include items that have the search term in there name and in there part number.  Do you know how to do this with the API?

    PS the link you provided was way over my head.
  • matthew_mueller537
    matthew_mueller537 Member Posts: 25 EDU
    @shawn_crocker sorry I missed this message. The getDocuments API isn't as granular as the native Onshape search and I'm not aware of any way to search for a document by part number directly through the API. The code I shared first defines a function to get all of the parts in a document, then gets a list of 20 document ID's for a user, then gets all of the parts from each of the documents and checks if the part number you're searching for matches any of the part numbers in the document. So you can do what you want algorithmically with the API, but it will take multiple API's strung together.
  • shawn_crocker
    shawn_crocker Member, OS Professional Posts: 1,053 PRO
    @matthew_mueller537
    Thank you.  I forgot I had left this question.  I have found a solution.  I the "rawQuery" parameter in the body of the request I use this syntax:

    _all:partNumber

    Seems that this returns all documents that contain the text in "partNumber" in there name or part number meta data.  Doesn't seem to look inside of the description meta data which is strange.  In fact, I have found when looking at the native onshape search query in the browser URL, all the parameters shown there work when used in the rawQuery parameter.  Only difference is, everything is separated by a ":" and they need to be in pairs which is probably obvious.  I also use ":state:RELEASED:type:assembly" after my part number and search properly filters out for those parameters.