3 Replies Latest reply on Mar 6, 2014 9:10 AM by craig.mcclanahan

    Help Using REST API to Get Info on All Content

    chrisbrown

      Hi. I'm new to Jive and totally new to REST and am trying to accomplish a specific query using the contents service. What we need is a list of all content titles, location, and visibility. Specifically we're looking for content that is posted in a personal space but is visible to all.

       

      I'm tinkering with Python to call the service, but I'm not quite sure if it's possible to return all content in one response rather than just the first 25.

       

      import requests
      
      response = requests.get('https://my.url.com/api/core/v3/contents', verify=False,
                              auth=('<username>', '<password>'))
      
      

       

      Can anyone help me with the ?filter syntax? The end result ideally would be a file listing the title, location, and visibility of all content in the system.

       

      Bonus question: How do I strip the "throw...;" string from the beginning of the response in Python?

        • Re: Help Using REST API to Get Info on All Content
          chrisbrown

          Here's what I've come up with, but it's bombing out with a 'No JSON object could be decoded' error before getting all the results. It bombs at 2000, and I'm pretty sure there are more than 2100 results.

           

          import re
          import json
          import requests
          
          index = 0
          types = "(discussion)"
          fields = "parentPlace,visibility"
          f = open('out.xml', 'w', encoding='utf-8')
          
          while True:
              url = 'https://myurl.com/api/core/v3/contents' + \
                    '?filter=type' + types + '&fields=' + fields + '&count=100&startIndex=' + str(index)
          
              response = requests.get(url, verify=False, auth=('username','password''))
          
              response = re.sub(r"^throw.*;\s*", "", response.text)
          
              result = json.loads(response)
          
              for x in result['list']:
                  f.write(str(x) + '\n')
          
              index += 100
          
              if result['itemsPerPage'] < 100:
                  break
          
          f.close()