Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

Dev Guide
Dev GuideUser GuidesGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Advanced

Instructions on defining an app's data schema in Optimizely Connect Platform (OCP).

You can define the app's data schema in your development environment, which involves creating and defining any custom objects, fields, and relationships necessary to store the data your app will handle.

Define the schema

In the src/schema folder, you can define the data tables, fields, and relationships needed for your app. All .yml files within refer to objects in OCP. These represent the data that users can select and sync to their Optimizely products in the OCP UI. When a user installs your app, what you define here is added to their OCP data schema.

🚧

Important

You must prefix object names with your app ID, and prefix the object display names with your app display name. For example, if your app ID is my_app and the display name is My App, prefix object names with my_app, like my_app_customer_service_tickets, and prefix object display names with My App, like My App Customer Service Tickets.

You do not have to do this for fields within an object that your app creates.

  1. Define any custom objects your app needs. For example, if you want to create a Commerce Products object, you need to create a src/schema/commerce_products.yml file, which might look like the following:

    name: my_app_commerce_products # internal name for the data table aka ‘object’  
    display_name: My App Commerce Products # the name that will show in the OCP UI for the object  
    fields:
    	- name: commerce_product_id # internal name of field. This is an example of creating the 			primary key for the object  
     		type: string # field type, options are: number, boolean, string, timestamp  
     		display_name: CS Ticket ID # name that will show in the OCP UI for the field  
     		description: Unique identifier of the ticket # description will appear on hover of the 			field in the OCP UI  
     		primary: true # denotes the field is the primary key for the object
    	- name: name # internal name of field  
     		type: string # field type  
     		display_name: Name # name that will show in the OCP UI for the field  
     		description: The name of the product # description will appear on hover of the 							field in the OCP UI
    	- name: price  
    		type: number  
    		display_name: Price 
    		description: The price of the product
    
  2. Define a relationship between objects. You can define relationships between objects should your app need to do so based on the data model of the external system you are connecting to. The following is an example of a product_category object containing a relation to the previously defined my_app_commerce_products object. Define the product_category object in a src/schema/my_app_commerce_product_categories.yml file, which might look like the following:

    name: my_app_commerce_product_categories
    display_name: My App Commerce Product Categories
    fields:
     - name: commerce_product_category_id
        display_name: Commerce Product Category ID
        type: string
        primary: true
      - name: commerce_product_id
        display_name: Commerce Product ID
        type: string
      - name: category_name
        display_name: Category Name
        type: string
    relations:
      - name: product
        display_name: Product
        child_object: my_app_commerce_products
    
        join_fields:
          - parent: commerce_product_id
            child: commerce_product_id