12 Replies Latest reply on Apr 27, 2017 8:02 AM by Jonathan Block

    Can I use the API to Create and Configure a Place?

    Jonathan Block

      As we build out our Jive cloud instance, I'm looking into the process of fully automating place creation.  The major use case is to set up places for potentially thousands of company projects per year.  Note that these aren't Jive Projects, but would rather map to Groups or Spaces.  We don't want to leave it up to the individual project teams to figure out how to manually effect a consistent baseline place setup, and we really don't want everyone making up their own way of doing it.

       

      I'm working my way through the API, and so far have made some good progress (basic steps below for anyone interested).  But I've now hit a significant wall:  I can't programmatically apply a template to the default activity page, and I don't seem to be able to apply a template to the place itself.  If I create a new place and then manually update the default page, even without changing anything, the page becomes visible to the API (/places/<id>/pages).  Without that manual intervention that API query comes up empty.  I really hope this is a bug or I'm totally missing something, because this is a dead-in-the-water obstacle.

       

      I'm also curious about the ability to enable external storage using our pre-configured external storage setup.  I see an unanswered question about that (Creating place via v3 api with external storage.), so I'm a bit pessimistic that there's a good answer to be found on this point.

       

      For reference, here are the API endpoints I'm using so far:

      • Check if the target space already exists, and, if not, grab the intended parent space:  GET /places
      • Grab the intended template:  GET /placeTemplates
      • Grab the intended place category:  GET /placeTopics
      • Create the place:  POST /places

      {

        `"type`" : `"space`",

        `"name`" : `"<name>`",

        `"parent`" : `"<API reference to the parent place>`",

        `"displayName`" : `"<url slug based on the name>`",

        `"description`" : `"<description>`",

        `"status`" : `"Active`",

        `"visibleToExternalContributors`" : false,

        `"tags`" : [`"project`",`"project <identifier>`"],

        `"placeTopics`" : [`"<place category>`"]

      }

      • Get the new place's pages (should only be the default Activity page):  GET /places/<placeID>/pages
        Response is empty unless the page has already been edited and saved manually.
      • Apply the template to the place:  PUT /pages/<pageID>

      {

          `"template`" : {

              `"id`" : `"<template ID>`",

              `"name`" : `"<template name>`"

          }

      }

      Unable to test this step due to errors in the previous step.  Syntax could be completely wrong.

       

      Intended additional steps:

      • Configure tiles within the template
      • Enable external storage (we can live without this if necessary)
      • Identify and assign place admins
      • In some cases, lock down access to a security group (created separately)

       

      I'd appreciate any guidance available on the issues I've already encountered and any others you think I'm about to run into.

        • Re: Can I use the API to Create and Configure a Place?
          Scott A Johnson

          Hi Jonathan,

           

          The activity page is created "lazily". I noticed this while helping a client do the same thing, creating spaces programatically. I believe if you make a simple get request to the place url or it's activity page, you the activity page should be generated. You should be able to do this through your script.

           

          For your other steps, configuring tiles on the page is fairly easy, especially if it's going to be pretty standard across the spaces. Not sure about ext-storage, haven't played with that before. Assigning social group admins should work through the members endpoint, spaces' admins are configured through security groups, so this is more of a manual step. Locking down access to security groups is something that I'm afraid is not possible right now. I don't think there is a service to alter security group associations with spaces, so this will need to be done manually.

           

          Hope that helps,

          Scott

          3 people found this helpful
            • Re: Can I use the API to Create and Configure a Place?
              Jonathan Block

              Very helpful, thanks.  I'll see if I can make that GET request without getting tangled up in our SSO integration.

               

              I think I see what you mean about the inability to assign any permission-related settings to a place via API.  I'm terribly disappointed, and can't understand how there can be gaps like this in a commercial product API.  We'll need to pester our admins programmatically for every space that gets set up, so they can go in and tweak the permissions appropriately.  Ick.

              • Re: Can I use the API to Create and Configure a Place?
                Jonathan Block

                I'm going in circles trying to figure out how to "make a simple get request to the place url".  I can of course make such a request, but it's intercepted by the Jive login mechanism.  My attempts at programmatically feeding back the right field values in an interactive session aren't working.  I can keep hammering at it, but if you happen to have working code to share for that step, I'd appreciate a chance to look at it.

                  • Re: Can I use the API to Create and Configure a Place?
                    Scott A Johnson

                    Are you unable to use the same credentials you used to create the place through the api? It seems like it could be as simple as calling something like:

                     

                    $.get('[jive-instance]/community/new-place')
                    
                    1 person found this helpful
                      • Re: Can I use the API to Create and Configure a Place?
                        Jonathan Block

                        I didn't try using the API authentication to make the call.  Checking...

                          • Re: Can I use the API to Create and Configure a Place?
                            Jonathan Block

                            Yep, that was it.  In PowerShell terms, it's

                             

                                 Invoke-WebRequest $url -Headers $validAuthHeadersForAPIUse

                             

                            Thanks again.

                            1 person found this helpful
                              • Re: Can I use the API to Create and Configure a Place?
                                Jonathan Block

                                Continuing the saga, while this was the correct way to request a web page with appropriate authorization, it was not the right way to instantiate an activity page.

                                 

                                I (finally) found an explicit reference to the issue in Pages API Overview (the existence of which page was unfortunately not discoverable from the API docs):

                                One additional note about activity pages: If you create a place using the UI, it will automatically create an activity page. If you create a place with the REST API, it will not create an activity page automatically. However, if you browse to a place created via the REST API, you will always see an activity page — if you did not create the activity page manually, a default page is generated on the fly. You can still manually create an activity page for this place using the API and customize it as you want.

                                 

                                So, my next step is to try explicitly creating an activity page via API.

                                1 person found this helpful
                                  • Re: Can I use the API to Create and Configure a Place?
                                    jgoldhammer

                                    Hi Jonathan,

                                    can you share any result here? Your approach sounds interesting and I am interested in your findings and solution.

                                     

                                    Thanks

                                    Jens

                                    • Re: Can I use the API to Create and Configure a Place?
                                      keithteach

                                      Hi Jonathan,

                                      What you are doing seems very similar to what we have built. I have automated private space creation using activity pages and loading up specific tiles, all using Powershell. Permissions still need to be set manually though. Have you tried to upload any files yet?

                                        • Re: Can I use the API to Create and Configure a Place?
                                          jgoldhammer

                                          Wow, Sounds Great. Can you Share??

                                            • Re: Can I use the API to Create and Configure a Place?
                                              keithteach

                                              This is Powershell code used to create spaces and set them the way we want. If anyone has figured out how to put a .pdf file into a space using the api please let me know!

                                               

                                              #some variables to be set from import for creating space - others hardcoded

                                                          $JivePrivateSpacename = $JiveSpacename
                                                          $JivePrivateSpaceDisplayName = $JiveSpaceDisplayName
                                                          $jivetype = "space"
                                                          $jivecontenttypes = '[ "documents", "discussions" ]'
                                                          $jivebody = '{
                                                                  "name" : "' + $JivePrivateSpacename + '",
                                                                  "displayName" : "' + $JivePrivateSpaceDisplayName + '",
                                                                  "type" : "' + $jivetype + '",
                                                                  "contentTypes" : ' + $jivecontenttypes + '
                                                               }'
                                                   

                                              #Create the space

                                                          $results = Invoke-WebRequest -uri $parenturlspace  -headers $JiveHeaders -ContentType: application/json -Method POST  -Body $jivebody

                                              # After creating space need the place and page id's for updating

                                                          $convertedjson =  $results | ConvertFrom-Json
                                                          $jiveplaceid = $convertedjson.placeID
                                                          $jivepageid = $convertedjson.id
                                                          $jiveplaceidURL = "https://<YourUrl>/api/core/v3/places/" + "$jiveplaceid"

                                              # Set default activity page

                                                          $defaultActivityPage = '{
                                                              "displayOrder": 0,
                                                              "layout": "activity",
                                                              "name" : "a",
                                                              "pageType": "place",
                                                              "parent": "https://sandbox.jiveon.com/api/core/v3/places/' + $jiveplaceid + '",
                                                              "tiles": [
                                                                      ],
                                                                  "type": "page",

                                               

                                                                                  }'     

                                                          $SetDefaultActivitypage = Invoke-WebRequest -uri $jivepagesurl  -headers $JiveHeaders -ContentType: application/json -Method POST -Body $defaultactivitypage

                                              #Create new page with tile

                                                          $Jivefalse = 'false'
                                                          $JiveTRUE = 'true'

                                                          $jivepagesbody = '{
                                                                    
                                                                  "displayOrder": 0,
                                                                  "layout": "wide_narrow",
                                                                  "name": "Overview",
                                                                  "pageType": "place",
                                                                  "parent": "' + $jiveplaceidURL + '",
                                                                  "tiles": [
                                                                       {
                                                                          "column": 2,
                                                                          "config": {},
                                                                          "definition": "https://<YourUrl>/api/core/v3/tileDefs/1093"

                                                                      },
                                                                      {
                                                                          "column": 1,
                                                                          "config": {
                                                                                  "action": {
                                                                                              "text": "",
                                                                                              "url": ""
                                                                                              },
                                                                                  "content": [
                                                                                              {
                                                                                              "id": 2562,
                                                                                              "text": "Welcome",
                                                                                              "type": "document"
                                                                                               }
                                                                          ],
                                                                  "suppressOutcomes": true,
                                                                  "suppressSocial": true,
                                                                  "suppressTitle": true,
                                                                  "title": "WELCOME TO YOUR PRIVATE SPACE"
                                                              },
                                                              "definition": "https://<YourUrl>/api/core/v3/tileDefs/1006"
                                                              },
                                                                  {
                                                                  "column": 1,
                                                                  "config": {
                                                                  "browseQuery": "filterID=contentstatus[published]&browseSite=place-content&containerType=14&containerID=' + $jivepageid + '&browseViewID=placeContent",
                                                                  "title": "Recent ' + $JivePrivateSpaceName + ' Content"
                                                                  },
                                                                      "definition": "https://<YourUrl>/api/core/v3/tileDefs/1082"
                                                              },
                                                              {
                                                                  "column": 1,
                                                                  "config": {
                                                                  "browseQuery": "browseSite=places&browseViewID=places&containerType=14&containerID=' + $jivepageid + '&filterID=all~objecttype~space",
                                                                  "title": "DEPLOYMENTS AND PROJECT DOCUMENTATION"
                                                              },
                                                              "definition": "https://<YourUrl>/api/core/v3/tileDefs/1082"
                                                          }
                                                      ]
                                                 

                                                                    }'

                                                  $newprivatespaceurl = "https://<YourUrl>/api/core/v3/places/" + "$jiveplaceid" + "/settings"
                                                  $jivesettingsbody = '{"activityTab" : "' + $Jivetrue +'", "overviewTab" : "' + $Jivefalse +'", "defaultTab" : ' + "activityTab" +'}'
                                                  $jivesettingsresults = Invoke-WebRequest -uri $newprivatespaceurl  -headers $JiveHeaders -ContentType: application/json -Method PUT  -Body $jivesettingsbody
                                                  $jivepagesresults = Invoke-WebRequest -uri $JivePagesURL -Headers $JiveHeaders -ContentType: application/json -Method Post -Body $jivepagesbody

                                              1 person found this helpful