Projects
Creating a project
Via the API you can create a project. First you need to create a private key for Encord.
- Node
- curl
const crypto = require('crypto');
const sshpk = require('sshpk');
const generateAuthHeader = (data, privateKey) => {
const pkParsed = sshpk.parsePrivateKey(privateKey, 'openssh');
const hashedData = crypto.createHash('sha256').update(data).digest();
const s = pkParsed.createSign('sha512');
s.update(hashedData);
const signature = s.sign();
const publicKey = pkParsed.toPublic();
const pkData = publicKey.parts[0].data;
const pkDataString = pkData.toString('hex');
return `${pkDataString}:${signature.parts[0].data.toString('hex')}`;
};
var axios = require('axios');
var data = JSON.stringify(
{
"query_type": "project",
"query_method":"POST",
"values": {
"uid": null,
"payload": {
"title": '<Project title>',
"description": '<Project description>',
"dataset_hashes": '<List of dataset hashes to add>',
"ontology_hash": '<Ontology hash>', // Optional parameter. Specify an existing ontology to associate the project with.
}
}
});
var config = {
method: 'post',
url: 'https://api.encord.com/public/user',
headers: {
'Content-Type': 'application/json',
'Authorization': generateAuthHeader(data, '<Private key>'),
'Accept': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
curl --location --request POST 'https://api.encord.com/public/user' \
--header 'Content-Type: application/json' \
--header 'Authorization: <auth_header>' \
--header 'Accept: application/json' \
--data-raw '{
"query_type": "project",
"query_method":"POST",
"values": {
"uid": null,
"payload": {
"title": '<Project title>',
"description": '<Project description>',
"dataset_hashes": '<List of dataset hashes to add>'
}
}
}
}'
The above API call returns the unique identifier of the project known as project_hash
.
The above API call makes the caller the Admin of the project.
Creating a project API key
Via the API you can create a project API key.
The project API key would be required to interact with the project.
You also need to provide the project_hash
which uniquely identifies a project.
This capability is available to only the Admin of the project.
The APIKeyScopes
provides the following values to restrict access to specific functionality via the API
- LABEL_READ : For access to getting label rows
- LABEL_WRITE : For access to creating/saving label rows
- Node
- curl
const crypto = require('crypto');
const sshpk = require('sshpk');
const generateAuthHeader = (data, privateKey) => {
const pkParsed = sshpk.parsePrivateKey(privateKey, 'openssh');
const hashedData = crypto.createHash('sha256').update(data).digest();
const s = pkParsed.createSign('sha512');
s.update(hashedData);
const signature = s.sign();
const publicKey = pkParsed.toPublic();
const pkData = publicKey.parts[0].data;
const pkDataString = pkData.toString('hex');
return `${pkDataString}:${signature.parts[0].data.toString('hex')}`;
};
var axios = require('axios');
var data = JSON.stringify(
{
"query_type": "projectapikey",
"query_method":"POST",
"values": {
"uid": '<project_id>',
"payload": {
"title": '<API key title>',
"scopes": '<["label.read", "label.write"]>'
}
}
});
var config = {
method: 'post',
url: 'https://api.encord.com/public/user',
headers: {
'Content-Type': 'application/json',
'Authorization': generateAuthHeader(data, '<Private key>'),
'Accept': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
curl --location --request POST 'https://api.encord.com/public/user' \
--header 'Content-Type: application/json' \
--header 'Authorization: <auth_header>' \
--header 'Accept: application/json' \
--data-raw '{
"query_type": "projectapikey",
"query_method":"POST",
"values": {
"uid": '<project_id>',
"payload": {
"title": '<API key title>',
"scopes": '<["label.read", "label.write"]>'
}
}
}
}'
Fetching a project API key
Via the API you can get all API keys for an existing project.
- Node
- curl
const crypto = require('crypto');
const sshpk = require('sshpk');
const axios = require('axios');
const generateAuthHeader = (data, privateKey) => {
const pkParsed = sshpk.parsePrivateKey(privateKey, 'openssh');
const hashedData = crypto.createHash('sha256').update(data).digest();
const s = pkParsed.createSign('sha512');
s.update(hashedData);
const signature = s.sign();
const publicKey = pkParsed.toPublic();
const pkData = publicKey.parts[0].data;
const pkDataString = pkData.toString('hex');
return `${pkDataString}:${signature.parts[0].data.toString('hex')}`;
};
var data = JSON.stringify(
{
"query_type": "projectapikey",
"query_method":"GET",
"values": {
"uid": '<project_id>',
"payload": null,
}
});
var config = {
method: 'post',
url: 'https://api.encord.com/public/user',
headers: {
'Content-Type': 'application/json',
'Authorization': generateAuthHeader(data, '<Private_key>'),
'Accept': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
curl --location --request POST 'https://api.encord.com/public/user' \
--header 'Content-Type: application/json' \
--header 'Authorization: <auth_header>' \
--header 'Accept: application/json' \
--data-raw '{
"query_type": "projectapikey",
"query_method":"GET",
"values": {
"uid": '<project_id>',
"payload": null,
}
}
}'
Adding datasets to a project
Via the API you can add existing datasets to a project.
You need to be the Admin of the datasets that you want to add to the project.
The unique identifier dataset_hash
for every dataset is needed for this functionality.
Only the Admin of a project is eligible to execute this functionality.
- Node
- curl
var axios = require('axios');
var data = JSON.stringify(
{
"query_type": "projectdataset",
"query_method":"POST",
"values": {
"uid": null,
"payload": {
"dataset_hashes": '["aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1", "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee2"]'
}
}
});
var config = {
method: 'post',
url: 'https://api.encord.com/public',
headers: {
'Content-Type': 'application/json',
'ResourceID': '<project_id>',
'Authorization': '<project_api_key>',
'Accept': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
curl --location --request POST 'https://api.encord.com/public' \
--header 'Content-Type: application/json' \
--header 'ResourceID: <project_id>' \
--header 'Authorization: <project_api_key>' \
--header 'Accept: application/json' \
--data-raw '{
"query_type": "projectdataset",
"query_method":"POST",
"values": {
"uid": null,
"payload": {
"dataset_hashes": '["aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1", "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee2"]'
}
}
}
}'
Removing datasets from a project
Via the API you can remove existing datasets to a project.
The unique identifier dataset_hash
for every dataset to be removed is needed for this functionality.
Only the Admin of a project is eligible to execute this functionality.
- Node
- curl
var axios = require('axios');
var data = JSON.stringify(
{
"query_type": "projectdataset",
"query_method":"DELETE",
"values": {
"uid": '<List of dataset hashes to delete>',
}
});
var config = {
method: 'post',
url: 'https://api.encord.com/public',
headers: {
'Content-Type': 'application/json',
'ResourceID': '<project_id>',
'Authorization': '<project_api_key>',
'Accept': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
curl --location --request POST 'https://api.encord.com/public' \
--header 'Content-Type: application/json' \
--header 'ResourceID: <project_id>' \
--header 'Authorization: <project_api_key>' \
--header 'Accept: application/json' \
--data-raw '{
"query_type": "projectdataset",
"query_method":"DELETE",
"values": {
"uid": '<List of dataset hashes to delete>',
}
}
}'
Adding users to a project
Using this functionality you can add users to an existing project.
The email_id
of the users need to be provided as an input.
Project user roles are Admin = 0, Annotator = 1, Reviewer = 2, Annotator and reviewer = 3, Team manager = 4
- Node
- curl
var axios = require('axios');
var data = JSON.stringify(
{
"query_type": "projectusers",
"query_method":"POST",
"values": {
"uid": '<project_id>',
"payload": {
"user_emails": '<List of user emails>',
"user_role": '<User role of the new users>'
}
}
});
var config = {
method: 'post',
url: 'https://api.encord.com/public',
headers: {
'Content-Type': 'application/json',
'ResourceID': '<project_id>',
'Authorization': '<project_api_key>',
'Accept': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
curl --location --request POST 'https://api.encord.com/public' \
--header 'Content-Type: application/json' \
--header 'ResourceID: <project_id>' \
--header 'Authorization: <project_api_key>' \
--header 'Accept: application/json' \
--data-raw '{
"query_type": "projectusers",
"query_method":"POST",
"values": {
"uid": null,
"payload": {
"user_emails": '<List of user emails>',
"user_role": '<User role of the new users>'
}
}
}
}'
Fetching project information
Fetch information associated with a given project.
- Node
- curl
var axios = require('axios');
var data = JSON.stringify(
{
"query_type": "project",
"query_method":"GET",
"values": {
"uid": null,
"payload": null
}
});
var config = {
method: 'post',
url: 'https://api.encord.com/public',
headers: {
'Content-Type': 'application/json',
'ResourceID': '<project_id>',
'Authorization': '<project_api_key>',
'Accept': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
curl --location --request POST 'https://api.encord.com/public' \
--header 'Content-Type: application/json' \
--header 'ResourceID: <project_id>' \
--header 'Authorization: <project_api_key>' \
--header 'Accept: application/json' \
--data-raw '{
"query_type": "project",
"query_method": "GET",
"values": {
"uid": null,
"payload": null
}
}'
Fetching project ontology
You can fetch the ontology of an existing project using the above API call. The editor ontology can be found in the API
response under the key editor_ontology
.