Using the API to pull all Cards from Guru but getting a time out error

  • 3 September 2020
  • 5 replies

Userlevel 1
Hey folks, we're trying to leverage the API to pull all cards in our knowledge base as we're building a find&replace MVP. We're using the search endpoint with a blank query to list all cards but it appears to be timing out. It stops printing at 8952 cards and that figure doesn't appear to bear any significance. Would you be able to shed any light on why that might be the case? I'll thread the code for reference.

5 replies

Userlevel 1
`def getCards(url):`
`payload = "{
`headers = {`
`'Authorization': 'Basic {{user token}}',`
`'Content-Type': 'application/json'`
`if url=="":`
`response = requests.request("GET", url, headers=headers, data = payload)`
`response = requests.request("GET", url, headers=headers)`
`jsonResponse = json.loads(response.text)`
`with open("cards.txt",mode='a') as f:`
`for card in jsonResponse:`
`if len(response.headers['Link']) > 0:`
`return response.headers['Link'].replace("<","").replace(">","").replace("; rel="next-page"","")`
`return False`
Userlevel 1
I initially tried to simply export all cards but the export never lands in my inbox. I suspect this is due to the size of our current KB. If all else fails, would you be able to send me an export of our entire knowledge base?
Thanks for flagging this @ruairi.murphy. I've pinged a couple of people to respond here, hang tight and we'll get you an answer on this ASAP.
Userlevel 1
Hey @ruairi.murphy! Is the authorization for the API call using your username? Or someone else? 8952 is a weird number to stop at because it should be pages of 50 at a time, so I'm wondering if you can see more cards than that but the account being used to authorize the calls has more limited access.
Userlevel 1
Hey Rob, another admin used their token for the API call but they have the same collection access as I do so that shouldn't be a factor 🤔