Using the content commands

You can use the content commands to list, import, and export content from your Developer Portal site.

About

The Developer Portal is based on the Drupal content management system. In Drupal, a content entity is an item of content data that is intended to be displayed to site users, such as text, images, and HTML markup. Content entities are grouped into entity types, and most of these entity types are also subdivided into entity subtypes, also known as bundles. The content commands enable you to list, import, and export either one type of content entity, or all of the content entity types, at a time. If you want to manage the export of assorted content entity types at the same time, you can use the export-entity commands; see Using the export-entity commands for more information.

Procedure

  1. Log in as Provider org as seen in the following example.
    apic login --server management_server --realm provider/identity_provider --username provider_username --password provider_password
    You can determine which identity provider to use in the --realm parameter by entering the following command to see a list of all available identity providers (you do not need to be logged in to use this command):
    apic identity-providers:list --scope provider --server mgmt_endpoint_url --fields title,realm
    For example,
    apic identity-providers:list --scope provider --server myserver.com --fields title,realm 
    total_results: 2
    results:
      - title: API Manager User Registry
        realm: provider/default-idp-2
      - title: Corporate LDAP user registry
        realm: provider/corporate-ldap
    The title value should enable you to determine which identity provider to use; you can then copy the corresponding --realm parameter directly from the displayed realm value. For any identity providers that were created by your administrator after API Connect was installed, the names will have been determined at creation time. The default API Manager Local User Registry for login as a member of a provider organization is default-idp-2.

    For full details of the apic login command, see Logging in to a management server.

    For a summary of the general-purpose commands and their use, see Developer Portal CLI commands.

  2. List the content entity types that are exportable from your site by using the following content:list-types command. This command returns a list of all of the content entity types that are allowed to be exported from your site. If a type isn't listed in the return, that type is either blocked or isn't a content entity type.
    apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:list-types
    Where:
    • management_server is the endpoint URL of the management server (required).
    • orgid/name is the ID or name of the provider organization that the catalog belongs to (required).
    • catalogid/name is the ID or name of the catalog that the site belongs to (required).

    Each content entity type can have subtypes, which are known as bundles. These bundles can be used in the content:list command, when you want to list a particular bundle type of a content entity. In the following example, page is a bundle type of the content entity type node.

    apic --mode portaladmin --server my_management_server --org my_org --catalog my_catalog content:list-types
    block_content:
      - basic
    comment:
      - comment
      - comment_forum
    export_entity: {  }
    file: {  }
    import_entity: {  }
    media: {  }
    menu_link_content: {  }
    node:
      - article
      - blog_post
      - faq
      - forum
      - page
    shortcut:
      - default
    taxonomy_term:
      - forums
      - tags
    
  3. List all of the entities in your site for a given content entity type and, if required, bundle by using the following content:list command.
    apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:list --entity_type entity_type_name --bundle bundle_name
    Where:
    • entity_type_name is the type of content entity that you want to list (required). You can use the content:list-types command to find the list of available content entity types.
    • bundle_name is the name of the bundle type that you want to list (optional).
    The following example lists the content of the page bundle type for the node content entity. Included in the return is an Entity ID for each item in the content list.
    apic --mode portaladmin --server my_management_server --org my_org --catalog my_catalog content:list --entity_type node --bundle page
    -
      Title: 'Terms of use'
      Langcode: en
      'Entity ID': '1'
      Bundle: page
      UUID: 75fc430e-fc4d-47e3-bc5f-7f23063716ac
    -
      Title: 'Privacy Policy'
      Langcode: en
      'Entity ID': '2'
      Bundle: page
      UUID: ddff300b-16fe-4d1e-be6f-ce7040131b68
  4. Export your site content entities by using the following content:create-export command. This command creates an export task that returns a .tgz file containing the content entities. By default, the command polls the status of the task every 30 seconds until the task is finished, at which point the export file is returned. You can export a specific content entity type, or specific entities within an entity type, or you can generate a .tar file that contains all of the exportable content from your site. Note that exporting all of your site content can take a long time to complete.
    apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:create-export --entity_type entity_type_name --entity_ids entity_ids
    Where:
    • entity_type_name is the type of content entity that you want to export (required). If you want to export all of the exportable content from your site, set this option to all.
    • entity_ids is a comma separated list of the entity IDs that you want to export (optional).
    • --no-poll is an optional flag meaning that the command won't poll the status of the task, but instead just returns the task ID. This task ID can then be used with the content:get-export command to return the export file.
    Note: The command continues to poll until the maximum polling time of 25 minutes is reached. At which point you can use the commands content:get_export_status and content:get-export to get the status and, if the task has finished, an artifact.
    The following example creates an export task for the Terms of use and Privacy Policy entity IDs of the node content entity.
    apic --mode portaladmin --server my_management_server --org my_org --catalog my_catalog content:create-export --entity_type node --entity_ids 1,2
    201 CREATED - Task ID: 8h86b8utjtw51
    
    Response Code - 202:
    
    Message(s) - 
    The status of this task is: RUNNING
    
    Response Code - 200:
    
    Message(s) -
    The status of this task is: FINISHED and the artifact can now be streamed
    
    Saving File (Large files may take a while)...
    Incoming project saved to content_createExport-20230627114023.tgz
    The command saves the export file to your running directory. The export .tgz file includes a root.json file that contains an index of all of the entities that are contained in the .tgz file, as well as a content_entity_type.json file for each content entity type exported. The content_entity_type.json file contains all of the information needed to be able to import those entities into a different Developer Portal site.
  5. If you ran the content:create-export command with the --no-poll option, you can use the following commands to manage your content export.
    • content:delete-export
      Cancels any currently running content:create-export tasks, and deletes any related artifacts. For example:
      apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:delete-export --task_id task_id
      Where task_id is the ID of the export task on the queue.
    • content:get-export
      Streams the content of a specific completed export task to a .tgz file. For example:
      apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:get-export --task_id task_id
    • content:get-export-status
      Returns the status of a specific export task. For example:
      apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:get-export-status --task_id task_id
  6. Import your site content entities by using the content:create-import command. This command launches an import polling task that polls the status of the task every 30 seconds until the task is finished, at which point a summary of the import is returned. If the command is run with the --no-poll option, the task doesn't return the status of the task, but just returns the task ID.
    Important: Before you import any content, make sure that you backup the site that you're importing to, in case content gets overwritten that you weren't expecting.
    apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:create-import export_file_name
    Where:
    • export_file_name is the name of the export file that you want to import. You can import .tgz files that were created by using the content:create-export or export-entity:launch commands.
    • --no-poll is an optional flag meaning that the command won't poll the status of the task, but instead just returns the task ID. This task ID can then be used with the content:get-import-status command to get the status of the task.
    Note: The command continues to poll until the maximum polling time of 25 minutes is reached. At which point you can use the command content:get-import-status to get the status of the task.
    In the following example, the export file from Step 4 is imported into a different Developer Portal site on a different server:
    apic --mode portaladmin --server my_management_server2 --org my_prod_org --catalog my_prod_catalog content:create-import content_createExport-20230627114023.tgz
    Loading File (Large files may take a while)...
    
    201 CREATED - Task ID: zmaskh7oo6531tty
    
    Response Code - 202:
    
    Message(s) -
    The status of this task is: QUEUED
    
    Response Code - 202:
    
    Message(s) -
    The status of this task is: RUNNING
    
    Response Code - 202:
    
    Message(s) -
    The status of this task is: RUNNING
    
    Response Code - 200:
    
    Message(s) -
    2023-10-18 13:36:18: CLI task (content:import) starting.
    2023-10-18 13:36:29: [notice] [1/2] - [node.page:1] "Terms of use" - Updated (https://my_management_server2/my_prod_catalog/tsandcs)
     [notice] [2/2] - [node.page:2] "Privacy Policy" - Updated (https://my_management_server2/my_prod_catalog/privacy)
    2023-10-18 13:37:20: CLI task (content:import) completed successfully.
    Depending on the content imported, the following three types of import can be shown in the import summary messages:
    • Overridden - In this case a content entity existed with the same entity ID but not the same UUID, and there was also no reference to it in the synchronization table, so the entity was overridden. Care must be taken when importing entities across different sites until they are in sync with one another, as data can be lost. For example, say you have a blog post about APIs with an entity ID of 50 on a test site, and you wanted to import this post onto your production site. However, the production site already has a blog post with an entity ID of 50 that talks about policies, in which case that post would be overwritten by the blog post about APIs, and be given the imported UUID. The next time that entity ID of 50 is imported, the import type will be Updated, because the UUID is now the same.
    • Updated - In this case the same content entity, with the same UUID, was found, so its contents were updated with the content from the import file.
    • Created - In this case no content entity of this type was found, so a new entity was created, and it was populated with the data from the import file.
  7. If you ran the content:create-import command with the --no-poll option, you can use the following commands to manage your content import.
    • content:delete-import
      Cancels any currently running content:create-import tasks, and deletes any related artifacts. For example:
      apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:delete-import --task_id task_id
      Where task_id is the ID of the import task on the queue.
    • content:get-import-status
      Returns the status of a specific import task. For example:
      apic --mode portaladmin --server management_server --org orgid/name --catalog catalogid/name content:get-import-status --task_id task_id