Exemplos de Pedidos
Os pedidos são feitos ao endereço https://api.cloudinvoice.net/
, acrescentando-lhe o end-point da acção pretendida. Nesta documentação, usaremos pedidos realizados a partir do software cURL como exemplo.
Exemplos de Pedidos à API:
Curl
curl https://api.cloudinvoice.net/customers/
-H "Content-Type: application/json"
-H "Authorization: Token 329c2d5cadd96ccce7b0b0f2653e8d08f61ddd52"
Python
import http.client
conn = http.client.HTTPSConnection("api.cloudinvoice.net")
headers = { 'Authorization': 'Token 329c2d5cadd96ccce7b0b0f2653e8d08f61ddd52', 'Content-Type': 'application/json' }
conn.request("GET", "/customers/", headers=headers)
res = conn.getresponse()
data = res.read().decode('utf-8')
json_data = json.loads(data)
print(json_data)
Node
const https = require("https");
var options = {
"hostname": "api.cloudinvoice.net",
"path": "/customers/",
"port": null,
"method": "GET",
"headers": {
"Authorization": "Token 329c2d5cadd96ccce7b0b0f2653e8d08f61ddd52",
"Content-Type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
var bodyStr = body.toString();
var bodyJson = JSON.parse(bodyStr);
});
});
req.end();
Ruby
require 'uri'
require 'net/http'
url = URI("https://api.cloudinvoice.net/customers/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["Authorization"] = "Token 329c2d5cadd96ccce7b0b0f2653e8d08f61ddd52"
request["Content-Type"] = "application/json"
response = http.request(request)
puts response.read_body
PHP
<?php
$url = 'https://api.cloudinvoice.net/customers/';
$token = "329c2d5cadd96ccce7b0b0f2653e8d08f61ddd52";
$headers = array(
'Content-Type: application/json',
'Authorization: Token '.$token,
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$result = json_decode($response, true);
echo $result;
}
Go
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.cloudinvoice.com/customers/"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Token 329c2d5cadd96ccce7b0b0f2653e8d08f61ddd52")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Last updated