Skip to content

Instantly share code, notes, and snippets.

@fabik
Created October 9, 2013 18:45
Show Gist options
  • Save fabik/2d5cd9711efb8c2a07df to your computer and use it in GitHub Desktop.
Save fabik/2d5cd9711efb8c2a07df to your computer and use it in GitHub Desktop.
Návod na použití FAPI API v PHP. Není potřeba instalovat žádné knihovny. Jediné, co je potřeba, je mít v php.ini nastaveno allow_url_fopen = on.
<?php
// přihlašovací údaje
$username = 'jmeno';
$password = '*****';
// příklad GET požadavku
$json = file_get_contents('http://api.fapi.cz/invoices?limit=10', false, stream_context_create(array(
'http' => array(
'method' => 'GET',
'header' => array(
'Authorization: Basic ' . base64_encode("$username:$password"),
'Accept: application/json'
)
)
)));
$response = json_decode($json, true);
// příklad POST požadavku
$data = array(
'email' => 'example@example.com'
);
$json = file_get_contents('http://api.fapi.cz/clients', false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => array(
'Authorization: Basic ' . base64_encode("$username:$password"),
'Accept: application/json',
'Content-Type: application/json'
),
'content' => json_encode($data)
)
)));
$response = json_decode($json, true);
// příklad PUT požadavku
$data = array(
'email' => 'example@example.com'
);
$json = file_get_contents('http://api.fapi.cz/clients/1234', false, stream_context_create(array(
'http' => array(
'method' => 'PUT',
'header' => array(
'Authorization: Basic ' . base64_encode("$username:$password"),
'Accept: application/json',
'Content-Type: application/json'
),
'content' => json_encode($data)
)
)));
$response = json_decode($json, true);
// příklad DELETE požadavku
$json = file_get_contents('http://api.fapi.cz/clients/1234', false, stream_context_create(array(
'http' => array(
'method' => 'DELETE',
'header' => array(
'Authorization: Basic ' . base64_encode("$username:$password"),
'Accept: application/json'
)
)
)));
$response = json_decode($json, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment