Creating Picklists Using REST APIs

The headless-admin-list-type service provides REST APIs for performing CRUD operations for picklists. Using these APIs is far more efficient than creating picklists manually through the UI, since you can add lists and items with pre-configured ERCs and localized names all in one step. Here you’ll use these APIs to add the remaining picklists for the Distributor Application object.

  1. Download and unzip the resources for this exercise.

    curl https://resources.learn.liferay.com/courses/latest/en/application-development/modeling-data-structures/liferay-r5w2.zip -O
    
    unzip liferay-r5w2.zip
    

    This .zip file includes shell scripts for creating the remaining picklists using the headless-admin-list-type REST APIs.

  2. Navigate to the curl folder in the liferay-r5w2 folder.

    cd liferay-r5w2/curl
    
  3. Run this script to create the Distribution Regions picklist:

    ./ListTypeDefinition_POST_DistributionRegions_ToInstance.sh
    

    Picklist

    NameExternal Reference Code
    Distribution RegionsLIST_DISTRIBUTION_REGIONS

    Picklist Items

    NameKeyExternal Reference Code
    Latin AmericalatinAmericaREGION_LATIN_AMERICA
    CaribbeancaribbeanREGION_CARIBBEAN
    Eastern EuropeeasternEuropeREGION_EASTERN_EUROPE
    Western EuropewesternEuropeREGION_WESTERN_EUROPE
    Middle EastmiddleEastREGION_MIDDLE_EAST
    AfricaafricaREGION_AFRICA
    Central AsiacentralAsiaREGION_CENTRAL_ASIA
    Asia & Pacific RimasiaPacificRimREGION_ASIA_PACIFIC_RIM
    IndiaindiaREGION_INDIA
    North AmericanorthAmericaREGION_NORTH_AMERICA
  4. Create the Distribution Channels picklist:

    ./ListTypeDefinition_POST_DistributionChannels_ToInstance.sh
    

    Picklist

    NameExternal Reference Code
    Distribution ChannelsLIST_DISTRIBUTION_CHANNELS

    Picklist Items

    NameKeyExternal Reference Code
    Distribute to Other RetailersotherRetailersCHANNEL_OTHER_RETAILERS
    Sell Through Own RetailownRetailCHANNEL_OWN_RETAIL
    E-CommerceeCommerceCHANNEL_E_COMMERCE
  5. Create the Order Types picklist:

    ./ListTypeDefinition_POST_OrderTypes_ToInstance.sh
    

    Picklist

    NameExternal Reference Code
    Order TypesLIST_ORDER_TYPES

    Picklist Items

    NameKeyExternal Reference Code
    WholesalewholesaleORDER_TYPE_WHOLESALE
    Private LabelingprivateLabelingORDER_TYPE_PRIVATE_LABELING
    Bulk FormatsbulkFormatsORDER_TYPE_BULK_FORMATS
    Not SurenotSureORDER_TYPE_NOT_SURE
  6. Create the Product Types picklist:

    ./ListTypeDefinition_POST_ProductTypes_ToInstance.sh
    

    Picklist

    NameExternal Reference Code
    Product TypesLIST_PRODUCT_TYPES

    Picklist Items

    NameKeyExternal Reference Code
    Maple SyrupmapleSyrupPRODUCT_TYPE_MAPLE_SYRUP
    Organic Maple SyruporganicMapleSyrupPRODUCT_TYPE_ORGANIC_MAPLE_SYRUP
    Maple ButtermapleButterPRODUCT_TYPE_MAPLE_BUTTER
    Maple SugarmapleSugarPRODUCT_TYPE_MAPLE_SUGAR
    Maple FondantmapleFondantPRODUCT_TYPE_MAPLE_FONDANT
    Maple JellymapleJellyPRODUCT_TYPE_MAPLE_JELLY
    TreestreesPRODUCT_TYPE_TREES
    SaplingssaplingsPRODUCT_TYPE_SAPLINGS
    Educational ContenteducationalContentPRODUCT_TYPE_EDUCATIONAL_CONTENT
    OtherotherPRODUCT_TYPE_OTHER
  7. Create the Annual Purchase Volumes picklist:

    ./ListTypeDefinition_POST_AnnualPurchaseVolumes_ToInstance.sh
    

    Picklist

    NameExternal Reference Code
    Annual Purchase VolumesLIST_ANNUAL_PURCHASE_VOLUMES

    Picklist Items

    NameKeyExternal Reference Code
    $50,000 - 100,000 USDfirstTierVOLUME_FIRST_TIER
    $200,000 - 500,000 USDsecondTierVOLUME_SECOND_TIER
    $500,000 - 1M USDthirdTierVOLUME_THIRD_TIER
    $1M+ USDfourthTierVOLUME_FOURTH_TIER
  8. Create the Product Labels picklist:

    ./ListTypeDefinition_POST_ProductLabels_ToInstance.sh
    

    Picklist

    NameExternal Reference Code
    Product LabelsLIST_PRODUCT_LABELS

    Picklist Items

    NameKeyExternal Reference Code
    Standard USstandardUSLABEL_STANDARD_US
    LocalizedlocalizedLABEL_LOCALIZED

When finished, you should have seven picklists:

Create these picklists for use in the Distributor Application object.

You can now use them to create single-select and multi-select fields in the Distributor Application object.

Next: Adding Picklist Fields to the Object

Relevant Concepts

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy