Skip to content

Instantly share code, notes, and snippets.

@nuxsmin
Last active December 15, 2018 10:01
Show Gist options
  • Save nuxsmin/62338b33178544894cd7237c7fe170bd to your computer and use it in GitHub Desktop.
Save nuxsmin/62338b33178544894cd7237c7fe170bd to your computer and use it in GitHub Desktop.
Basic (very) CURL client to connect to sysPass API
<?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>';
{
"jsonrpc" : "2.0",
"method" : "getAccountData",
"params" : {
"authToken" : "PUT_YOUR_TOKEN_HERE",
"tokenPass" : "PUT_YOUR_TOKEN_PASS_HERE",
"id" : 11
},
"id" : 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment