LogoLogo
Log InSign UpHomepage
  • 👋Welcome
  • Account and Team Setup
    • Sign up
    • Subscription Plans
    • Profile information
    • Account information
    • Roles
    • Users
    • Tags
    • Logs
  • FAQ
  • UNDERSTANDING MACHINE LEARNING
    • What is Graphite Note?
      • Graphite Note Insights Lifecycle
    • Introduction to Machine Learning
      • What is Machine Learning
      • Data Analitycs Maturity
    • Machine Learning concepts
      • Key Drivers
      • Confusion Matrix
      • Supervised vs Unsupervised ML
  • Demo datasets
    • Demo Datasets
      • Ads
      • Churn
      • CO2 Emission
      • Diamonds
      • eCommerce Orders
      • Housing Prices
      • Lead Scoring
      • Mall Customers
      • Marketing Mix
      • Car Sales
      • Store Item Demand
      • Upsell
    • What Dataset do I need for my use case?
      • Predict Cross Selling: Dataset
      • Predict Customer Churn: Dataset
      • Predictive Lead Scoring: Dataset
      • Predict Revenue : Dataset
      • Product Demand Forecast: Dataset
      • Predictive Ads Performance: Dataset
      • Media Mix Modeling (MMM): Dataset
      • Customer Lifetime Value Prediction : Dataset
      • RFM Customer Segmentation : Dataset
    • Dataset examples - from online sources
      • Free datasets for Machine Learning
  • Datasets
    • Introduction
    • Prepare your Data
      • Data Labeling
      • Expanding datasets
      • Merging datasets
      • CSV File creating and formatting
    • Data sources in Graphite Note
      • Import data from CSV file
        • Re-upload or append CSV
        • CSV upload troubleshooting tips
      • MySQL Connector
      • MariaDB Connector
      • PostgreSQL Connector
      • Redshift Connector
      • Big Query Connector
      • MS SQL Connector
      • Oracle Connector
  • Models
    • Introduction
    • Preprocessing Data
    • Machine Learning Models
      • Timeseries Forecast
      • Binary Classification
      • Multiclass Classification
      • Regression
      • General Segmentation
      • RFM Customer Segmentation
      • Customer Lifetime Value
      • Customer Cohort Analysis
      • ABC Pareto Analysis
      • New vs Returning Customers
    • Advanced ML model settings
      • Actionable insights
      • Advanced parameters
      • Model Overview
      • Regressors
      • Model execution logs
    • Predict with ML Models
    • Improve your ML Models
  • Notebooks
    • What is Notebook?
    • My first Notebook
    • Data Visualization
  • REST API
    • API Introduction
    • Dataset API
      • Create
      • Fill
      • Complete
    • Prediction API
      • Request v1
        • Headers
        • Body
      • Request v2
        • Headers
        • Body
      • Response
      • Usage Notes
    • Model Results API
      • Request
        • Headers
        • Body
      • Response
      • Usage Notes
      • Code Examples
    • Model Info API
      • Request
        • Headers
        • Body
      • Response
      • Usage notes
      • Code Examples
Powered by GitBook
On this page
  • Python code example
  • PHP Code Example
  • Tips & Best Practices

Was this helpful?

Export as PDF
  1. REST API
  2. Model Results API

Code Examples

This page provides practical examples for interacting with the Model Results API using both Python and PHP. The Model Results API allows you to retrieve paginated outputs from your Graphite Note model

Python code example

1. We use the requests library to send a POST request to the /fetch-result endpoint.

2. We pass the Authorization header with a valid token, as well as Content-Type: application/json.

3. The payload includes page and page-size parameters to fetch paginated results.

4. We handle any HTTP exceptions using raise_for_status() and basic exception catching.

import requests

# Replace {model-code} with your specific model code
url = "https://test-app.graphite-note.com/api/model/fetch-result/{model-code}"

# Insert your Graphite Note tenant token
headers = {
    "Authorization": "Bearer YOUR-TENANT-TOKEN",
    "Content-Type": "application/json"
}

# Request payload
payload = {
    "page": 1,
    "page-size": 10000
}

try:
    response = requests.post(url, json=payload, headers=headers)
    response.raise_for_status()  # Raises an exception for 4XX/5XX errors
    
    # Parse JSON response
    data = response.json()
    print("Request successful!")
    print("Response Data:", data)
except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")

PHP Code Example

1. We use cURL in PHP to send a POST request to the /fetch-result endpoint.

2. We set both the Authorization header (with a bearer token) and Content-Type.

3. We pass the page and page-size parameters in JSON format.

4. We then parse the JSON response if the request is successful (HTTP status code 200). Otherwise, we print an error message.

<?php
// Replace {model-code} with your specific model code
$url = "https://test-app.graphite-note.com/api/model/fetch-result/{model-code}";

// Insert your Graphite Note tenant token
$headers = [
    "Authorization: Bearer YOUR-TENANT-TOKEN",
    "Content-Type: application/json"
];

// Request payload
$payload = [
    "page" => 1,
    "page-size" => 10000
];

// Initialize cURL
$ch = curl_init($url);

// Configure cURL options
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute the POST request
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Close the connection
curl_close($ch);

// Handle the response
if ($http_code === 200) {
    $data = json_decode($response, true);
    echo "Request successful!\n";
    print_r($data);
} else {
    echo "Error: HTTP status code $http_code\n";
    echo $response;
}

Tips & Best Practices

• Always use HTTPS (as shown above) to ensure data security.

• Replace YOUR-TENANT-TOKEN with the valid token assigned to your Graphite Note tenant.

• Adjust page and page-size to match how many records you want per request.

• Handle potential rate-limiting (e.g., 429 Too Many Requests status) by adding retry logic if needed.

• For production environments, consider using more robust error handling and logging.

PreviousUsage NotesNextModel Info API

Last updated 3 months ago

Was this helpful?