Difference between revisions of "REST API:package Resource"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
 
(51 intermediate revisions by the same user not shown)
Line 1: Line 1:
This resource provides the ability to download and subscribe to packages using the [[REST API]].
This resource provides the ability to manage packages using the [[REST API]].


:''Learn more:'' REST API [[REST API#Conventions and Considerations|Conventions and Considerations]].
:''Learn more:'' REST API [[REST API#Conventions and Considerations|Conventions and Considerations]].
__TOC__
__TOC__
===Permissions===
=== Subscribe to a Package ===  
Use this resource to install a [[Package]].
 
{{permissions|Manage Packages|use this resource.}}
{{permissions|Manage Packages|use this resource.}}


=== Subscribe to a Package ===
:'''Note:'''
:To use this resource to subscribe from a file, ''Install Package from File'' must be enabled.
{{:Option:Install Package from File}}
 
;Method:POST
;Method:POST
   
   
;URI:<tt><nowiki>https://{domain}/networking/rest/package/operation/subscribe?{query_parameters}</nowiki></tt>  
;URI:<tt>{{platformURL}}/rest/package/operation/subscribe?{query_parameters}</tt>  


{{Query Parameters|
{{Query Parameters|
:*<tt>packageId</tt> - This is the package ''installation'' ID -- the value that appears as the '''id'' value in the '''Installation Link''' part of the [[Package]] page.
:*<tt>packageId</tt> - This is the package ''installation'' ID -- the value that appears as the '''id''' value in the '''Installation Link''' part of the [[Package]] page.
:*<tt>fileName</tt> - The path to the package file, when subscribing to a downloaded copy of the package. ([[Subscribe from File]] tenant capability must be enabled to use this option.)}}  
:*<tt>fileName</tt> - The path to the package file, when subscribing to a downloaded copy of the package. ([[Install from File]] tenant capability must be enabled to use this option.)}}  


;Examples:
;Examples:
:*Subscribe from repository:<br/>
:*Subscribe from repository:<br/>
::https://{domain}/networking/rest/package/operation/subscribe?packageId=123123123
::https://{{domain}}/networking/rest/package/operation/subscribe?packageId=123123123
:*Subscribe from repository, specifying a version number:<br/>
:*Subscribe from repository, specifying a version number:<br/>
::https://{domain}/networking/rest/package/operation/subscribe?packageId=123123123&version=1.2
::https://{{domain}}/networking/rest/package/operation/subscribe?packageId=123123123&version=1.2
:*Subscribe from a file:<br/>
:*Subscribe from a file:<br/>
::https://{domain}/networking/rest/package/operation/subscribe?fileName=C:\package.zip
::https://{{domain}}/networking/rest/package/operation/subscribe?fileName=C:\package.zip


;Response:
;Response:
Line 40: Line 45:
===Download a Package===
===Download a Package===
Download a package as a zip file.
Download a package as a zip file.
{{permissions|Manage Packages|use this resource.}}
;Method:POST
;Method:POST
;URI:<tt><nowiki>https://{domain}/networking/rest/package/operation/download/{package_id}?{query_parameters}</nowiki></tt>
;URI:<tt>{{platformURL}}/rest/package/operation/download/{package_id}?{query_parameters}</tt>
:where:
::* '''package_id''' - Is the package ''record'' ID - the value at the top of the [[Package]] page.
 
{{Query Parameters|
{{Query Parameters|
:*<tt>lastPublishedVersion</tt>
::*<tt>lastPublishedVersion</tt>
::* If TRUE, the package downloaded will be the last published version. ('''Default''') If the package has never been published, it will be published first, so that it can be downloaded.
:::* If TRUE, the package downloaded will be the last published version. ('''Default''') If the package has never been published, it will be published first, so that it can be downloaded.
::* If FALSE, the package will be re-assembled/re-created, and this version will include all changes made to the components, from the last package publish date. (If any components of the package have been checked out, the request returns an Error.)}}
:::* If FALSE, the package will be re-assembled/re-created, and this version will include all changes made to the components, from the last package publish date. (If any components of the package have been checked out, the request returns an Error.)}}


;Response:
;Response:
Line 83: Line 94:


:See also: [[REST API:Error Codes|REST API Error Codes]]
:See also: [[REST API:Error Codes|REST API Error Codes]]


====Sample Package Download Client Program====  
====Sample Package Download Client Program====  
{{:REST API:PackageDownloadClient}}
{{:REST API:PackageDownloadClient}}


===Deploy a Package===
===Deploy a Package===
Deploy a package to a list of tenants, where both the package to deploy and the tenant list are specified in the request.  
Deploy a package to a list of tenants, where both the package to deploy and the tenant list are specified in the request.  


;Additional Permissions:
{{permissions|Manage Packages|use this resource, and [[Mass Deployment of Packages to Tenants]] must be enabled for the publishing tenant.}}
:In addition to the [[Manage Packages]] permission, [[Mass Deployment of Packages to Tenants]] must be enabled for the publishing tenant.


;Method:POST
;Method:POST
   
   
;URI:<tt><nowiki>https://{domain}/networking/rest/package/operation/deploy</nowiki></tt>  
;URI:<tt>{{platformURL}}/rest/package/operation/deploy</tt>  


;Request:
;Request:
:<syntaxhighlight lang="xml" enclose="div">
:<syntaxhighlight lang="xml" enclose="div">
<package>
<platform>
    <id>123123123</id>
    <package>
    <deployConfiguration>
        <id>123123123</id>             --package installation ID
        <tenantList>
        <deployConfiguration>
            <tenantId>1214573329</tenantId>
            <tenantList>
            <tenantId>1224242818</tenantId>
                <tenantId>1214573329</tenantId>
              ...
                <tenantId>1224242818</tenantId>
        </tenantList>
                  ...
        <notifyTenants>false</notifyTenants>
            </tenantList>
        <deployTime>0</deployTime>   
            <notifyTenants>false</notifyTenants>
    </deployConfiguration>
            <deployTime>0</deployTime>   
</package>
        </deployConfiguration>
    </package>
</platform>
</syntaxhighlight>
</syntaxhighlight>


Line 132: Line 142:
===Fields===
===Fields===


====DeployConfiguration====
====package====
:{| border="1" cellpadding="5" cellspacing="1"
:{| border="1" cellpadding="5" cellspacing="1"
|'''Name'''||'''Type'''||'''Required on Add'''||'''Description'''||'''Additional Info'''
! Name!!Type!!Attribute!!Required on Add!!Description!!Additional Information
|-
|-
|<tt>tenantList</tt>||List||align="center"|[[File:Checkmark.gif|link=]]||List of tenants to deploy the package to ||
|<tt>id</tt>||String|| align="center"|Read Only  || ||The package ''installation'' ID || The value that appears as the '''id''' value in the '''Installation Link''' part of the [[Package]] page.
|}
 
====deployConfiguration====
:{| border="1" cellpadding="5" cellspacing="1"
! Name!!Type!!Attribute!!Required on Add!!Description!!Additional Information
|-
|-
|<tt>notifyTenants</tt>||Boolean||align="center"|[[File:Checkmark.gif|link=]]||If true, send a message to notify tenants about package deployment||
|<tt>tenantList</tt>||List|| ||align="center"|[[File:Checkmark.gif|link=]]||List of tenants to deploy the package to ||
|-
|-
|<tt>deployTime</tt>||Date||align="center"|[[File:Checkmark.gif|link=]]||Deployment date/time<br/>0=Deploy immediately||[[UTC Format]]
|<tt>notifyTenants</tt>||Boolean|| ||align="center"|[[File:Checkmark.gif|link=]]||If true, send a message to notify tenants about package deployment||
|-
|-
|<tt>deployTime</tt>||Date|| ||align="center"|[[File:Checkmark.gif|link=]]||Deployment date/time<br/>0=Deploy immediately||[[UTC Format]]
|}
|}


====TenantList====
====tenantList====
:{| border="1" cellpadding="5" cellspacing="1"
:{| border="1" cellpadding="5" cellspacing="1"
|'''Name'''||'''Type'''||'''Required on Add'''||'''Description'''||'''Additional Info'''
! Name!!Type!!Attribute!!Required on Add!!Description!!Additional Information
|-
|<tt>tenantId</tt>||String||align="center"|[[File:Checkmark.gif|link=]]||Tenant ID||
|-
|-
|<tt>tenantId</tt>||String|| ||align="center"|[[File:Checkmark.gif|link=]]||Tenant ID||
|}
|}
<noinclude>
<noinclude>

Latest revision as of 20:58, 15 January 2015

This resource provides the ability to manage packages using the REST API.

Learn more: REST API Conventions and Considerations.

Subscribe to a Package

Use this resource to install a Package.

Lock-tiny.gif

Users that have the Manage Packages permission can use this resource. 
Note:
To use this resource to subscribe from a file, Install Package from File must be enabled.

Lock-tiny.gif

Method
POST
URI
https://{yourDomain}/networking/rest/package/operation/subscribe?{query_parameters}
Query Parameters
  • packageId - This is the package installation ID -- the value that appears as the id value in the Installation Link part of the Package page.
  • fileName - The path to the package file, when subscribing to a downloaded copy of the package. (Install from File tenant capability must be enabled to use this option.)
For more information, see: Specifying Query Parameters in REST APIs
Examples
  • Subscribe from repository:
https://{yourDomain}/networking/rest/package/operation/subscribe?packageId=123123123
  • Subscribe from repository, specifying a version number:
https://{yourDomain}/networking/rest/package/operation/subscribe?packageId=123123123&version=1.2
  • Subscribe from a file:
https://{yourDomain}/networking/rest/package/operation/subscribe?fileName=C:\package.zip
Response
<syntaxhighlight lang="xml" enclose="div">

<platform>

   <message>
       0
       <description>Success</description>
   </message>

</platform> </syntaxhighlight>

See also: REST API:Error Codes

Sample Package Subscribe Client

The PackageSubscribeClient demo program extends the REST API:BaseClient class to subscribe to a package file (a zip file downloaded from the platform). With minor modifications, it can be used to subscribe to a package hosted on the platform.

<syntaxhighlight lang="java" enclose="div" style="overflow: auto">

package demo.rest;

import java.io.File;

import javax.ws.rs.core.MediaType;

import org.apache.wink.client.ClientResponse; import org.apache.wink.client.ClientWebException; import org.apache.wink.client.Resource; import org.apache.wink.common.internal.utils.MediaTypeUtils;

/**

* "Subscribe" to (install or update) a package contained in a zip file. 
* This program extends demo.rest.BaseClient.java 
* which in turn makes use of demo.rest.BaseUtil.java to handle
* logging in, logging out, and message formatting.
*/

public class PackageSubscribeClient extends BaseClient {

   public static void main(String[] args)
   {
       String packageUrl = baseUrl + "/package/operation/subscribe"
              + "?fileName=orders.zip";         // Subscribe from a file
       File f = new File("c:\\orders.zip");
       //Other options:
       //     + "?packageId=123123123";       // Subscribe from platform
       //     + "?packageId=123123123&version=1.2";  //  Specify version
       // Instantiate BaseClient.client and get sessionId
       PackageSubscribeClient subscribeClient = new PackageSubscribeClient();
       cookieString = subscribeClient.login(); 
       try
       {
          Resource resource = getResource(packageUrl);
          resource.header("Cookie", cookieString);
          ClientResponse response =
               resource.contentType(MediaTypeUtils.ZIP).accept(
                   MediaType.APPLICATION_XML).post(ClientResponse.class, f);
           String responseXml = response.getEntity(String.class);
           echoResponse(responseXml);
       }
       catch (ClientWebException webException)
       {
           echoResponse(webException);
       }
       catch (Exception e)
       {
          System.out.println(e.getMessage());
          e.printStackTrace();
       }
       finally
       {
           client.logout();
       }
   }

} </syntaxhighlight>

Download a Package

Download a package as a zip file.

Lock-tiny.gif

Users that have the Manage Packages permission can use this resource. 
Method
POST
URI
https://{yourDomain}/networking/rest/package/operation/download/{package_id}?{query_parameters}
where:
  • package_id - Is the package record ID - the value at the top of the Package page.
Query Parameters
  • lastPublishedVersion
  • If TRUE, the package downloaded will be the last published version. (Default) If the package has never been published, it will be published first, so that it can be downloaded.
  • If FALSE, the package will be re-assembled/re-created, and this version will include all changes made to the components, from the last package publish date. (If any components of the package have been checked out, the request returns an Error.)
For more information, see: Specifying Query Parameters in REST APIs
Response

The response is of type multipart/mixed.

  • On success it will contain two parts which look something like this
<syntaxhighlight lang="xml" enclose="div">

103832778631715

    content-type: application/xml

    <platform>
       <message>
           0
           <description>Success</description>
       </message>
   </platform>


103832778631715

content-type: application/octet-stream

Encoded file part


103832778631715--

</syntaxhighlight>

  • On failure it will contain just a single part which looks something like this
<syntaxhighlight lang="xml" enclose="div">

103832778631715

    content-type: application/xml

    <platform>
       <message>
           0
           <description>Success</description>
       </message>
   </platform>

103832778631715--

</syntaxhighlight>

See also: REST API Error Codes

Sample Package Download Client Program

The PackageDownloadClient demo program extends the REST API:BaseClient class to download a package from the platform to your local system.

<syntaxhighlight lang="java" enclose="div" style="overflow: auto">

package demo.rest;

import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.regex.Matcher; import java.util.regex.Pattern;

import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap;

import org.apache.wink.client.ClientResponse; import org.apache.wink.client.ClientWebException; import org.apache.wink.client.Resource; import org.apache.wink.common.internal.utils.MediaTypeUtils; import org.apache.wink.common.model.multipart.InMultiPart; import org.apache.wink.common.model.multipart.InPart;

/**

* Download a package from the platform to the local system.
* This program extends demo.rest.BaseClient.java 
* which in turn makes use of demo.rest.BaseUtil.java to handle
* logging in, logging out, and message formatting.
*/

public class PackageDownloadClient extends BaseClient {

   public static void main(String[] args)
   {
       // packageId is the unique id associated with the package.
       // Get it from the platform UI while viewing a package.
       String packageId = "761fb822e95d48c498d4c4f97dd1470b";
       String lastPublishedVersion="true";
       String downloadPackageUrl = baseUrl + "/package/operation/download/"
                 + packageId+"?lastPublishedVersion="+lastPublishedVersion;
       // Instantiate BaseClient.client and get sessionId
       PackageDownloadClient client = new PackageDownloadClient();
       cookieString = client.login(); 
      try
       {
           Resource resource = getResource(downloadPackageUrl);
           resource.header("Cookie", cookieString);
           ClientResponse response =
               resource.accept(MediaTypeUtils.MULTIPART_MIXED).post(
                   ClientResponse.class, "");
           InMultiPart iMultiPart = 
               response.getEntity(InMultiPart.class);
           while (iMultiPart.hasNext())
           {
               InPart iPart = iMultiPart.next();
               String contentType = iPart.getContentType();
               if (contentType.contains(MediaType.APPLICATION_XML))
               {
                   InputStream ips = iPart.getInputStream();
                   echoResponse(ips);
               }
               else if (contentType.contains(MediaType.APPLICATION_OCTET_STREAM))
               {
                   MultivaluedMap<String, String> headers = iPart.getHeaders();
                   String cDHeader = headers.getFirst("Content-Disposition");
                   String fileName = "";
                   Pattern p = Pattern.compile("filename=.*");
                   Matcher m = p.matcher(cDHeader);
                   if (m.find())
                   {
                       fileName = m.group();
                   }
                   fileName = fileName.replace("filename=", "");
                   File packageZipFile = new File("c:\\" + fileName);
                   FileOutputStream fos = null;
                   fos = new FileOutputStream(packageZipFile);
                   InputStream is = iPart.getInputStream();
                   int size = 0;
                   int i = 0;
                   byte[] ba = new byte[8196];
                   while ((i = is.read(ba)) != -1)
                   {
                       fos.write(ba, 0, i);
                       size += i;
                   }
                   fos.close();
                   System.out.println("Package downloaded to " 
                       + packageZipFile.getAbsolutePath());
               }
               else 
               {
                   System.out.println("Unrecognized media type: " + contentType);
               }
           }
       }
       catch (ClientWebException webException)
       {
           echoResponse(webException);
       }
       catch (IOException io)
       {
           io.printStackTrace();
       }
       catch (Exception e)
       {
           System.out.println(e.getMessage());
           e.printStackTrace();
       }
       finally
       {
           client.logout();
       }
   }

}

</syntaxhighlight>

Deploy a Package

Deploy a package to a list of tenants, where both the package to deploy and the tenant list are specified in the request.

Lock-tiny.gif

Users that have the Manage Packages permission can use this resource, and Mass Deployment of Packages to Tenants must be enabled for the publishing tenant. 
Method
POST
URI
https://{yourDomain}/networking/rest/package/operation/deploy
Request
<syntaxhighlight lang="xml" enclose="div">

<platform>

   <package>
       <id>123123123</id>              --package installation ID
       <deployConfiguration>
           <tenantList>
               <tenantId>1214573329</tenantId>
               <tenantId>1224242818</tenantId>
                 ...
           </tenantList>
           <notifyTenants>false</notifyTenants>
           <deployTime>0</deployTime>  
       </deployConfiguration>
   </package>

</platform> </syntaxhighlight>

Response

Returns the id of the submitted import job, along with a message telling whether or not the job was accepted for processing. (Use the REST packageDeploy Status resource to follow the progress of the job.)

<syntaxhighlight lang="xml" enclose="div">

<platform>

   <message>
       0
       <description>Success</description>
       <id>...</id>        
   </message>

</platform> </syntaxhighlight>

See also: REST API:Error Codes

Fields

package

Name Type Attribute Required on Add Description Additional Information
id String Read Only The package installation ID The value that appears as the id value in the Installation Link part of the Package page.

deployConfiguration

Name Type Attribute Required on Add Description Additional Information
tenantList List Checkmark.gif List of tenants to deploy the package to
notifyTenants Boolean Checkmark.gif If true, send a message to notify tenants about package deployment
deployTime Date Checkmark.gif Deployment date/time
0=Deploy immediately
UTC Format

tenantList

Name Type Attribute Required on Add Description Additional Information
tenantId String Checkmark.gif Tenant ID