Skip to main content

"cloneCodePackage" (JSON Action)

Create a new code package with a new name and copy an existing code package into it

You can optionally modify the new code package's status and properties.

Links: Concepts | Tutorials | FAQs

Request examples

Typical

{ 
  "api": "admin",
  "action": "cloneCodePackage",
  "params": {
    "databaseName": "faircom",
    "ownerName": "admin",
    "codeName": "convertTemperature",
    "newDatabaseName": "faircom",
    "newOwnerName": "admin",
    "newCodeName": "convertTemperature V2",
    "codeStatus": "developing",
    "comment": "optional change comment",
    "description": "optional new description",
    "metadata": {}
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}
{ 
  "api": "admin",
  "action": "cloneCodePackage",
  "params": {
    "codeName": "convertTemperature",
    "newCodeName": "convertAndCategorizeTemperature",
    "comment": "Cloned from convertTemperature"
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}
{
  "debugInfo": {
    "request": {
      "api": "admin",
      "action": "cloneCodePackage",
      "params": {
        "databaseName": "faircom",
        "ownerName": "admin",
        "codeName": "convertTemperature",
        "newDatabaseName": "faircom",
        "newOwnerName": "admin",
        "newCodeName": "convertTemperature V2",
        "codeStatus": "developing",
        "comment": "optional change comment",
        "description": "optional new description",
        "metadata": {}
      },
      "debug": "max",
      "authToken": "replaceWithAuthTokenFromCreateSession"
    }
  },
  "errorCode": 0,
  "errorMessage": "",
  "authToken": "replaceWithAuthTokenFromCreateSession"
}
{
  "debugInfo": {
    "request": {
      "api": "admin",
      "action": "cloneCodePackage",
      "params": {
        "codeName": "convertTemperature",
        "newCodeName": "convertAndCategorizeTemperature",
        "comment": "Cloned from convertTemperature"
      },
      "debug": "max",
      "authToken": "replaceWithAuthTokenFromCreateSession"
    }
  },
  "errorCode": 0,
  "errorMessage": "",
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

The "cloneCodePackage" JSON Action creates a new code package by copying an existing one, with optional modifications to status and properties. It includes request and response examples, and a comprehensive table summarizing "params" properties like codeName, codeStatus, databaseName, and ownerName. It explains key properties such as "code," "codeFormat," "codeLanguage," and their usage within the action.

API actionJSON ADMIN APIJSON ActioncloneCodePackagecloneCodePackagesclonesCodePackageclonesCodePackagesclone code packagecodepackagecopy code packageduplicate code packagenew code packagemodify code packagecode package templatecode package action
Table 1. cloneCodePackage "params" property summaries

Property

Description

Default

Type

Limits (inclusive)

code

(optional) contains the source code stored in the server.

""

string

1 to 8,388,096 bytes

codeFormat

(optional) specifies the encoding of the code in the code property.

"utf8"

string

"utf8"

codeLanguage

specifies the programming language of the code in the "code" property.

Required - No default value

string

"javascript"
"json"

codeName

specifies the name of the code package.

Required - No default value

string

1 to 64 bytes

codeStatus

(optional) specifies the status of the code. The server only runs code with a status of "deprecated", "testing", or "active".

"developing"

string

"developing"
"deleted"
"inactive"
"deprecated"
"testing"
"active"

codeType

specifies how and where a FairCom server can run the JavaScript code.

Required - No default value

string

"integrationTableTransform"
"getRecordsTransform"

comment

(optional) describes the latest change to the code.

""

string

1 to 65,535 bytes

databaseName

(optional) specifies the name of the database.

Defaults to the session's "defaultDatabaseName" property

string

1 to 64 bytes

description

(optional) describes the code package.

""

string

0 to 65,500 bytes

metadata

(optional) contains user-defined properties that add keywords and tags about the code package.

{}

object

0 or more key/value pairs

newCodeName

(optional) when specified, the server renames the code package to the new name.

null

string

1 to 64 bytes

newDatabaseName

(optional) when specified, the server clones the code package into another database.

null

string

1 to 64 bytes

newOwnerName

(optional) when specified, the server assigns the cloned code package to the new owner name.

null

string

1 to 64 bytes

ownerName

(optional) specifies the name of the owner.

Defaults to the session's "defaultOwnerName" property

string

1 to 64 bytes



"code" contains the source code. Before embedding it in a JSON string, encode the source code using the format specified in the "codeFormat" property.

"codeFormat" is an optional string that specifies the encoding of code in the code property. You must encode your code to embed it in a JSON string. "codeFormat" currently only supports the "utf8" encoding, requiring you to use JSON rules to escape problem characters in your code with the \ backslash character, such as \n.

"codeLanguage" is a required string. It is the programming language's name. Any string value is accepted. Currently, "javascript" and "json" are the only types of code the FairCom server can use.

The "codeName" property is a required, case-sensitive string between 1 and 64 bytes containing the user-defined name for the code package.

It is an error to set "codeName" to the empty string "".

The package's unique identifier is the combination of "databaseName", "ownerName", and "codeName". See the "databaseName" and "ownerName" properties for more information.

"codeStatus" is optional and specifies a new status for the code. When you create a code package, it defaults to "developing". When you alter a code package, it defaults to the current state. You may set it to one of the following states: "developing", "deleted", "inactive", "deprecated", "testing", or "active". You can use "alterCodePackage" to transition from any state to any other. See "Use "codeStatus" to make a package runnable".

The "codeType" property defines how and where a FairCom server can run the JavaScript code. See Code Package Types for how to use each type of Code Package. The following enumerated values are supported:

"comment" is an optional string explaining the code change.

The "databaseName" property is an optional string from 1 to 64 bytes that specifies the database that contains an object, such as a table or code package. If it is set to null or is omitted, it defaults to the default database of the JSON Action session, see "createSession" and the "defaultDatabaseName" property. 

You specify this property when you want to use a different database instead of the default. Your session's account must have the appropriate privileges to access the code package.

This property is useful because objects, such as tables and code packages, can have the same name in multiple databases. This feature allows you to create multiple environments in the same server and reuse the same JSON actions in each environment. For example, you can create "dev", "test", "stage", and "prod" databases on the same server and use the "defaultDatabaseName" or "databaseName" properties to specify the desired environment.

It is an error to set "databaseName" to the empty string "".

If no default database is specified during "createSession", the server sets the "defaultDatabaseName" to the "defaultDatabaseName" value specified in the services.json file.

"description" is an optional string that describes the code package. The server indexes this field with a full-text index so that you can search for any word or phrase.

"metadata" contains user-defined properties that add keywords and tags about the code package. The server indexes this field with a full-text index so you can search for any word or phrase to find code packages.

"newCodeName" is an optional string. When present, the server renames the code package from the current "codeName" to the "newCodeName". The server does not change the "codeName" when null or omitted.

"newDatabaseName" is an optional string. When present, the server uses the new database as the target for the action. When null or omitted, the server runs the action in the current database.

"newOwnerName" is an optional string. When present, the server uses the new owner name as the target for the action. When null or omitted, the server runs the action using the current owner name.

The "ownerName" property is an optional string from 1 to 64 bytes that specifies the account that owns an object, such as a table or code package. If it is set to null or is omitted, it defaults to the account that created the JSON Action session, see "createSession" and the "defaultOwnerName" property. 

You specify this property when you want to use a different account instead of the default. Your session's account must have the appropriate privileges to access the code package. 

This property is useful because objects, such as tables and code packages, can have the same name in the same database as long as different accounts own each object. This feature allows you to create duplicate objects for different users on the same server and reuse the same JSON actions on those objects. For example, an administrator can copy objects from a production environment to her account so she can troubleshoot an issue using the same JSON actions, JavaScript, and SQL code.

It is an error to set "ownerName" to the empty string "".

If no default owner is specified during "createSession", the server sets the "defaultOwnerName" to the "defaultOwnerName" value specified in the services.json file.