Building a Schema

MarketPay's Schema Builder empowers companies to create custom JSON schemas tailored to their unique data processing needs. By defining specific inputs and outputs, you can efficiently handle unstructured text or images, transforming them into structured data for analysis, storage, or further processing.

This guide provides extensive documentation on using the Schema Builder and interacting with our API. You'll learn how to:

  • Build custom schemas using our intuitive interface.

  • Define fields, data types, and nested structures.

  • Integrate with the API to submit data and receive structured responses.

  • Utilize examples to accelerate your development process.


Understanding Schemas

A schema is a blueprint that defines the structure of your data. In the context of MarketPay, a schema specifies the expected fields, data types, and hierarchical relationships within your JSON data. By creating a schema, you:

  • Ensure Data Consistency: Validate incoming data against the schema to maintain uniformity.

  • Facilitate Data Processing: Streamline parsing and processing by knowing the exact data structure.

  • Enhance Data Validation: Automatically check for required fields and correct data types.


Using the Schema Builder

Our Schema Builder offers two primary methods for creating schemas:

  1. Click-to-Build Interface: An interactive UI that allows you to construct schemas without writing code.

  2. Copy-and-Paste Functionality: Directly paste your existing JSON schema for quick setup.

Click-to-Build Schema Builder

The interactive Schema Builder provides a user-friendly interface to define your schema's fields and structure.

Steps to Build a Schema:

  1. Access the Schema Builder: Navigate to the Schema Builder in your MarketPay dashboard.

  2. Add Fields: Click on the "Add Field" button to create a new field.

  3. Define Field Attributes:

    • Key: A unique identifier for the field (e.g., damage_location).

    • Field Name: A human-readable name (e.g., Damage Location).

    • Type: Choose the data type (e.g., string, number, boolean, array, object, picklist, multi-select-picklist).

    • Description: Provide a brief explanation of the field's purpose.

  4. Specify Possible Values (for picklists):

    • Enter possible values for single or multi-select picklists.

  5. Add Nested Fields (for objects and arrays):

    • Expand the field to add child fields, defining their attributes similarly.

  6. Review and Save: Once all fields are defined, review your schema and save it.

Field Types Explained:

  • String: Textual data.

  • Number: Numerical data.

  • Boolean: true or false values.

  • Array: A list of items, which can be of any data type.

  • Object: A nested set of key-value pairs.

  • Picklist: A dropdown selection with predefined options (single selection).

  • Multi-Select Picklist: A selection allowing multiple choices from predefined options.

Copy-and-Paste Functionality

If you have an existing JSON schema, you can directly paste it into the Schema Builder.

Steps:

  1. Switch to Raw JSON View:

    • Toggle the "Interactive View" switch to enter the "Raw JSON View".

  2. Paste Your Schema:

    • Copy your JSON schema and paste it into the text area.

  3. Validate and Edit:

    • The Schema Builder will parse the JSON. You can switch back to the interactive view to make further edits if needed.

  4. Save the Schema:

    • Once satisfied, save your schema for use with the API.


API Specification

Integrate your schema with MarketPay's API to process unstructured text or images and receive structured data based on your schema.

Authentication

All API requests require authentication via an API key.

  • API Key: Obtain your API key from the MarketPay dashboard.

  • Header: Include the API key in the request header as Authorization: Bearer YOUR_API_KEY.

Endpoints

Submit Data for Processing

  • URL: https://api.marketpay.com/v1/process

  • Method: POST

  • Headers:

    • Content-Type: application/json

    • Authorization: Bearer YOUR_API_KEY

  • Body Parameters:

    • schema_id (string): The ID of the schema you want to use.

    • data (object): The unstructured text or images to be processed.

Retrieve Processed Data

  • URL: https://api.marketpay.com/v1/results/{job_id}

  • Method: GET

  • Headers:

    • Authorization: Bearer YOUR_API_KEY

  • Path Parameters:

    • job_id (string): The ID of the processing job.

Request and Response Formats

Submit Data Request Example

POST /v1/process
Host: api.marketpay.com
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY

{
  "schema_id": "abc123",
  "data": {
    "text": "The property has severe roof damage due to the recent hailstorm.",
    "images": ["image1_url", "image2_url"]
  }
}

Submit Data Response Example

{
  "job_id": "job_xyz789",
  "status": "processing",
  "submitted_at": "2023-10-01T12:34:56Z"
}

Retrieve Processed Data Response Example

{
  "job_id": "job_xyz789",
  "status": "completed",
  "completed_at": "2023-10-01T12:45:00Z",
  "results": {
    "Damage Location": ["Roof"],
    "Damage Severity": "Severe",
    "Damage Type": "Hail",
    "Requires Immediate Attention": true,
    "Visible Damage": ["Missing Roof Shingles", "Cracks"]
  }
}

Examples

Example Schema

Below is an example of a schema defining various fields related to property damage assessments.

{
  "Damage Location": {
    "field": "Damage_Location__c",
    "type": "multi-select-picklist",
    "description": "Location of the damage on the property",
    "possible_values": [
      "Roof",
      "Walls",
      "Foundation",
      "Window / Doors",
      "Flooring",
      "Plumbing",
      "Electrical System",
      "Landscaping",
      "Garage"
    ]
  },
  "Damage Severity": {
    "field": "Damage_Severity__c",
    "type": "picklist",
    "description": "The severity level of the damage",
    "possible_values": [
      "Minor",
      "Moderate",
      "Severe",
      "Total Loss"
    ]
  },
  "Damage Type": {
    "field": "Damage_Type__c",
    "type": "picklist",
    "description": "The type of damage sustained by the property",
    "possible_values": [
      "Fire",
      "Water",
      "Wind",
      "Hail",
      "Earthquake",
      "Vandalism",
      "Structural Damage",
      "Roof Damage",
      "Foundation Damage"
    ]
  },
  "Materials Affected": {
    "field": "Materials_Affected__c",
    "type": "multi-select-picklist",
    "description": "Materials that have been affected by the damage",
    "possible_values": [
      "Wood",
      "Concrete",
      "Brick",
      "Drywall",
      "Glass",
      "Roofing Shingles",
      "Metal",
      "Carpet / Flooring"
    ]
  },
  "Requires Immediate Attention": {
    "field": "Requires_Immediate_Attention__c",
    "type": "boolean",
    "description": "Indicates if the damage requires immediate attention"
  },
  "Structural Integrity Concern": {
    "field": "Structural_Integrity_Concern__c",
    "type": "boolean",
    "description": "Indicates if there is a structural integrity concern"
  },
  "Visible Damage": {
    "field": "Visible_Damage__c",
    "type": "multi-select-picklist",
    "description": "Any visible damage on the property",
    "possible_values": [
      "Cracks",
      "Burns / Scorch Marks",
      "Water Stains",
      "Mold / Mildew",
      "Broken Glass",
      "Missing Roof Shingles",
      "Collapsed Walls",
      "Fallen Trees / Debris",
      "Flooding",
      "Fire / Smoke Residue",
      "Rotting Wood"
    ]
  }
}

Example API Requests and Responses

Submitting Data for Processing

Request:

POST /v1/process
Host: api.marketpay.com
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY

{
  "schema_id": "property_damage_assessment",
  "data": {
    "text": "The recent earthquake caused severe foundation cracks and damaged the plumbing system. Immediate attention is required to prevent further structural damage.",
    "images": ["https://example.com/image1.jpg", "https://example.com/image2.jpg"]
  }
}

Response:

{
  "job_id": "job_earthquake123",
  "status": "processing",
  "submitted_at": "2023-10-02T09:15:30Z"
}

Retrieving Processed Data

Request:

GET /v1/results/job_earthquake123
Host: api.marketpay.com
Authorization: Bearer YOUR_API_KEY

Response:

{
  "job_id": "job_earthquake123",
  "status": "completed",
  "completed_at": "2023-10-02T09:20:00Z",
  "results": {
    "Damage Location": ["Foundation", "Plumbing"],
    "Damage Severity": "Severe",
    "Damage Type": "Earthquake",
    "Materials Affected": ["Concrete", "Metal"],
    "Requires Immediate Attention": true,
    "Structural Integrity Concern": true,
    "Visible Damage": ["Cracks", "Broken Pipes"]
  }
}

Conclusion

By leveraging MarketPay's Schema Builder and API, you can effectively transform unstructured text and images into structured data tailored to your business needs. Whether you're assessing property damage, analyzing customer feedback, or processing any form of unstructured data, our tools provide the flexibility and power to get the job done efficiently.

For further assistance, please refer to our API Documentation or contact our support team at [email protected].

Last updated