Create a Warrant
Create a new warrant that associates an object (objectType
and objectId
) to a subject
via a relation
.
POST /v1/warrants
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
objectType | The type of object. Must be one of your system's existing object types. | JSON body | yes |
objectId | The id of the specific object. | JSON body | yes |
relation | The relation for this object to subject association. The relation must be valid as per the object type definition. | JSON body | yes |
subject | The subject for which this warrant applies. Subject can be a specific object (by id) or a set of objects matching the given objectType, objectId and relation. | JSON body | yes |
context | The context under which this warrant applies. If context is provided, only access check queries that provide a matching context will match this warrant. | JSON body | no |
Request
- Curl
- Go
- Java
- Node.js
- Python
- Ruby
- PHP
curl "https://api.warrant.dev/v1/warrants" \
-X POST \
-H "Authorization: ApiKey YOUR_KEY" \
--data-raw \
'{
"objectType": "report",
"objectId": "23ft346",
"relation": "editor",
"subject": {
"objectType": "user",
"objectId": "15ads7823a9df7as433gk23dd"
}
}'
createdWarrant, err := warrant.Create(&warrant.WarrantParams{
ObjectType: "report",
ObjectId: "23ft346",
Relation: "editor",
Subject: warrant.Subject{
ObjectType: "role",
ObjectId: "15ads7823a9df7as433gk23dd",
},
})
if err != nil {
// handle error
}
try {
Report report = new Report("23ft346"); // assuming 'Report' implements the 'WarrantObject' interface
client.createWarrant(report, "editor", new WarrantSubject("user", "15ads7823a9df7as433gk23dd"));
} catch (WarrantException e) {
// Handle error
}
const newWarrant = await warrantClient.Warrant.create({
object: {
objectType: "report",
objectId: "23ft346",
},
relation: "editor",
subject: { objectType: "user", objectId: "15ads7823a9df7as433gk23dd" },
});
user_subject = warrant.Subject("user", "15ads7823a9df7as433gk23dd")
warrant.Warrant.create(object_type="report", object_id="23ft346", relation="editor", subject=user_subject)
createdWarrant = Warrant::Warrant.create(
object_type: "report",
object_id: "23ft346",
relation: "editor",
subject: {
object_type: "user",
object_id: "15ads7823a9df7as433gk23dd"
}
)
$subject = new \Warrant\Subject("user", "15ads7823a9df7as433gk23dd");
$created_warrant = $warrant->createWarrant(new \Warrant\Warrant("report", "23ft346", "editor", $subject));
Response
{
"objectType": "report",
"objectId": "23ft346",
"relation": "editor",
"subject": {
"objectType": "user",
"objectId": "15ads7823a9df7as433gk23dd"
}
}