cURL
curl --request GET \
--url https://api.camposcloud.com/v1/apps/{appId}/logs \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.camposcloud.com/v1/apps/{appId}/logs"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.camposcloud.com/v1/apps/{appId}/logs', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.camposcloud.com/v1/apps/{appId}/logs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.camposcloud.com/v1/apps/{appId}/logs"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.camposcloud.com/v1/apps/{appId}/logs")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.camposcloud.com/v1/apps/{appId}/logs")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodyretry: 5000
event: ready
data: {"applicationId":"64b7f0c2a1b2c3d4e5f60718","name":"my-bot","online":true,"tail":100}
event: clear
data:
event: log
data: Bot connected as my-bot#1234
event: log
data: Error: something failed
data: at main (index.js:10:5)
: ping
event: status
data: {"action":"die"}
event: end
data: {"reason":"timeout","message":"The stream reached its maximum duration. Reconnect to continue."}
{
"error": "'tail' must be an integer between 0 and 500."
}{
"error": "Invalid developer token"
}{
"error": "You do not have permission to perform this action on this application."
}{
"error": "Application not found or you do not have permission to access it."
}{
"error": "At most 5 log streams can be open at the same time."
}{
"error": "Internal server error. Please try again later."
}Applications
/v1/apps/{appId}/logs
This endpoint streams the console of an application in real time, read-only.
GET
/
v1
/
apps
/
{appId}
/
logs
cURL
curl --request GET \
--url https://api.camposcloud.com/v1/apps/{appId}/logs \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.camposcloud.com/v1/apps/{appId}/logs"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.camposcloud.com/v1/apps/{appId}/logs', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.camposcloud.com/v1/apps/{appId}/logs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.camposcloud.com/v1/apps/{appId}/logs"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.camposcloud.com/v1/apps/{appId}/logs")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.camposcloud.com/v1/apps/{appId}/logs")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodyretry: 5000
event: ready
data: {"applicationId":"64b7f0c2a1b2c3d4e5f60718","name":"my-bot","online":true,"tail":100}
event: clear
data:
event: log
data: Bot connected as my-bot#1234
event: log
data: Error: something failed
data: at main (index.js:10:5)
: ping
event: status
data: {"action":"die"}
event: end
data: {"reason":"timeout","message":"The stream reached its maximum duration. Reconnect to continue."}
{
"error": "'tail' must be an integer between 0 and 500."
}{
"error": "Invalid developer token"
}{
"error": "You do not have permission to perform this action on this application."
}{
"error": "Application not found or you do not have permission to access it."
}{
"error": "At most 5 log streams can be open at the same time."
}{
"error": "Internal server error. Please try again later."
}At most 5 streams can be open at the same time per account, and at most 20 new connections can be opened per minute. Close the streams you no longer need.
This endpoint is read-only: it only sends the output of the application. There is no way to send input or commands to the application through it.
How the stream behaves
- When the stream opens you receive
ready, thenclearand the lasttaillines (100 by default). - After that, every new line arrives as a
logevent as soon as the application writes it. - When the application stops or starts you receive
statuswithdieorstart. After a start you receiveclearand the first lines of the new run. - The server closes every stream after 30 minutes with
endandreason: "timeout", and also when it loses the connection to the server that runs the application (worker-lost) or when your client reads too slowly (slow-client). Reconnect when that happens; the permissions are checked again on every connection.
Always handle
clear by discarding what you have shown. That is how you avoid showing the same lines twice after a reconnection.Examples
curl -N "https://api.camposcloud.com/v1/apps/<appId>/logs?tail=50" \
-H "Authorization: Bearer <token>"
const response = await fetch("https://api.camposcloud.com/v1/apps/<appId>/logs?tail=50", {
headers: { Authorization: "Bearer <token>", Accept: "text/event-stream" },
});
if (!response.ok) throw new Error((await response.json()).error);
const decoder = new TextDecoder();
let buffer = "";
for await (const chunk of response.body) {
buffer += decoder.decode(chunk, { stream: true });
let end;
while ((end = buffer.indexOf("\n\n")) >= 0) {
const block = buffer.slice(0, end);
buffer = buffer.slice(end + 2);
let event = "message";
const data = [];
for (const line of block.split("\n")) {
if (line.startsWith("event:")) event = line.slice(6).trim();
else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
}
if (data.length === 0) continue; // comments such as ": ping"
if (event === "clear") console.clear();
else if (event === "log") console.log(data.join("\n"));
else if (event === "end") console.log("stream ended:", JSON.parse(data.join("\n")).reason);
}
}
import json
import requests
url = "https://api.camposcloud.com/v1/apps/<appId>/logs"
headers = {"Authorization": "Bearer <token>", "Accept": "text/event-stream"}
with requests.get(url, headers=headers, params={"tail": 50}, stream=True, timeout=(10, 70)) as response:
response.raise_for_status()
event, data = "message", []
for line in response.iter_lines(decode_unicode=True):
if line == "":
if data:
text = "\n".join(data)
if event == "log":
print(text)
elif event == "end":
print("stream ended:", json.loads(text)["reason"])
event, data = "message", []
elif line.startswith("event:"):
event = line[6:].strip()
elif line.startswith("data:"):
data.append(line[5:].removeprefix(" "))
The browser
EventSource API cannot send the Authorization header, so call this endpoint from your server or with fetch, never from a public web page: that would expose your API token.Authorizations
Query Parameters
Response
The stream. It stays open until the client disconnects or the server sends end.
The response is of type string.