API Example Requests
This page provides simple examples of making API requests in various programming languages to help you get started with the OpenTiendas API. Each example show how to:
- Send authenticated HTTP requests.
- Parse the JSON response.
- Handle basic errors.
info
These examples focus on authentication and request logic only.
For complete use cases, integrate them into your preferred framework and handle the API response appropriately.
use your shop ID
Use your unique store ID in place of {SHOP_ID}.
You can find this in the API section of your OpenTiendas Admin Panel.
Example: https://mystore123.opentiendas.app/api/v1/store
- Python
- Node.js
- .NET (C#)
- Ruby
- PHP
- Go
- Java
import requests
api_key = "YOUR_API_KEY"
headers = {"Authorization": f"Bearer {api_key}"}
response = requests.get("https://{SHOP_ID}.opentiendas.app/api/v1/store", headers=headers)
if response.status_code == 200:
data = response.json()
print("Store Info:", data)
else:
print(f"Error: {response.status_code} - {response.text}")
const fetch = require("node-fetch");
const apiKey = "YOUR_API_KEY";
const headers = { "Authorization": `Bearer ${apiKey}` };
fetch("https://{SHOP_ID}.opentiendas.app/api/v1/store", { headers })
.then(res => {
if (!res.ok) throw new Error(`${res.status} - ${res.statusText}`);
return res.json();
})
.then(data => console.log("Store Info:", data))
.catch(err => console.error("Error:", err));
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
var response = await client.GetAsync("https://{SHOP_ID}.opentiendas.app/api/v1/store");
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine("Store Info: " + data);
}
else
{
Console.WriteLine($"Error: {response.StatusCode}");
}
}
}
require 'net/http'
require 'json'
uri = URI("https://{SHOP_ID}.opentiendas.app/api/v1/store")
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer YOUR_API_KEY"
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
if res.is_a?(Net::HTTPSuccess)
data = JSON.parse(res.body)
puts "Store Info:", data
else
puts "Error: #{res.code} - #{res.message}"
end
<?php
$apiKey = "YOUR_API_KEY";
$headers = [
"Authorization: Bearer $apiKey"
];
$options = [
"http" => [
"header" => implode("\r\n", $headers),
"method" => "GET"
]
];
$context = stream_context_create($options);
$response = file_get_contents("https://{SHOP_ID}.opentiendas.app/api/v1/store", false, $context);
if ($response !== false) {
$data = json_decode($response, true);
echo "Store Info:\n";
print_r($data);
} else {
echo "Error fetching data.";
}
?>
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://{SHOP_ID}.opentiendas.app/api/v1/store", nil)
req.Header.Add("Authorization", "Bearer YOUR_API_KEY")
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("Store Info:", string(body))
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class ApiExample {
public static void main(String[] args) {
try {
String apiKey = "YOUR_API_KEY";
URL url = new URL("https://{SHOP_ID}.opentiendas.app/api/v1/store");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Bearer " + apiKey);
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("Store Info: " + response.toString());
} else {
System.out.println("Error: " + responseCode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Need more help? Check out the API Reference or contact us.
🚀 Happy coding!