-
-
Save cyhook/a3473960efe184c769ba2e8e2c202f42 to your computer and use it in GitHub Desktop.
Basic (very) CURL client to connect to sysPass API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = [ | |
'jsonrpc' => '2.0', | |
'method' => 'backup', | |
'params' => [ | |
'authToken' => 'PUT_YOUR_TOKEN_HERE', | |
// 'id' => '11', | |
// 'userPass' => 'debian', | |
// 'text' => 'Keepass', | |
// 'categoryId' => '5', | |
// 'customerId' => '1', | |
// 'pass' => '1234', | |
// 'login' => 'root', | |
// 'url' => 'http://syspass.org', | |
// 'notes' => 'pruebaaaaaaa' | |
], | |
'id' => 1 | |
]; | |
$url = 'http://localhost/api.php'; | |
$content = json_encode($data); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $content); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($content), | |
'Accept-Language: de_DE,en-US;q=0.7,en;q=0.3' | |
) | |
); | |
$result = curl_exec($ch); | |
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($status != 200) { | |
die("Error: call to URL $url failed with status $status, response $result, curl_error " . curl_error($ch) . ", curl_errno " . curl_errno($ch)); | |
} | |
curl_close($ch); | |
echo '<pre>'; | |
var_dump(json_decode($result)); | |
echo '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment