SimpleSpa Documentation
Back to SimpleSpa
  • SimpleSpa Documentation
  • Scheduling Software
    • What is Scheduling Software
    • What is Salon Software
    • What is Spa Software
    • What is Medical Scheduling Software
    • What is Medi-Spa Scheduling Software
    • What is Microblading Software
  • Guides
    • General
    • Adding your first Service/Staff
    • Creating your first Appointment
    • Creating your first Transaction/Checking out a Client
  • Fundamentals
    • Dashboard
      • Overview
      • Viewing Appointments
      • Viewing Transactions
      • Making a Sale
      • Birthdays
    • Appointments
      • Calendar
      • Creating an Appointment
      • Appointment Status
      • Appointment Notes
      • Appointment Checkout
      • Creating a Block
      • Cloning a Block
    • POS
      • Recording a Sale
      • Balances & Deposits
      • Multiple Payment Methods
      • Processing Credit Cards
      • PCI Compliance
      • Common Checkouts & Tutorial Walkthroughs
        • Accepting Multiple Payments
        • Using Gift Certificates in Checkout
        • Accepting Appointment Deposits
        • Adding a Balance to a client
        • Assigning Staff during Checkout
        • Prompting and Collecting Tips
        • Applying Discounts during Checkout
        • Applying Notes & Change Calculator
    • Hardware
      • Receipt Printing
      • Thermal Receipt
      • Receipt Printer Setup
      • Cash drawer / Till
      • POS Terminal
    • Staff
      • Managing Staff
      • Fields and Settings
      • Calendar
      • Commissions Tab
      • Weekly Schedule Tab
      • Block Hours on Calendar
      • Breaks Tab
      • Clock In/Out Tab
      • How to Clock In/Out
      • Assigning Specialties
      • Staff Login
    • Clients
      • Managing Clients
      • Files
      • Images
      • Notes
      • Appointments
      • Transactions
      • Packages
      • Forms
    • Services
      • Managing Services
      • Fields and Service Settings
      • Adding Form(s) to Services
      • Assigning Resources to a Service
    • Products
      • Managing Products
      • Fields and Products Settings
      • Assign Tax Rate to all Products
      • Inventory
      • Orders
      • Vendors
    • Gift Cards
      • Gift Cards & Gift Certificates
      • Selling Gift Cards/Certificates
      • Sending Gift Cards/Certificates
      • Using Gift Cards/Certificates
      • Reloading Gift Cards/Certificates
      • Viewing Balance Gift Cards/Certificates
      • Viewing History Gift Cards/Certificates
      • Apple Wallet
    • Packages
      • Managing Packages
      • Selling Packages
      • Redeeming Packages
      • Manually Adjusting Clients Package Balance
      • Memberships
    • Forms
      • Managing Forms
      • Additional Settings
      • Additional Questions (Form Editor)
      • Assigning to a Service
      • Sending a Form
    • Users
      • Manage Users
      • User Roles
      • User Password
    • Discounts
      • Managing Discounts
      • Applying Discounts
    • Expenses
      • Managing Expenses
    • Online Booking
      • Your Custom Booking URL
      • Multiple Bookings
      • Accepting Deposits for Bookings
      • Linking & Embedding Online Booking
      • Adding a Holiday
      • Waitlist
    • Notifications
      • Email Notifications
      • SMS/Text Notifications
    • Marketing
      • Campaigns
      • Creating a New Campaign
      • Image Campaign
      • AI Campaign Generator
    • Mobile Device Support
      • iOS (iPhone & iPad)
      • Android
    • Browser Support
  • Extras
    • Video Walkthroughs
      • Creating your first appointment
      • Using the POS & completing an appointment
      • Making a sale without an appointment
      • Demo Walkthrough
    • FAQ
      • Is there anything to install?
      • Can I import my existing data to SimpleSpa?
      • How much does SimpleSpa cost?
      • Where can I get a SimpleSpa perpetual license?
      • How do I convert my SimpleSpa free trial to a paid subscription?
      • What kind of computer do I need?
      • What countries do you support?
      • How can I view the timestamp an appointment was created?
      • Do I need to download updates to my computer?
      • Does SimpleSpa have online booking?
      • Is online booking in my language?
      • How does SimpleSpa handle double booking for online appointments?
      • Does SimpleSpa send appointment reminders?
      • Does SimpleSpa send SMS/Text reminders?
      • How much does SMS/Text Notifications cost?
      • How can I add SMS/Text Notifications to my account?
      • Are the SimpleSpa Marketing Tools included in my plan?
      • I am already paying for SMS Notifications is SMS Marketing included in my package?
      • What businesses can use SimpleSpa?
      • Can I brand SimpleSpa with my logo?
      • Can I process Credit Cards with SimpleSpa?
      • What type of Credit Card Integration does SimpleSpa Support?
      • How can I disable Credit Card Auto-fill in Chrome?
      • Do plans have a minimum contract?
      • Can I downgrade my plan?
      • I am trying to login but it is redirecting to SimpleSpa.com
      • Does SimpleSpa Support Parallel Bookings
      • Does SimpleSpa support multiple business locations?
      • My online booking hours show different availability than what I have set in the staff page
      • I am a third party processor/reseller, can I work with SimpleSpa?
      • My staff will work on a different schedule on a specific date, can SimpleSpa handle this?
      • My online booking is not showing availability although I am available in my calendar
      • SimpleSpa HIPAA
      • How does SimpleSpa transmit data securely?
      • How is the data on the SimpleSpa network protected?
      • Can you provide me with more information about your data centers?
      • SimpleSpa iOS
  • API
    • SimpleSpa Enterprise API
      • Appointment Endpoint
      • Client Endpoint
      • Service Endpoint
      • Staff Endpoint
      • Ideas & Inspiration
      • Integrations
        • Zapier
        • Make.com
        • OpenAI
        • OpenAI & Cron Jobs
        • Ideas: Marketing Campaigns with Zapier, Make.com, Integrately
Powered by GitBook
On this page
  • Flow
  • React
  • What This React App Does:
  • PHP
  1. API
  2. SimpleSpa Enterprise API
  3. Integrations

OpenAI

Here is an easy integration flow to start using OpenAI with the SimpleSpa API

Flow

SimpleSpa API (/clients.php)
        ↓
Filter Clients (birthday month = this month)
        ↓
For Each Client:
    ↓
    → Create custom prompt (Name + Birthday)
    → Send to OpenAI (ChatGPT API)
    → Receive Birthday Message
    → (Optional) Send email via Mailchimp/Gmail

React

npm create vite@latest birthday-ai-app -- --template react
cd birthday-ai-app
npm install axios
npm run dev

Then replace src/App.jsx with this:

import { useEffect, useState } from 'react';
import axios from 'axios';

function App() {
  const [clients, setClients] = useState([]);
  const [messages, setMessages] = useState([]);
  const [loading, setLoading] = useState(true);

  const simpleSpaApiKey = 'YOUR_SIMPLESPA_API_KEY';
  const openaiApiKey = 'YOUR_OPENAI_API_KEY';
  const simpleSpaApiUrl = 'https://my.simplespa.com/api/clients.php';
  const todayMonth = new Date().getMonth() + 1; // JS months are 0-indexed
  const todayDay = new Date().getDate();

  useEffect(() => {
    async function fetchClientsAndMessages() {
      try {
        // Step 1: Fetch clients
        const response = await axios.post(
          simpleSpaApiUrl,
          {
            dob_month: todayMonth,
            dob_day: todayDay,
            page: 1,
            per_page: 100
          },
          {
            headers: {
              Authorization: `Bearer ${simpleSpaApiKey}`,
              'Content-Type': 'application/json'
            }
          }
        );

        const clients = response.data.clients || [];
        setClients(clients);

        // Step 2: Generate birthday messages
        const newMessages = [];

        for (const client of clients) {
          const name = client.firstname || 'Client';

          const aiResponse = await axios.post(
            'https://api.openai.com/v1/chat/completions',
            {
              model: 'gpt-4', // or 'gpt-3.5-turbo'
              messages: [
                { role: 'system', content: 'You are a creative assistant for a spa.' },
                { role: 'user', content: `Write a short, warm, friendly birthday message for a client named ${name}.` }
              ],
              temperature: 0.7
            },
            {
              headers: {
                Authorization: `Bearer ${openaiApiKey}`,
                'Content-Type': 'application/json'
              }
            }
          );

          const message = aiResponse.data.choices[0]?.message?.content || 'Happy Birthday!';
          newMessages.push({ name, email: client.email, message });
        }

        setMessages(newMessages);
      } catch (error) {
        console.error('Error fetching clients or generating messages:', error);
      } finally {
        setLoading(false);
      }
    }

    fetchClientsAndMessages();
  }, []);

  return (
    <div style={{ padding: '2rem', fontFamily: 'Arial, sans-serif' }}>
      <h1>🎉 Birthday Messages</h1>

      {loading ? (
        <p>Loading...</p>
      ) : messages.length === 0 ? (
        <p>No birthdays today!</p>
      ) : (
        <div>
          {messages.map((item, index) => (
            <div key={index} style={{ marginBottom: '2rem', padding: '1rem', background: '#f9f9f9', borderRadius: '8px' }}>
              <h3>{item.name} ({item.email})</h3>
              <p>{item.message}</p>
            </div>
          ))}
        </div>
      )}
    </div>
  );
}

export default App;

What This React App Does:

Step

Action

1

Calls your SimpleSpa API to get today’s birthday clients

2

For each client, calls OpenAI and generates a unique message

3

Displays the generated birthday messages on the screen

PHP

To do this directly on your webserver you can also create a PHP file that generates this message

<?php
// Configuration
$simpleSpaApiUrl = 'https://my.simplespa.com/api/clients.php';
$simpleSpaApiKey = 'YOUR_SIMPLESPA_API_KEY_HERE';

$openaiApiKey = 'YOUR_OPENAI_API_KEY_HERE';
$openaiModel = 'gpt-4'; // or 'gpt-3.5-turbo' if you want cheaper
$todayMonth = date('n'); // 1-12
$todayDay = date('j');   // 1-31

// 1. Fetch clients with birthday today
$clients = fetchClientsWithBirthdayToday($simpleSpaApiUrl, $simpleSpaApiKey, $todayMonth, $todayDay);

if (empty($clients)) {
    echo "No clients found with birthday today.\n";
    exit;
}

foreach ($clients as $client) {
    $firstname = $client['firstname'];
    $email = $client['email'];

    // 2. Generate a birthday message with OpenAI
    $message = generateBirthdayMessage($firstname, $openaiApiKey, $openaiModel);

    // Output
    echo "🎉 Birthday Message for {$firstname} ({$email}):\n";
    echo $message . "\n\n";
}

// Functions

function fetchClientsWithBirthdayToday($apiUrl, $apiKey, $month, $day) {
    $postData = json_encode([
        'dob_month' => (int)$month,
        'dob_day' => (int)$day,
        'page' => 1,
        'per_page' => 100
    ]);

    $ch = curl_init($apiUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json'
    ]);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_POST, true);

    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'SimpleSpa API error: ' . curl_error($ch) . "\n";
        return [];
    }
    curl_close($ch);

    $data = json_decode($response, true);
    if (isset($data['clients']) && is_array($data['clients'])) {
        return $data['clients'];
    }
    return [];
}

function generateBirthdayMessage($clientName, $openaiKey, $model) {
    $prompt = "Write a short, warm, friendly birthday message for a client named {$clientName}.";

    $payload = json_encode([
        'model' => $model,
        'messages' => [
            ['role' => 'system', 'content' => 'You are a creative assistant for a beauty spa.'],
            ['role' => 'user', 'content' => $prompt]
        ],
        'temperature' => 0.7
    ]);

    $ch = curl_init('https://api.openai.com/v1/chat/completions');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $openaiKey,
        'Content-Type: application/json'
    ]);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_POST, true);

    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'OpenAI API error: ' . curl_error($ch) . "\n";
        return 'Happy Birthday!';
    }
    curl_close($ch);

    $data = json_decode($response, true);
    if (isset($data['choices'][0]['message']['content'])) {
        return trim($data['choices'][0]['message']['content']);
    }
    return 'Happy Birthday!';
}
?>

PreviousMake.comNextOpenAI & Cron Jobs

Last updated 15 days ago