Python
import os
from gcore import Gcore
client = Gcore(
api_key=os.environ.get("GCORE_API_KEY"), # This is the default and can be omitted
)
role_assignment = client.cloud.users.role_assignments.create(
role="ClientAdministrator",
user_id=777,
)
print(role_assignment.id)package main
import (
"context"
"fmt"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/cloud"
"github.com/G-Core/gcore-go/option"
)
func main() {
client := gcore.NewClient(
option.WithAPIKey("My API Key"),
)
roleAssignment, err := client.Cloud.Users.RoleAssignments.New(context.TODO(), cloud.UserRoleAssignmentNewParams{
Role: cloud.UserRoleAssignmentNewParamsRoleClientAdministrator,
UserID: 777,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", roleAssignment.ID)
}
curl --request POST \
--url https://api.gcore.com/cloud/v1/users/assignments \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"role": "ClientAdministrator",
"user_id": 777,
"client_id": 8,
"project_id": null
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({role: 'ClientAdministrator', user_id: 777, client_id: 8, project_id: null})
};
fetch('https://api.gcore.com/cloud/v1/users/assignments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gcore.com/cloud/v1/users/assignments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'role' => 'ClientAdministrator',
'user_id' => 777,
'client_id' => 8,
'project_id' => null
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.gcore.com/cloud/v1/users/assignments")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"role\": \"ClientAdministrator\",\n \"user_id\": 777,\n \"client_id\": 8,\n \"project_id\": null\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gcore.com/cloud/v1/users/assignments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"role\": \"ClientAdministrator\",\n \"user_id\": 777,\n \"client_id\": 8,\n \"project_id\": null\n}"
response = http.request(request)
puts response.read_body{
"assigned_by": 123,
"client_id": 123,
"created_at": "2019-06-25T08:42:42Z",
"id": 12,
"project_id": 123,
"role": "ClientAdministrator",
"updated_at": "2019-06-25T08:42:42Z",
"user_id": 123
}User Role Assignments
Create role assignment
Assign a role to an existing user in the specified scope.
POST
/
cloud
/
v1
/
users
/
assignments
Python
import os
from gcore import Gcore
client = Gcore(
api_key=os.environ.get("GCORE_API_KEY"), # This is the default and can be omitted
)
role_assignment = client.cloud.users.role_assignments.create(
role="ClientAdministrator",
user_id=777,
)
print(role_assignment.id)package main
import (
"context"
"fmt"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/cloud"
"github.com/G-Core/gcore-go/option"
)
func main() {
client := gcore.NewClient(
option.WithAPIKey("My API Key"),
)
roleAssignment, err := client.Cloud.Users.RoleAssignments.New(context.TODO(), cloud.UserRoleAssignmentNewParams{
Role: cloud.UserRoleAssignmentNewParamsRoleClientAdministrator,
UserID: 777,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", roleAssignment.ID)
}
curl --request POST \
--url https://api.gcore.com/cloud/v1/users/assignments \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"role": "ClientAdministrator",
"user_id": 777,
"client_id": 8,
"project_id": null
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({role: 'ClientAdministrator', user_id: 777, client_id: 8, project_id: null})
};
fetch('https://api.gcore.com/cloud/v1/users/assignments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gcore.com/cloud/v1/users/assignments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'role' => 'ClientAdministrator',
'user_id' => 777,
'client_id' => 8,
'project_id' => null
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.gcore.com/cloud/v1/users/assignments")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"role\": \"ClientAdministrator\",\n \"user_id\": 777,\n \"client_id\": 8,\n \"project_id\": null\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gcore.com/cloud/v1/users/assignments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"role\": \"ClientAdministrator\",\n \"user_id\": 777,\n \"client_id\": 8,\n \"project_id\": null\n}"
response = http.request(request)
puts response.read_body{
"assigned_by": 123,
"client_id": 123,
"created_at": "2019-06-25T08:42:42Z",
"id": 12,
"project_id": 123,
"role": "ClientAdministrator",
"updated_at": "2019-06-25T08:42:42Z",
"user_id": 123
}Authorizations
API key for authentication. Make sure to include the word apikey, followed by a single space and then your token.
Example: apikey 1234_abcdef
Body
application/json
User role
Available options:
ClientAdministrator, InternalNetworkOnlyUser, Observer, ProjectAdministrator, User Example:
"ClientAdministrator"
User ID
Example:
777
Client ID. Required if project_id is specified
Example:
8
Project ID
Example:
null
Response
200 - application/json
OK
Client ID
Example:
123
Created timestamp
Example:
"2019-06-25T08:42:42Z"
Assignment ID
Example:
12
Project ID
Example:
123
User role
Available options:
ClientAdministrator, InternalNetworkOnlyUser, Observer, ProjectAdministrator, User Example:
"ClientAdministrator"
Updated timestamp
Example:
"2019-06-25T08:42:42Z"
User ID
Example:
123
Was this page helpful?