Import and Export APIs

Import and Export APIs
lac40
You can create a backup, or copy, of your API by exporting it. A typical use case is the life cycle operation of moving a system from development to production. For example, to move an API from API Server-1 into a file, save the exported file into a source control system, and then import the file onto API Server-2.
In this article:
 
3
Your exported API is a JSON file that contains the metadata for the current API, including resources, custom endpoints, rules, virtual and physical relationships, JavaScript libraries, timers, listeners, connections, users, and their roles. You can check in the exported JSON file into a source control system, view the file in a text editor, or import the file into another API.
Exported APIs do not include the logic libraries.
Best Practice: 
Maintain your logic libraries individually so that you can reload them onto the production target. You can reload your logic libraries using scripts by way of the CA Live API Creator Admin project API (Admin API).
 
CA Live API Creator
 is accessed by way of normal HTTP.
The following code block shows the organization of an example exported JSON file:
[
{
"ident": 2001,
"ts": "2017-10-31T09:27:27+00:00",
"exportVersion": "v4",
"adminSchemaVersion": "20171022",
"name": "Demo (Derby)",
"url_name": "demo_derby",
"comments": "Welcome examples.",
"status": null,
"is_active": true,
"account_ident": 1000,
"authprovider_ident": 1000,
"@metadata": {
},
"Topics": [],
"Rules": [
{
"RuleTopics": []
}
],
"ApiKeys": [],
"ApiVersions": [
{
"Resources": [
{
"ResourceAttributes": []
}
],
"Applications": [],
"Connections": [],
"DbaseSchemas": [
{
"NonPersistentAttributes": [],
"TableInfos": [],
"ViewInfos": []
}
],
"EventHandlers": [],
"Functions": [
{
"FunctionParameters": []
}
],
"Handlers": [],
"Listeners": [],
"NamedFilters": [],
"NamedSorts": [],
"ProjectLibraries": [],
"ProjectOptions": [],
"ProjectProblems": [],
"Relationships": [],
"Roles": [
{
"ApiKeyRoles": [],
"ApiVisibility": [],
"PermissionData": [],
"TablePermissions": []
}
],
"ScheduleItems": [],
"Users": []
}
]
Verify the Prerequisites
Before you export an API to create a production server, ensure that you have completed the following steps:
  • Delete each data source that your API is not using or that your API does not require. For example, you might have test/dev data sources.
    For more information about how to delete a data source, see Database Connectivity.
  • Clear the 
    Used
     checkbox for each JavaScript library that your API is not referencing.
    For more information about this checkbox, see Logic Libraries.
  • Export each JavaScript library that you want to import into your new API.
    For more information about how to export JavaScript libraries, see Logic Libraries.
Methods for Importing and Exporting
You can import APIs using the following methods:
Import APIs Using API Creator
You can interactively export an API, import the API, and define the export file format.
Use the following process to import an API using API Creator:
Export an API as a JSON File
Follow these steps:
 
  1. With your API open, in the Create section, click 
    API Properties
    .
    The Details appears.
  2. Click 
    Export
    .
Your API is downloaded as a JSON file.
Do not change the contents of the exported JSON file.
Import the Exported JSON File as an API
If your imported API references missing JavaScript libraries, 
CA Live API Creator
 imports the API and reports an issue that the API is missing the referenced libraries. A yellow banner appears at the top of the page with a link to the issue. You can view the issue to determine which JavaScript libraries are missing, resolve the issue by importing the missing libraries, and then clearing the issue from the list.
Best Practice: 
If your imported API references JavaScript libraries, before you you import the exported JSON file into your API and begin testing your API, add those exported JavaScript libraries to your API.
For more information:
Follow these steps:
 
  1. In API Creator, from the APIs page, click 
    I
     
    mport
    .
    The Import JSON window opens.
  2. Click 
    Select file to upload
    .
  3. Select the exported JSON file that you want to import, and then click 
    Open
    .
  4. Click 
    OK
    .
    The JSON file is imported into API Server.
    If an API with the same name/URL already exists, API Server renames the imported API to avoid collisions.
  5. (If you imported the API from an exported JSON file that includes active connections and listeners) Enable your API.
    The connections are automatically marked active and the listeners are automatically restarted.
    For more information about connections and listeners, see Creating Listeners.
The exported API is imported into a new API.
Fix the Imported API
The exported JSON file you that imported into your API does not include passwords and other security information. The authentication provider is preserved if possible or defaulted if not. You must fix the API to re-supply this information.
  1. With your API open, select 
    Your Account
     from the gear icon menu at the top right of API Creator.
    The User info page appears by default.
  2. Respecify your database password and then save your changes.
  3. In the Create section, click 
    API Properties
    .
    The Details page appears by default.
  4. Verify the authentication provider in the 
    Authentication provider
     field.
  5. (If you are using the built-in authentication provider) Specify the admin passwords
    .
    For more information about how to manage users using the built-in authentication provider, including how to change a user's password, see Authentication.
  6. (Optional) Respecify the URL name for your API, which includes the timestamp of the import.
The imported API is fixed.
Import APIs Using Scripts or API Calls
You can script the export/import procedures. For example, you can automate the life cycle operation of moving an API from development to production. Scripting is based on the underlying concepts of programmatic API creation, and requires more background. The following examples illustrate scripting the import process using cURL and NodeJS.
The APIs in 
CA Live API Creator
 consist of settings in the admin data and not in the code. These settings are the contents of the JSON file export. You can access these settings (APIs) by way of the Admin API. This API is a RESTful API that accesses the admin data that is stored in the admin database.
Access Admin Data Using the Admin API
You can access admin data using the Admin API. For example, you can use this API to create an API. You can create an API using cURL commands, the 
CA Live API Creator
 Admin command-line interface (Admin CLI), or the Node SDK. The Admin CLI is a NodeJS application packaged so it operates from the command line.
You can also access admin data using the 
ProjectExport
 resource within the Admin API. Its response data is shown in the "Sample JSON Layout". Export is a GET and import is a POST on 
ProjectExport
 using this API.
For more information:
Manage your APIs Using the Admin CLI
You can manage your APIs using the Admin CLI. The Admin CLI accesses the Admin API.
For more information about how to create an API using the Admin CLI, see API Creation by Command Line.
Access the Admin API Using Node SDK
The Node SDK simplifies API access for NodeJS applications, with services to make auth IDs transparent, etc. You can manage your APIs using the Node SDK by writing Node applications that you can employ in DevOp scripts.
For more information: