This feature is only available if you have subscribed to the API option. Do not hesitate to contact your sales representative if you wish to activate this option.
________________________________________________________________________________________
Here are some examples of how to use the LockSelf API in Python 3.
For these examples we will use the following variables :
- [URLAPI] : Corresponds to the url of the API you want to use (more information on the article What is the LockSelf API ?)
- [XLSTOKEN] : Displayed when creating an API user under the name "X-Ls-Token"
- [AUTHTOKEN] : Displayed when creating an API user under the name "X-Auth-Token Key".
Example 1 - LockPass (GET)
Retrieve the list of logins in a category :
import requests
url = "https://[URLAPI]/api-key/credentials?categoryId=1234&limit=10"
payload={}
headers = {
'X-Ls-Token': '[XLSTOKEN]',
'X-Auth-Token': '[AUTHTOKEN]'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
In this example we ask for the first 10 logins of the category whose ID is 1234.
The other parameters of this method can be consulted on the technical documentation of the API.
You will receive a response from the API in the following form :
{
"page": "1",
"limit": "10",
"pages": "2",
"total": "13",
"items": [
{
"id": 1337,
"name": "Test",
"domain": "google.fr",
"userId": 0,
"categoryId": "42",
"creationDate": "2020-05-27 14:51:28",
"modificationDate": "2020-05-28 14:51:28",
"isOwner": true,
"view": 1
}
]
}
You can then retrieve the ID of the login you are interested in for its decryption at the API.
Example 2 - LockPass (POST)
Creation of a login :
import requests
url = "https://[URLAPI]/api-key/credentials"
payload={'categoryId': 1337,
'description': 'Ma description',
'domain': 'lockself.com',
'isAlert': false,
'name': 'Mon identifiant',
'opt1': '',
'opt2': '',
'opt3': '',
'password': 'M0nP4s$',
'tags': '',
'username': 'login@ndd.com'}
headers = {
'X-Ls-Token': '[XLSTOKEN]',
'X-Auth-Token': '[AUTHTOKEN]'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
In this example we ask the API to create a login by specifying all the necessary information for its creation.
The description of the parameters of this method can be found in the technical documentation of the API.
You will get a response in the following form :
{
"id": 1234,
"name": "Mon identifiant",
"domain": "lockself.com",
"userId": 4321,
"categoryId": "12",
"isOwner": true
}
Example 3 - LockTransfer (POST)
Drop a file in a deposit box :
import requests
url = "https://[URLAPI]/api-key/depositboxes/file"
payload={'depositBoxId': '1234',
'uuid': '12334-5678-54321-32671',
'chunkIndex': '0',
'totalChunkCount': '1',
'totalSize': '22222',
'description': 'Description de mon fichier'}
files=[
('file',('monImage.jpg', open('/home/perso/monImage.jpg','rb'),'image/jpeg'))
]
headers = {
'X-Ls-Token': '[XLSTOKEN]',
'X-Auth-Token': '[AUTHTOKEN]'
}response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
In this example we drop a file named "monImage.jpg" in the deposit box with the id 1234.
We indicate :
- the uuid that we generated beforehand
- the chunkIndex which corresponds to the number of the file chunk (max 20MB per chunk)
- the totalChunkCount which corresponds to the total number of chunks that will be sent
- totalSize which is the total size of the file.
You will get a response in the following form :
{
"id": "42",
"userId": "26",
"status": 0,
"isPrivate": "true",
"token": "26vl42",
"hash1": "faf11c4cf0bc40233e70da3808a97f1c",
"hash2": "768753d715912d9fd563c0858f5c0615",
"hashReport": "43c385881ccba6663afc58b766e2c5c3",
"name": "June report.",
"description": "You will find attached the financial reports as requested.",
"ackNotification": "true",
"uploadNotification": "true",
"creationDate": "2020-11-02 12:34:39",
"expirationDate": "20221102",
"reportLink": "https://www.example.com/report/deposit-box-report?displayReport=1&hash=e2af8bf73873765c0b90370734c3ceb6&hashReport=5g6ea87a92f21a60dd8848fe1ff02568",
"creatorEmail": "john.doe@example.com",
"files": [
{
"id": "9",
"hash": "f0ba55c1-16bc-42e3-84c8-9c8e4db872f5",
"name": "report-december.pdf",
"size": "42 Mo",
"realSize": 44444,
"uploader": "john.doe@company.com",
"description": "You will find attached the financial reports as requested.",
"creationDate": "2020-11-02 10:30:02",
"_links": {
"add": {
"href": "string"
},
"delete": {
"href": "string"
},
"download": {
"href": "string"
}
}
}
],
"users": [
{
"id": "9",
"relationId": "98",
"email": "john.doe@example.com",
"canModify": "true",
"isInternal": "false",
"_links": {
"add": {
"href": "string"
},
"modify": {
"href": "string"
},
"delete": {
"href": "string"
}
}
}
],
"externalUsers": [
{
"ownerFirstName": "string",
"ownerLastName": "string",
"email": "string"
}
],
"_links": {
"self": {
"href": "string"
},
"add": {
"href": "string"
},
"modify": {
"href": "string"
},
"delete": {
"href": "string"
}
}
}
For more details, you can consult the technical documentation of the API. It will allow you to know the different parameters to send for each method as well as the different possible returns.
Updated