Difference between revisions of "CCAPI Config"

From ADF Docs
Jump to: navigation, search
(File format and location)
(Overview)
 
(41 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
The CCAPI Config uses the [[Config|Core Config]] object to handle its site specific configuration.
 
The CCAPI Config uses the [[Config|Core Config]] object to handle its site specific configuration.
  
<source lang="java">
+
Note: CommonSpot must be configured to allow API calls before using the ADF CCAPI components.
Note: CommonSpot must be configured to allow API calls before using the ADF CCAPI components.
+
Please read the section of the '''Developers Guide''' on the '''Content Creation API'''
Please read the section of the Developers Guide on the Content Creation API
+
(search for "loaderrequest.dat").
(search for "loaderrequest.dat").
+
 
</source>
+
 
 +
''New Feature:'' [[CCAPI Conduit Page Pool|'''CCAPI Conduit Page Pool''']] for updating Global Custom Elements.
  
 
== File format and location ==
 
== File format and location ==
<source lang="java">
+
 
Security Note:  
+
'''Security Note:'''
 +
<pre>
 
When setting up the CCAPI configuration file there are a couple of approaches that can be
 
When setting up the CCAPI configuration file there are a couple of approaches that can be
used to secure your CCAPI login information.
+
used to secure your CCAPI config data:
 
1. Instead of using the 'ccapi.xml' config file, use the specially formatted 'ccapi.cfm' file
 
1. Instead of using the 'ccapi.xml' config file, use the specially formatted 'ccapi.cfm' file
 
   for the XML configuration data. An example 'ccapi.cfm' file can be found here:  
 
   for the XML configuration data. An example 'ccapi.cfm' file can be found here:  
Line 20: Line 22:
 
2. Lock down your "/_cs_apps/config" directory via your web server, so this folder can not be
 
2. Lock down your "/_cs_apps/config" directory via your web server, so this folder can not be
 
   accessed via the web.  
 
   accessed via the web.  
</source>
+
</pre>
  
 
To allow each site to have its own configuration for the CCAPI:
 
To allow each site to have its own configuration for the CCAPI:
 
# Locate the '/_cs_apps/config/' directory in your site.  If this directory does not exist, create it.
 
# Locate the '/_cs_apps/config/' directory in your site.  If this directory does not exist, create it.
# Place a file in this directory called "ccapi.xml".
+
# Place a file in this directory called "ccapi.cfm".
# Place the following XML content into the ccapi.xml file  
+
# Place the following CFML and XML content into the ccapi.cfm file  
<source lang="xml">
+
<!-- <source lang="xml"> -->
 +
<pre>
 +
<cfprocessingdirective suppresswhitespace="Yes">
 +
<cfxml variable="configXML">
 +
<cfoutput>
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
 
<settings>
 
<settings>
  <logging>
+
<logging>
  <enabled>1</enabled>
+
<enabled>1</enabled>
  </logging>
+
</logging>
  <elements>
+
<elements>
  <UniqueElementName>
+
<UniqueElementName>
    <pageID>30622</pageID>
+
<pageID>30622</pageID>
    <subsiteID>1</subsiteID>
+
<subsiteID>1</subsiteID>
    <elementType>custom</elementType>
+
<elementType>custom</elementType>
    <controlName>posts</controlName>
+
<controlName>posts</controlName>
  </UniqueElementName>
+
</UniqueElementName>
</elements>
+
</elements>
<wsVars>
+
<wsVars>
  <webserviceURL>http://cfusion/commonspot/webservice/cs_service.cfc?wsdl</webserviceURL>
+
<webserviceURL>http://cfusion/commonspot/webservice/cs_service.cfc?wsdl</webserviceURL>
  <csuserid>csUserName</csuserid>
+
<csuserid>csUserName</csuserid>
  <cspassword>csPassword</cspassword>
+
<cspassword>csPassword</cspassword>
  <site>Demo</site>
+
<site>Demo</site>
  <siteURL>http://cfusion/demo</siteURL>
+
<siteURL>http://cfusion/demo</siteURL>
  <subsiteID>1</subsiteID>
+
<subsiteID>1</subsiteID>
  <cssites>commonspot-sites</cssites>
+
<cssites>commonspot-sites</cssites>
</wsVars>
+
</wsVars>
 
</settings>
 
</settings>
</source>
+
</cfoutput>
 +
</cfxml>
 +
</cfprocessingdirective>
 +
</pre>
 +
<!-- </source> -->
 +
 
 +
 
 +
For CommonSpot 7.0.1+, 8.0.1+ and 9+ in the <wsVars> section in the <webserviceURL> node update cs_service.cfc to use the cs_remote.cfc component file:
 +
<pre>
 +
<webserviceURL>http://cfusion/commonspot/webservice/cs_remote.cfc?wsdl</webserviceURL>
 +
</pre>
  
 
== XML Components ==
 
== XML Components ==
There are three major components in the CCAPI XML Config file:
+
There are three major XML components in the CCAPI Config file:
 
# <logging> This tag contains the flag to enable logging. <br><br>
 
# <logging> This tag contains the flag to enable logging. <br><br>
 
# <elements> This tag contains the Custom Elements and Textblock elements that you would like to use.  See the [[CCAPI Element|CCAPI Content]] page for additional information about how to add/edit data within Textblocks and Custom Elements.<br><br>
 
# <elements> This tag contains the Custom Elements and Textblock elements that you would like to use.  See the [[CCAPI Element|CCAPI Content]] page for additional information about how to add/edit data within Textblocks and Custom Elements.<br><br>
Line 97: Line 113:
 
     </elements>
 
     </elements>
 
     <wsVars>
 
     <wsVars>
         <webserviceURL>http://cms.mysite.com/commonspot/webservice/cs_service.cfc?wsdl</webserviceURL>
+
         <webserviceURL>http://cms.mysite.com/commonspot/webservice/cs_remote.cfc?wsdl</webserviceURL>
 
         <csuserid>admin</csuserid>
 
         <csuserid>admin</csuserid>
 
         <cspassword>password</cspassword>
 
         <cspassword>password</cspassword>
Line 120: Line 136:
 
Now it is simple to use the [[CCAPI]] to make calls to populate this custom element. Sample code would look like this:
 
Now it is simple to use the [[CCAPI]] to make calls to populate this custom element. Sample code would look like this:
  
<source lang="java">
+
<!-- <source lang="java"> -->
 +
<pre>
 
<cfscript>
 
<cfscript>
 
  // setup a data structure for the news element content
 
  // setup a data structure for the news element content
Line 132: Line 149:
 
  addContentResults = application.ADF.csContent.populateContent("News", newsData);
 
  addContentResults = application.ADF.csContent.populateContent("News", newsData);
 
</cfscript>
 
</cfscript>
</source>
+
</pre>
 +
<!-- </source> -->
  
The newsData structure contains all of the fields for the custom element.  The call to "csContent" has 2 parameters the first being the "named element" - this matches the node in the <elements> section of the CCAPI.xml file from above.  The second parameter is the actual data for the custom element.
+
The newsData structure contains all of the fields for the custom element.  The call to "csContent" has 2 parameters the first being the "named element" - this matches the node in the <elements> section of the CCAPI.cfm file from above.  The second parameter is the actual data for the custom element.
  
  
  
 
[[Category:CCAPI]]
 
[[Category:CCAPI]]

Latest revision as of 14:08, 13 October 2014

Overview

Sometimes your applications may need to add content programmatically (like creating pages, uploading documents and adding custom element content). The CCAPI Library Component makes it easy to add content into CommonSpot. The CCAPI Library Component utilizes an Application Configuration at the Site Level (XML) to load the settings into the CCAPI calls.

The CCAPI Config uses the Core Config object to handle its site specific configuration.

Note: CommonSpot must be configured to allow API calls before using the ADF CCAPI components.
Please read the section of the Developers Guide on the Content Creation API
(search for "loaderrequest.dat").


New Feature: CCAPI Conduit Page Pool for updating Global Custom Elements.

File format and location

Security Note:

When setting up the CCAPI configuration file there are a couple of approaches that can be
used to secure your CCAPI config data: 
1. Instead of using the 'ccapi.xml' config file, use the specially formatted 'ccapi.cfm' file
   for the XML configuration data. An example 'ccapi.cfm' file can be found here: 
   "/ADF/lib/ccapi/ccapi.cfm"
2. Lock down your "/_cs_apps/config" directory via your web server, so this folder can not be
   accessed via the web. 

To allow each site to have its own configuration for the CCAPI:

  1. Locate the '/_cs_apps/config/' directory in your site. If this directory does not exist, create it.
  2. Place a file in this directory called "ccapi.cfm".
  3. Place the following CFML and XML content into the ccapi.cfm file
<cfprocessingdirective suppresswhitespace="Yes">
<cfxml variable="configXML">
<cfoutput>
<?xml version="1.0" encoding="utf-8"?>
<settings>
	<logging>
		<enabled>1</enabled>
	</logging>
	<elements>
		<UniqueElementName>
			<pageID>30622</pageID>
			<subsiteID>1</subsiteID>
			<elementType>custom</elementType>
			<controlName>posts</controlName>
		</UniqueElementName>
	</elements>
	<wsVars>
		<webserviceURL>http://cfusion/commonspot/webservice/cs_service.cfc?wsdl</webserviceURL>
		<csuserid>csUserName</csuserid>
		<cspassword>csPassword</cspassword>
		<site>Demo</site>
		<siteURL>http://cfusion/demo</siteURL>
		<subsiteID>1</subsiteID>
		<cssites>commonspot-sites</cssites>
	</wsVars>
</settings>
</cfoutput>
</cfxml>
</cfprocessingdirective>


For CommonSpot 7.0.1+, 8.0.1+ and 9+ in the <wsVars> section in the <webserviceURL> node update cs_service.cfc to use the cs_remote.cfc component file:

<webserviceURL>http://cfusion/commonspot/webservice/cs_remote.cfc?wsdl</webserviceURL>

XML Components

There are three major XML components in the CCAPI Config file:

  1. <logging> This tag contains the flag to enable logging.

  2. <elements> This tag contains the Custom Elements and Textblock elements that you would like to use. See the CCAPI Content page for additional information about how to add/edit data within Textblocks and Custom Elements.

  3. <wsVars> This node contains the Web Services information for your site.

Example

For this example we will use a custom element called "News" with the following fields (Note: Field Labels in text, field names in brackets []):

  • Title [title]
  • Description [descr]
  • Date Posted [datePosted]
  • Content [content]
  • Author [author]

Lets also assume that your Server has the following configuration:


Sample Steps

If you want to easily populate this Custom Element using the CCAPI then you would do the following:

  1. Create a page somewhere in your site (we usually create a page called ccapi.cfm)
  2. Place thew "News" custom element in the page
  3. Give the element the name "NewsElement" (using the Element Indicators in CS v.5+ you would click the "more" icon and then go to Name)
  4. Save the page and move into read mode
  5. View the source of the page and look for the page and subsite IDs (Note: this will be in a javascript block near the top of the page - look for "jsPageID" and "subsiteID") - for the sake of our example lets say the pageID = 1345 and the subsiteID = 4
  6. Enter the code below into your CCAPI.xml file
 <?xml version="1.0" encoding="utf-8"?>
 <settings>
   <logging>
        <enabled>1</enabled>
    </logging>
    <elements>
        <News>
            <pageID>1345</pageID>
            <subsiteID>4</subsiteID>
            <elementType>custom</elementType>
            <controlName>NewsElement</controlName>
        </News>
    </elements>
    <wsVars>
        <webserviceURL>http://cms.mysite.com/commonspot/webservice/cs_remote.cfc?wsdl</webserviceURL>
        <csuserid>admin</csuserid>
        <cspassword>password</cspassword>
        <site>Demo</site>
        <siteURL>http://cms.mysite.com</siteURL>
        <subsiteID>1</subsiteID>
        <cssites>commonspot-sites</cssites>
    </wsVars>
 </settings>

Analyzing the file

We have created a <News> node under the <elements> node. The word "News" is arbitrary and really only needs to be unique (e.g. each xml node within elements needs to be unique).

In the <News> element we have configured it to use the information from the ccapi.cfm page we created above. Notice how the <elementType> is "custom" - thats because we are working with a Custom Element. The <controlName> contains the value you entered in the "Name" field for the "News" element on the page.

In the <wsVars> node we completed the information based on the settings for the server.

Note: Make sure you Reset the ADF whenever this file is added/modified

Code sample

Now it is simple to use the CCAPI to make calls to populate this custom element. Sample code would look like this:

<cfscript>
 // setup a data structure for the news element content
 newsData = structNew();
 newsData.title = "My New News Article";
 newsData.descr = "We are adding content via the CCAPI with the ADF";
 newsData.datePosted = request.formattedTimestamp;
 newsData.content = "Here is the content of the article (can contain <html>)";
 newsData.author = "John Smith";
 // make the call to create content
 addContentResults = application.ADF.csContent.populateContent("News", newsData);
</cfscript>

The newsData structure contains all of the fields for the custom element. The call to "csContent" has 2 parameters the first being the "named element" - this matches the node in the <elements> section of the CCAPI.cfm file from above. The second parameter is the actual data for the custom element.