Skip to content
Last update: July 5, 2024

Generate API client

This guide describes the process of generating an API client to access the VC Platform API from your custom application.

Note

Platform Manager REST Client offers generated REST API methods that make it easy to interact with the existing VirtoCommerce Platform API.

Prerequisites

  • .NET Core 6.0, particularly if you are using MacOS or Linux.

Generate TypeScript API clients

To enable TypeScript API client generation in your project:

  1. Make sure your project has the necessary dependencies, if not - add dependencies to your project:

    yarn add @vc-shell/api-client-generator cross-env
    

    cross-env runs scripts that set and use environment variables across platforms.

    Readmore Cross Env

    Add the dependencies to your project's package.json:

    vc-app/package.json
    1
    2
    3
    4
    5
    6
    7
    8
    9
    {
        ...
        "devDependencies": {
            ...
            "@vc-shell/api-client-generator": "latest",
            "cross-env": "latest",
            ...
        }
    }
    
  2. Configure client generation in your project. Inside your project's package.json file, add a "generate-api-client" command to the list of scripts:

    vc-app-extend/package.json
    1
    2
    3
    4
    5
    6
    {
        "scripts": {
        ...
        "generate-api-client": cross-env api-client-generator --APP_PLATFORM_MODULES='[Virtocommerce.MarketplaceVendor,Virtocommerce.Catalog,Virtocommerce.Orders]' --APP_API_CLIENT_DIRECTORY=./src/api_client/
        }
    }
    

    The options are listed in the table below:

    Options Description Example
    --APP_PLATFORM_MODULES Platform modules with namespaces to generate API client.
    string[]
    Customize the --APP_PLATFORM_MODULES list
    to match your project's requirements.
    --APP_PLATFORM_MODULES='[Virtocommerce.MarketplaceVendor,Virtocommerce.Orders,Virtocommerce.Catalog]'
    --APP_API_CLIENT_DIRECTORY Output directory for generated API clients.
    string
    --APP_API_CLIENT_DIRECTORY=./src/api_client/
    --APP_PLATFORM_URL Platform URL to obtain client API configs.
    string
    --APP_PLATFORM_URL=https://vcmp-dev.govirto.com/
  3. Configure Platform URL to ensure your project can access the platform's API configurations. Add the platform URL to your project's .env file:

    vc-app-extend/.env
    APP_PLATFORM_URL=https://vcmp-dev.govirto.com/
    

    Note

    Alternatively, you can specify the Platform URL as a command option in the previous step when running the "generate-api-client" command.

  4. Generate the API clients using the following command:

    yarn generate-api-client
    

This command generates the required API clients for your custom application. Now you can effortlessly access the VC Platform API from your custom application using the generated API client.