🔐 Step 2: Authenticate Your Requests

The Scenario API uses Basic Authentication. This means you need to encode your API Key and API Secret (joined by a colon) in Base64 and include it in the Authorization header of every request. Let's look at how to do this in different programming environments.

Example: Basic Authentication

Assume your API Key is YOUR_API_KEY and your API Secret is YOUR_API_SECRET.

1. Combine Key and Secret:
YOUR_API_KEY:YOUR_API_SECRET

2. Base64 Encode the Combined String:
For example, if YOUR_API_KEY is hello and YOUR_API_SECRET is world, the combined string is hello:world. The Base64 encoding of hello:world is aGVsbG86d29ybGQ=.

3. Construct the Authorization Header:
Authorization: Basic aGVsbG86d29ybGQ=

Code Examples for Authentication

cURL

curl -u "YOUR_API_KEY:YOUR_API_SECRET" \
  https://api.scenario.com/v1/user

Python

import requests

api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"

response = requests.get(
    "https://api.scenario.com/v1/user",
    auth=(api_key, api_secret)
)

print(response.json())

Node.js

const fetch = require("node-fetch");

const apiKey = "YOUR_API_KEY";
const apiSecret = "YOUR_API_SECRET";

const credentials = Buffer.from(`${apiKey}:${apiSecret}`).toString("base64");

async function getUserData() {
  const response = await fetch("https://api.scenario.com/v1/user", {
    headers: {
      Authorization: `Basic ${credentials}`,
    },
  });
  const data = await response.json();
  console.log(data);
}

getUserData();