Rowlogy
Rowlogy

TypeScript

Learn how to interact with the Rowlogy API using native TypeScript/JavaScript libraries.

You can interact with the Rowlogy API using standard JavaScript/TypeScript features like the fetch API for HTTP communication. This approach gives you full control over your API interactions.

Authentication

All interactions with the Rowlogy API require an API key. You can obtain your API key from your profile page.

When initializing the client library, you will need to provide your API key.

Usage

The Rowlogy API is a RESTful API. You can interact with it using standard HTTP requests.

// Base URL for the Rowlogy API
const BASE_URL = "https://rowlogy.com/api/"; // Replace with the actual API base URL

// It's recommended to store your API key in an environment variable
const API_KEY = process.env.ROWLOGY_API_KEY;

if (!API_KEY) {
    throw new Error("ROLOGY_API_KEY environment variable not set.");
}

const HEADERS = {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
};

async function getProjectContent(username: string, projectId: string) {
    /**
     * Retrieves project content from the Rowlogy API.
     */
    const url = `${BASE_URL}/users/${username}/projects/${projectId}/content`;
    try {
        const response = await fetch(url, { headers: HEADERS });
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return await response.json();
    } catch (error) {
        console.error("Error retrieving project content:", error);
        throw error;
    }
}

async function updateProjectContent(username: string, projectId: string, content: object) {
    /**
     * Updates project content on the Rowlogy API.
     */
    const url = `${BASE_URL}/users/${username}/projects/${projectId}/content`;
    try {
        const response = await fetch(url, {
            method: "POST",
            headers: HEADERS,
            body: JSON.stringify(content),
        });
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return await response.json();
    } catch (error) {
        console.error("Error updating project content:", error);
        throw error;
    }
}

Retrieve Project Content

You can retrieve project content using a GET request to the Rowlogy API.

Using Fetch API

// Base URL for the Rowlogy API
const BASE_URL = "https://rowlogy.com/api/"; // Replace with the actual API base URL

// It's recommended to store your API key in an environment variable
const API_KEY = process.env.ROWLOGY_API_KEY;

if (!API_KEY) {
    throw new Error("ROWLOGY_API_KEY environment variable not set.");
}

const HEADERS = {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
};

async function getProjectContentFetch(username: string, projectId: string) {
    /**
     * Retrieves project content from the Rowlogy API using Fetch API.
     */
    const url = `${BASE_URL}/users/${username}/projects/${projectId}/content`;
    try {
        const response = await fetch(url, { headers: HEADERS });
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return await response.json();
    } catch (error) {
        console.error("Error retrieving project content with Fetch:", error);
        throw error;
    }
}

// Example Usage (Fetch):
// getProjectContentFetch("your-username", "your-project-id")
//     .then(content => console.log("Retrieved Content (Fetch):", content))
//     .catch(error => console.error("Failed to retrieve content (Fetch):", error));

Using Axios

import axios from "axios";

// Base URL for the Rowlogy API
const BASE_URL = "https://rowlogy.com/api/"; // Replace with the actual API base URL

// It's recommended to store your API key in an environment variable
const API_KEY = process.env.ROWLOGY_API_KEY;

if (!API_KEY) {
    throw new Error("ROWLOGY_API_KEY environment variable not set.");
}

const HEADERS = {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
};

async function getProjectContentAxios(username: string, projectId: string) {
    /**
     * Retrieves project content from the Rowlogy API using Axios.
     */
    const url = `${BASE_URL}/users/${username}/projects/${projectId}/content`;
    try {
        const response = await axios.get(url, { headers: HEADERS });
        return response.data;
    } catch (error) {
        console.error("Error retrieving project content with Axios:", error);
        throw error;
    }
}

// Example Usage (Axios):
// getProjectContentAxios("your-username", "your-project-id")
//     .then(content => console.log("Retrieved Content (Axios):", content))
//     .catch(error => console.error("Failed to retrieve content (Axios):", error));

Update Project Content

You can update project content using a POST request to the Rowlogy API.

Using Fetch API

// Base URL for the Rowlogy API
const BASE_URL = "https://rowlogy.com/api/"; // Replace with the actual API base URL

// It's recommended to store your API key in an environment variable
const API_KEY = process.env.ROWLOGY_API_KEY;

if (!API_KEY) {
    throw new Error("ROWLOGY_API_KEY environment variable not set.");
}

const HEADERS = {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
};

async function updateProjectContentFetch(username: string, projectId: string, content: object) {
    /**
     * Updates project content on the Rowlogy API using Fetch API.
     */
    const url = `${BASE_URL}/users/${username}/projects/${projectId}/content`;
    try {
        const response = await fetch(url, {
            method: "POST",
            headers: HEADERS,
            body: JSON.stringify(content),
        });
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return await response.json();
    } catch (error) {
        console.error("Error updating project content with Fetch:", error);
        throw error;
    }
}

// Example Usage (Fetch):
// const newContentFetch = { key: "value", another_key: "another_value" };
// updateProjectContentFetch("your-username", "your-project-id", newContentFetch)
//     .then(result => console.log("Update Result (Fetch):", result))
//     .catch(error => console.error("Failed to update content (Fetch):", error));

Using Axios

import axios from "axios";

// Base URL for the Rowlogy API
const BASE_URL = "https://rowlogy.com/api/"; // Replace with the actual API base URL

// It's recommended to store your API key in an environment variable
const API_KEY = process.env.ROWLOGY_API_KEY;

if (!API_KEY) {
    throw new Error("ROWLOGY_API_KEY environment variable not set.");
}

const HEADERS = {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
};

async function updateProjectContentAxios(username: string, projectId: string, content: object) {
    /**
     * Updates project content on the Rowlogy API using Axios.
     */
    const url = `${BASE_URL}/users/${username}/projects/${projectId}/content`;
    try {
        const response = await axios.post(url, content, { headers: HEADERS });
        return response.data;
    } catch (error) {
        console.error("Error updating project content with Axios:", error);
        throw error;
    }
}

// Example Usage (Axios):
// const newContentAxios = { key: "value", another_key: "another_value" };
// updateProjectContentAxios("your-username", "your-project-id", newContentAxios)
//     .then(result => console.log("Update Result (Axios):", result))
//     .catch(error => console.error("Failed to update content (Axios):", error));