POST
/
api
/
create-script
Create Script
curl --request POST \
  --url https://onlyautomator.com/api/create-script \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "New Script Name",
  "text": "Script content here.",
  "folder_id": "folder_456"
}'
{
  "status": 200,
  "message": "Script created successfully",
  "script": {
    "id": "new_script_uuid"
  }
}
Adds a new script record to the scripts table, associated with a specific folder and the authenticated user. This endpoint requires at least a ‘Basic’ plan.

Authentication & Authorization

This endpoint requires authentication via bearer token representing a valid user session managed by Supabase Auth (cookies).Plan Restriction: Access is restricted to users with a ‘Basic’ or ‘Pro’ plan. Users on the ‘Free’ plan will receive a 403 Forbidden error.Testing Note: Requires user session and paid plan.
Retrieving JWT Token: (Refer to other endpoints for instructions)

Request

Authorization
string
required
Bearer token for authentication. Format: Bearer YOUR_JWT_TOKEN
name
string
required
The name of the script.
text
string
required
The content/body of the script.
folder_id
string | number
required
The ID of the folder where the script should be placed.

Response

status
number
HTTP status code (e.g., 200).
message
string
A descriptive message about the result (e.g., “Script created successfully”).
script
object
The created script data object from the scripts table.

Error Codes

Status CodeDescriptionExample Message
400Missing required fields (name, text, folder_id).”Missing required fields”
401Invalid or missing authentication token.”Unauthorized”
403User is on the ‘Free’ plan.”Please upgrade your plan to access this feature.”
500Internal server error during processing.”Failed to create script”
500Database error during insert.Specific DB error

Notes

  • Creates a new script entry associated with the authenticated user.
  • Requires the user to be on a paid plan (‘Basic’ or ‘Pro’).
  • Assumes a scripts table exists.

Code Examples

// Using fetch
const createScript = async (scriptData, apiToken) => {
  const response = await fetch(`https://onlyautomator.com/api/create-script`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${apiToken}`
    },
    body: JSON.stringify(scriptData)
  });

  if (!response.ok) {
     const errorData = await response.json();
     throw new Error(`API Error (${response.status}): ${errorData.error || 'Unknown error'}`);
  }
  return await response.json();
};

// Example usage
const newScript = {
  name: "Welcome Message",
  text: "Hello there! Thanks for subscribing.",
  folder_id: "folder_123"
};

createScript(newScript, 'your_api_token')
  .then(data => console.log('Script created:', data.script))
  .catch(error => console.error('Error creating script:', error));

Headers

Authorization
string
required

Bearer token for authentication (JWT)

Body

application/json
name
string
required
Example:

"New Script Name"

text
string
required
Example:

"Script content here."

folder_id
string
required
Example:

"folder_456"

Response

Script created successfully.

status
number
Example:

200

message
string
Example:

"Script created successfully"

script
object