Import and Export APIs

Import and Export APIs
lac32
You can create a backup of your API by exporting it. A basic example is exporting an API from API Server-1 into a file, saving the export file in a source control system, and then importing the file on API Server-2. The exported file is effectively a copy of your API. A typical use is the life cycle operation to move a system from development to production.
In this article:
2
Import/Export Best Practices
Before you export an API to create a production server, we recommend that you complete the following:
  • Remove unused data sources.
    You might have test/dev data sources. Remove what is not required.
  • Clear unused libraries.
  • Export each JavaScript library to a separate file.
Your logic libraries are not exported with the API. Development teams should maintain these libraries individually so that they can reload them onto the production target. Your import scripts can reload these libraries by way of the CA Live API Creator Admin project API (Admin API).
 
CA Live API Creator
 is accessed by way of normal HTTP(s).
You can import APIs in the following ways:
Import and Export APIs Using API Creator
You can interactively export an API, import the API, and define the export file format.
Export an API as a JSON File
You can export your API as a 
.JSON
 file. This file contains the metadata for the current API including database schema, business rules, resource endpoints, security definitions for users, and roles.
The exported 
.JSON
 file is an ordinary text file and can be large. You can check in this file into a source control system, view the file in a text editor, or import the file into another API.
 Do not make changes to the contents of the exported 
.JSON
 file.
The following code block shows the organization of an example exported 
.JSON
 file:
[
{
"ident": 2004,
"ts": "2015-10-29T10:46:31.979282Z",
"exportVersion": "v4",
"adminSchemaVersion": "20151009",
"name": "Banking Demo",
"url_name": "banking",
"status": null,
"is_active": true,
"account_ident": 1000,
"authprovider_ident": 1000,
"@metadata": {...},
"Topics": [...],
"Rules": [...],
"Topics": [...],
"ApiVersions": [...],
"DbaseSchemas": [...],
"ProjectLibraries": [
[,
"ProjectOptions": [...],
"ApiKeys": [...],
"Roles": [...],
"Users": [...],
"Handlers": [
[,
"EventHandlers": [...],
"Relationships": [...],
"Applications": [...],
}
]
  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.
Import the Exported JSON File as an API
  1. From the Home page, click 
    Import
    .
    The Import window opens.
  2. Select the exported 
    .JSON
     file you want to import and click 
    OK
    . The 
    .JSON
     file is imported into the API Server.
    If an API with the same name/URL already exists, the imported API is renamed to avoid collisions.
The exported API is imported into a new API.
Fix the Imported API
The exported 
.JSON
 file you 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 re-supply this information.
For an example of how to import an API, see the Demo API Sample.
  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 you 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 might want to automate the life cycle operation of moving an API from development to production. Scripting is based on the underlying concepts of programmatic API creation. Scripting requires more background. The following examples illustrate scripting the import process using cURL and NodeJS.
 
CA Live API Creator
 APIs 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 stored in the Admin database.
Access Admin Data Using the ProjectExport Resource
You can 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.
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 do this using cURL commands, the Admin CLI, or the Node SDK.
For more information:
Manage your APIs Using the Admin CLI
You can manage your APIs using the Admin CLI, 
liveapicreator-admin-cli
, which accesses the Admin API. The Admin CLI is a NodeJS application packaged so it operates from the command line.
For more information about 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: