Skip to main content

First Api Request

Welcome to the Getting Started section! This guide will help you through the initial steps to start using the Miragek Quote API effectively.

Authentication Methods​

The Miragek Quote API uses API key-based authentication. To authenticate your requests, include your API key in the request headers. Here's how to do it:

Example using PHP:​

<?php
$apiKey = "test"; // Replace with your actual API key
$url = "https://quotes.miragek.com/api?rand=1&api_key={$apiKey}"; // Add the API key to the URL

// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Add a timeout to prevent hanging requests

// Execute cURL request
$response = curl_exec($ch);

// Check if the request was successful
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpCode == 200) {
// Successfully received a response, decode and display it
$decodedResponse = json_decode($response, true);

if (json_last_error() === JSON_ERROR_NONE) {
// Print the decoded JSON
echo "<pre>";
print_r($decodedResponse);
echo "</pre>";
} else {
echo "Failed to decode JSON response.";
}
} else {
// Handle unsuccessful responses
echo "Request failed with HTTP code: " . $httpCode;
}
}

// Close cURL session
curl_close($ch);
?>

Replace YOUR_API_KEY with your actual API key.

Example Request and Response​

Here’s a quick example to illustrate how to make a request and what the response will look like.

Example Request​

To fetch a random quote, you can make a GET request to the following endpoint or enter the link directly in your broswer for testing:

GET https://quotes.miragek.com/api?rand=1&api_key=YOUR_API_KEY

Example Response​

Here’s what a successful response might look like:

{
"success": true,
"data": [
{
"id": 1,
"author": "Albert Einstein",
"quote": "Life is like riding a bicycle. To keep your balance you must keep moving.",
"category": "life"
}
],
"count": 1
}

Basic Setup in Various Programming Languages​

To help you get started quickly, here are examples of how to make a basic API request in different programming languages:

Python​

import requests

# Replace with your actual API key
api_key = "YOUR_API_KEY"
url = f"https://quotes.miragek.com/api?rand=1&api_key={api_key}"

# Make the GET request
response = requests.get(url)

# Check if the request was successful
if response.status_code == 200:
# Print the JSON response
print(response.json())
else:
print(f"Error: {response.status_code} - {response.text}")

JavaScript (using Fetch API)​

// Replace with your actual API key
const apiKey = "YOUR_API_KEY";
const url = `https://quotes.miragek.com/api?rand=1&api_key=${apiKey}`;

fetch(url)
.then(response => {
console.log('Response Status:', response.status); // Log the response status
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

PHP (using cURL)​

$apiKey = "YOUR_API_KEY"; // Replace with your actual API key
$url = "https://quotes.miragek.com/api?rand=1&api_key={$apiKey}";

// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Execute cURL request
$response = curl_exec($ch);

// Check for cURL errors
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
// Print the JSON response
echo $response;
}

// Close cURL session
curl_close($ch);

Conclusion​

Now that you have your API key and know how to authenticate requests, you're ready to start making calls to the Miragek Quote API. Check out the next sections for more advanced features and capabilities!