How can I create global collections through the REST API?
search cancel

How can I create global collections through the REST API?

book

Article ID: 220513

calendar_today

Updated On:

Products

CA Spectrum DX NetOps

Issue/Introduction

I am planning on creating a set of Global Collections via REST API calls to the OneClick server. How can this be done?  Also, I need to be able to create the same GC on all of my landscapes.  Do I have to do this on each SpectroSERVER?

Resolution

The process begins with sending a HTTPS GET request to the OneClick host to obtain a unique GUID value from the MLS.  In this case, the MLS has a landscape handle of 0x1000000

https://<hostName>:8443/spectrum/restful/action/0x10474?mh=0x1000000

This returns a GUID value that is needed for the creation of the Global Collection.  You would need to run this command once for every new GC you want to create.  If you have 50 GC you want to create, you would need 50 GUID.

For this example, the GUID generated is:  

61002ede-cc53-1000-03a4-008010ef0000

Then you need to create a HTTP POST request for each SpectroSERVER using the same GUID.  For example, we have 3 SpectroSERVERs with Landscape handles:
0x1000000
0x2000000
0x3000000

To have the GC created on these 3 SpectroSERVERs, you need to send the POST to all 3 SS using the same GUID:

https://<hostName>:8443/spectrum/restful/model?landscapeid=0x1000000&mtypeid=0x10474&attr=0x1006e&val=Test+via+REST&attr=0x12e56&val=61002ede-cc53-1000-03a4-008010ef0000
https://<hostName>:8443/spectrum/restful/model?landscapeid=0x2000000&mtypeid=0x10474&attr=0x1006e&val=Test+via+REST&attr=0x12e56&val=61002ede-cc53-1000-03a4-008010ef0000
https://<hostName>:8443/spectrum/restful/model?landscapeid=0x3000000&mtypeid=0x10474&attr=0x1006e&val=Test+via+REST&attr=0x12e56&val=61002ede-cc53-1000-03a4-008010ef0000

This will create the same GC named "Test via REST" on all three SpectroSERVERS.

 

Additional Information

If you then want to update the search criteria of the GC, please refer knowledge article "Spectrum - Update dynamicCriteriaXML attribute using REST".

1) This is the dynamicCriteriaXML attribute value for the Global Collection search rule:

<search-criteria><devices-only-search /><filtered-models><does-not-equal><attribute id="0x10024"><value>NULL</value></attribute></does-not-equal></filtered-models></search-criteria>

2) Encode the following:

<search-criteria><devices-only-search /><filtered-models><does-not-equal><attribute id="0x10024"><value>NULL</value></attribute></does-not-equal></filtered-models></search-criteria>

I used this URL: https://www.w3schools.com/tags/ref_urlencode.ASP

This is the result:

%3Csearch-criteria%3E%3Cdevices-only-search+%2F%3E%3Cfiltered-models%3E%3Cdoes-not-equal%3E%3Cattribute+id%3D%220x10024%22%3E%3Cvalue%3ENULL%3C%2Fvalue%3E%3C%2Fattribute%3E%3C%2Fdoes-not-equal%3E%3C%2Ffiltered-models%3E%3C%2Fsearch-criteria%3E

3) This is the RESTful API PUT query:

http://localhost/spectrum/restful/model/0x1000386?attr=0x12a6a&val=%3Csearch-criteria%3E%3Cdevices-only-search+%2F%3E%3Cfiltered-models%3E%3Cdoes-not-equal%3E%3Cattribute+id%3D%220x10024%22%3E%3Cvalue%3ENULL%3C%2Fvalue%3E%3C%2Fattribute%3E%3C%2Fdoes-not-equal%3E%3C%2Ffiltered-models%3E%3C%2Fsearch-criteria%3E

Where 0x1000386 is the Global Collection model_handle and 0x12a6a is the dynamicCriteriaXML attribute ID.

How to get a list of Global Collections and Portal IPDomain models using the REST API

This is the XML body:

<rs:model-request throttlesize="5"
  xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd "> 

    <rs:target-models>
      <rs:models-search>
        <rs:search-criteria
             xmlns="http://www.ca.com/spectrum/restful/schema/filter">
          <filtered-models>
           <or>
            <equals>
              <attribute id="AttributeID.MTYPE_HANDLE">
                <value>0x10474</value> <!-- Global Collection Modeltype_Handle-->
              </attribute>
            </equals>
           </or>
          </filtered-models>
        </rs:search-criteria>
      </rs:models-search>
    </rs:target-models> 

    <rs:requested-attribute id="0x1006e" /> <!-- Model_Name -->
    <rs:requested-attribute id="0x10000" /> <!-- Modeltype_Name --> 

</rs:model-request>

4) I used the RESTClient:

5) This is the result: