API Documentation
Welcome to our API documentation. Follow the steps below to get started:
1) Create an API Key
When you register on Pariette and create an environment, you will be given a 32-character Pariette Token. Please store this token securely. If you lose it, don’t worry — we will help you.
2) Configuration
All you need is your Pariette Token! With the token we provide, you can perform unlimited operations.
API Anahtarınız
.envenvironment
PARIETTE_API_URL="https://live.pariette.com/api/public/"
PARIETTE_TOKEN=your_api_key_here
PARIETTE_LOCALE=enLet's assume you are communicating using Axios. You can modify the sample API request function below to suit your needs.
response handlertypescript
const apiRequest = async (
url: string,
method = "GET",
body = null,
) => {
try {
const response = await axios({
method,
url: process.env.PARIETTE_API_URL + url,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
ParietteToken: process.env.PARIETTE_TOKEN,
Locale: process.env.PARIETTE_LOCALE,
},
data: body,
});
return response.data;
} catch (error: any) {
if (
error.response.data.status == true ||
error.response.data.status == false
) {
return {
code: error?.response?.status,
status: error?.response?.data?.status,
text: error?.response?.data?.statusText,
message: error?.response?.data?.message,
errors: error?.response?.data?.errors,
};
} else if (error.request) {
return {
status: false,
code: error?.request?.status,
text: error?.request?.statusText,
message: error?.message,
};
} else {
return {
status: error?.status,
text: error?.message,
};
}
}
}Everything looks good, let's move on to the next step...
Now let's create a POST method
POST responsetypescript
export const $post = (url: string, body: null | any, headers = {}) => {
return apiRequest(url, "POST", body, headers);
};If everything is correct, let's continue.
Now let's create a GET method
GET responsetypescript
export const $get = (url: string, headers = {}) => {
return apiRequest(url, "GET", null, headers);
};Now that our request methods are complete, we can proceed to the next step.
3) Send Your First Request
Send your first API request using the SDK. You can start with a simple GET request.
Demo Layouttypescript
"use client";
import { useState, useEffect } from 'react';
import { $get, glob } from '@/lib/pariette'
import PageLoader from '@/app/components/PageLoader';
import PageError from '@/app/components/PageError';
interface LayoutError {
status: boolean;
code: number;
title: string;
message: string;
}
export default function ParietteLayout({ children, errors, messages, loading }: Readonly<{ children: React.ReactNode, errors: any | null, messages: any | null, loading: boolean }>) {
const [siteData, setSiteData] = useState({ navigations: [] });
const [error, setError] = useState<LayoutError | any>(glob.errors.noError)
const [message, setMessage] = useState<any>({})
useEffect(() => {
const fetchData = async () => {
try {
const { data } = await $get('environment/' + glob.pariette_token);
setSiteData(data);
setError(glob.errors.noError)
} catch (error) {
setError(error)
}
};
fetchData()
if (errors) {
setError(errors)
}
if (messages) {
setMessage(message)
}
}, [errors, message, messages])
const MainContainer = () => (
<main className="scroll-smooth min-h-screen">
{children}
</main>
)
return (
<>
{loading && <PageLoader />}
{!error.status && <PageError errors={error} />}
<Header siteData={siteData} />
<MainContainer />
</>
)
}4) Error Handling
Learn how to handle errors in your API requests. You can use try-catch blocks or promise catch methods.