Log

JavaScript

JavaScript - Fetch

var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer YOUR_API_TOKEN");
myHeaders.append("Content-Type", "application/json");
​
var raw = JSON.stringify({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
});
​
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
​
fetch("https://api.logsnag.com/v1/log", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

JavaScript - jQuery

var settings = {
"url": "https://api.logsnag.com/v1/log",
"method": "POST",
"timeout": 0,
"headers": {
"Authorization": "Bearer YOUR_API_TOKEN",
"Content-Type": "application/json"
},
"data": JSON.stringify({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
}),
};
​
$.ajax(settings).done(function (response) {
console.log(response);
});

Javascript - XHR

var data = JSON.stringify({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
});
​
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
​
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
​
xhr.open("POST", "https://api.logsnag.com/v1/log");
xhr.setRequestHeader("Authorization", "Bearer YOUR_API_TOKEN");
xhr.setRequestHeader("Content-Type", "application/json");
​
xhr.send(data);

NodeJS

NodeJS - Axios

var axios = require('axios');
var data = JSON.stringify({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
});
​
var config = {
method: 'post',
url: 'https://api.logsnag.com/v1/log',
headers: {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
},
data : data
};
​
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});

NodeJS - Native

var https = require('follow-redirects').https;
var fs = require('fs');
​
var options = {
'method': 'POST',
'hostname': 'api.logsnag.com',
'path': '/v1/log',
'headers': {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
},
'maxRedirects': 20
};
​
var req = https.request(options, function (res) {
var chunks = [];
​
res.on("data", function (chunk) {
chunks.push(chunk);
});
​
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
​
res.on("error", function (error) {
console.error(error);
});
});
​
var postData = JSON.stringify({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
});
​
req.write(postData);
​
req.end();

NodeJS - Request

var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.logsnag.com/v1/log',
'headers': {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
})
​
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});

NodeJS - Unirest

var unirest = require('unirest');
var req = unirest('POST', 'https://api.logsnag.com/v1/log')
.headers({
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
})
.send(JSON.stringify({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
}))
.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.raw_body);
});

Python

Python - http.client

import http.client
import json
​
conn = http.client.HTTPSConnection("api.logsnag.com")
payload = json.dumps({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": True
})
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
}
conn.request("POST", "/v1/log", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Python - Requests

import requests
import json
​
url = "https://api.logsnag.com/v1/log"
​
payload = json.dumps({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": True
})
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
}
​
response = requests.request("POST", url, headers=headers, data=payload)
​
print(response.text)

Ruby

Ruby - Net:HTTP

require "uri"
require "json"
require "net/http"
​
url = URI("https://api.logsnag.com/v1/log")
​
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
​
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer YOUR_API_TOKEN"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
})
​
response = https.request(request)
puts response.read_body

Golang

Golang - Native

package main
​
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
​
func main() {
​
url := "https://api.logsnag.com/v1/log"
method := "POST"
​
payload := strings.NewReader(`{
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
}`)
​
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
​
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Bearer YOUR_API_TOKEN")
req.Header.Add("Content-Type", "application/json")
​
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
​
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

PHP

PHP - cURL

<?php
​
$curl = curl_init();
​
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.logsnag.com/v1/log',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
}',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer YOUR_API_TOKEN',
'Content-Type: application/json'
),
));
​
$response = curl_exec($curl);
​
curl_close($curl);
echo $response;

PHP - HTTP_Request2

<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.logsnag.com/v1/log');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'Bearer YOUR_API_TOKEN',
'Content-Type' => 'application/json'
));
$request->setBody('{\n "project": "my-saas",\n "channel": "waitlist",\n "event": "Waitlist Member",\n "description": "email: [email protected]",\n "icon": "πŸ”₯",\n "notify": true\n}');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}

PHP - pecl_http

<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://api.logsnag.com/v1/log');
$request->setRequestMethod('POST');
$body = new http\Message\Body;
$body->append('{
"project": "my-saas",
"channel": "waitlist",
"event": "Waitlist Member",
"description": "email: [email protected]",
"icon": "πŸ”₯",
"notify": true
}');
$request->setBody($body);
$request->setOptions(array());
$request->setHeaders(array(
'Authorization' => 'Bearer YOUR_API_TOKEN',
'Content-Type' => 'application/json'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Copy link
Outline
JavaScript
JavaScript - Fetch
JavaScript - jQuery
Javascript - XHR
NodeJS
NodeJS - Axios
NodeJS - Native
NodeJS - Request
NodeJS - Unirest
Python
Python - http.client
Python - Requests
Ruby
Ruby - Net:HTTP
Golang
Golang - Native
PHP
PHP - cURL
PHP - HTTP_Request2
PHP - pecl_http