Obeo Designer Team Administration Server REST API: User Guide (legacy)
See OpenAPI documentation available in /doc when the administration server is deployed. |
This guide describes the REST API of the administration server for Obeo Designer Team Server. This API will allow you to manage CDO repositories, shared modeling projects, and depending on the type of repository you manage, you will be able to manager the repository users. If you already have configured the administration server for Obeo Designer Team Server, you can start to use our API.
Remark: The protocol, host and port can be different from your server configuration.
In this documentation, we will use the web service API in the version v1.0.
Disclaimer: As basic authentication is enabled for the administration server, the Authorization header must be added in all requests with the base64 encoded credentials.
1. Repositories
This section describes the API to create, delete, start, stop your repositories, to export a backup of the repository database and to import a backup into the database.
As the repository creation is the main feature of this API, we provide many examples of how to create a repository.
1.1. Rest endpoints
-
/api/{version}/repositories
-
/api/{version}/repositories/{repositoryId}
-
/api/{version}/repositories/start/{repositoryId}
-
/api/{version}/repositories/stop/{repositoryId}
-
/api/{version}/repositories/export/{repositoryId}
-
/api/{version}/repositories/import/{repositoryId}
1.1.1. POST /api/{version}/repositories
This request will allow you to create a repository.
The body of the request takes a JSON object with the following parameters: repositoryName, authenticationType and datasourceType which are mandatory and also authenticationData and datasourceData which are optional.
While the authenticationType value can be empty, the repositoryName and the datasourceType values cannot.
By default, you can use the following values to manage your repositories:
-
authenticationType can take:
-
an empty value
-
LDAP
-
USERPROFILE
-
LDAP_USERPROFILE
-
FILE
-
LDAP_FILE
-
-
datasourceType can take:
-
H2_EMBEDDED
-
H2_SERVER
-
You can also contribute your own extensions and use the key value of your extension as described in the administration server of Obeo Designer team Server documentation.
Those values describe how your repository will manage authentication and database.
As the optional parameters (authenticationData and datasourceData) depend on the mandatory parameters, we will use examples to describe how to use them.
Create a repository without authentication on H2 embedded database
This example will create a repository without authentication with an H2 embedded database. The body of the request:
{
"repositoryName": "repository-without-authentication",
"authenticationType": "",
"datasourceType": "H2_EMBEDDED"
}
With an empty value set to authenticationType, your repository will not have authentication. With H2_EMBEDDED value set to datasourceType, your repository database will be an h2 embedded database.
The repository is started after it is created and life cycle hooks are called before and after its start.
The body of the response will be:
{
"message": "The repository repository-without-authentication has been created.",
"status": 201,
"repository": {
"name": "repository-without-authentication"
}
}
Create a repository without authentication on H2 server database
This example will create a repository without authentication on H2 server database.
The body of the request:
{
"repositoryName": "repository-without-authentication",
"authenticationType": "",
"datasourceType": "H2_SERVER",
"datasourceData": {
"h2ServerPort": "9092"
}
}
With an empty value set to authenticationType, your repository will not have authentication. With H2_SERVER value set to datasourceType, your repository database will be an h2 server database and you will need to provide additional data like the h2ServerPort within the datasourceData map. The h2ServerPort is used in the connection between the repository and the h2 database. The h2ServerPort value must be a string.
The repository is started after it is created and life cycle hooks are called before and after its start.
Disclaimer
If your repository is configured with an h2 server database, we use the IP address of the current machine to set up the h2 server before it starts.
The attribute "port" of datasourceData has been deprecated in favor of "h2ServerPort". This changes has been made to avoid confusion with the port used to connect to the repository.
The body of the response will be:
{
"message": "The repository repository-without-authentication has been created.",
"status": 201,
"repository": {
"name": "repository-without-authentication"
}
}
Create a repository with LDAP on H2 embedded database
This example will create a repository with LDAP authentication on H2 embedded database. The body of the request:
{
"repositoryName": "repository-with-ldap",
"authenticationType": "LDAP",
"authenticationData": {
"url": "ldap://localhost:10389",
"dnPattern": "cn={user},ou=people,o=sevenSeas"
},
"datasourceType": "H2_EMBEDDED"
}
With LDAP value set to authenticationType, your repository will use LDAP to authenticate users who have the right to modify the repository. You will need to provide within the authenticationData map the same data described in the Administrator manual of Obeo Designer Team Server documentation, namely:
-
the url (url)
-
the distinguished names (dnPattern)
-
if tls is enabled [Optional] (isTlsEnabled)
-
the trust store path [Optional] (trustStorePath): needed only if tls is enabled
-
the trust store passphrase [Optional] (trustStorePassphrase): needed only if tls is enabled
The repository is started after it is created and life cycle hooks are called before and after its start.
The body of the response will be:
{
"message": "The repository repository-with-ldap has been created.",
"status": 201,
"repository": {
"name": "repository-with-ldap"
}
}
An H2 server database can be used instead of an h2 embedded database. Go to this section to see how to create a repository with an H2 server database. |
Create a repository with User manager authentication on H2 embedded database
This example will create a repository with User manager authentication on H2 embedded database. The body of the request:
{
"repositoryName": "repository-with-file",
"authenticationType": "FILE",
"authenticationData": {
"users": [
{
"login": "Horatio Nelson",
"password": "pass"
}
]
},
"datasourceType": "H2_EMBEDDED"
}
With FILE value set to the authenticationType, your repository will use the user manager to authorize registered user to modify the repository. You will need to provide within the authenticationData map a list of users used to populate the users.properties file as the Administrator manual of Obeo Designer Team Server documentation describe it. The list of users is an array of map containing at least the login and password keys.
The repository is started after it is created and life cycle hooks are called before and after its start.
The body of the response will be:
{
"message": "The repository repository-with-file has been created.",
"status": 201,
"repository": {
"name": "repository-with-file"
}
}
An H2 server database can be used instead of an h2 embedded database. Go to this section to see how to create a repository with an H2 server database. |
Create a repository with User manager and LDAP authentication on H2 embedded database
This example will create a repository with user manager and LDAP authentication on H2 embedded database. The body of the request:
{
"repositoryName": "repository-with-file-ldap",
"authenticationType": "LDAP_FILE",
"authenticationData": {
"url": "ldap://localhost:10389",
"dnPattern": "cn={user},ou=people,o=sevenSeas",
"users": [
{
"login": "Horatio Nelson"
}
]
},
"datasourceType": "H2_EMBEDDED"
}
With LDAP_FILE value set to authenticationType, your repository will use the user manager to register to authorize registered user to modify the repository and use LDAP to authenticate them. You will need to provide within the authenticationData map a list of users used to populate the users.properties file and also additional data to handle LDAP as the Administrator manual of Obeo Designer Team Server documentation describes it.
The list of users is an array of map containing at least the login keys. The additional data needed to handle LDAP are :
-
the url (url)
-
the distinguished names (dnPattern)
-
if tls is enabled [Optional] (isTlsEnabled)
-
the trust store path [Optional] (trustStorePath): needed only if tls is enabled
-
the trust store passphrase [Optional] (trustStorePassphrase): needed only if tls is enabled
The repository is started after it is created and life cycle hooks are called before and after its start.
The body of the response will be:
{
"message": "The repository repository-with-file-ldap has been created.",
"status": 201,
"repository": {
"name": "repository-with-file-ldap"
}
}
An H2 server database can be used instead of an h2 embedded database. Go to this section to see how to create a repository with an H2 server database. |
Create a repository with User profile authentication on H2 embedded database
This example will create a repository with user profile authentication on H2 embedded database. The body of the request:
{
"repositoryName": "repository-with-userprofile",
"authenticationType": "USERPROFILE",
"authenticationData": {
"administrators": [
{
"login": "Horatio Nelson",
"password": "pass"
}
]
},
"datasourceType": "H2_EMBEDDED"
}
With USERPROFILE value set to the authenticationType, your repository will use the user profile to manage authorization on your repository. You will need to provide within the authenticationData map a list of administrators used to populate the user profile model with users who have the write right on the repository as the Administrator manual of Obeo Designer Team Server documentation describes it. The list of administrators is an array of map containing at least the login and password keys.
The repository is started after it is created and life cycle hooks are called before and after its start.
The body of the response will be:
{
"message": "The repository repository-with-userprofile has been created.",
"status": 201,
"repository": {
"name": "repository-with-userprofile"
}
}
An H2 server database can be used instead of an h2 embedded database. Go to this section to see how to create a repository with an H2 server database. |
Create a repository with User profile and LDAP authentication on H2 embedded database
This example will create a repository with user profile and LDAP authentication on H2 embedded database. The body of the request:
{
"repositoryName": "repository-with-userprofile-ldap",
"authenticationType": "LDAP_USERPROFILE",
"authenticationData": {
"url": "ldap://localhost:10389",
"dnPattern": "cn={user},ou=people,o=sevenSeas",
"administrators": [
{
"login": "Horatio Nelson"
}
]
},
"datasourceType": "H2_EMBEDDED"
}
With LDAP_USERPROFILE value set to the authenticationType, your repository will use the user profile to manage authorization on your repository. You will need to provide within the authenticationData map a list of administrators used to populate the user profile model with users who have the write right on the repository and also additional data to handle LDAP as the Administrator manual of Obeo Designer Team Server documentation describes it.
The list of administrators is an array of map containing at least the login key. The additional data needed to handle LDAP are :
-
the url (url)
-
the distinguished names (dnPattern)
-
if tls is enabled [Optional] (isTlsEnabled)
-
the trust store path [Optional] (trustStorePath): needed only if tls is enabled
-
the trust store passphrase [Optional] (trustStorePassphrase): needed only if tls is enabled
The repository is started after it is created and life cycle hooks are called before and after its start.
The body of the response will be:
{
"message": "The repository repository-with-userprofile-ldap has been created.",
"status": 201,
"repository": {
"name": "repository-with-userprofile-ldap"
}
}
An H2 server database can be used instead of an h2 embedded database. Go to this section to see how to create a repository with an H2 server database. |
Error management
The above responses are returned if everything goes well. It may be possible parameters given to the web service are not valid or an error can simply happen. In those cases, an error message that explains the cause of the error is returned:
-
400 Bad request if parameters given to the web service are not valid. As some required parameters depend on the repository type (authentication and database), the validation of those parameters will be done by extensions. For example:
{
"message": "The repository repository-with-userprofile-ldap has not been created.",
"status": 400,
"error": "The url to the ldap server is empty."
}
-
500 Internal server response if something unexpected occurred while the repository is creating. For example:
{
"message": "The repository repository-with-userprofile-ldap has not been created.",
"status": 500,
"error": "An error occurred during the repository configuration: The h2 server was not able to start.\nException: ...."
}
1.1.2. GET /api/{version}/repositories
This request will allow you to retrieve all repositories that were created using the web service to create a repository.
Retrieve all repositories
The body of the response can be:
-
200 OK if everything went well
{
"message": "All available repositories",
"status": 200,
"repositories": [
{
"name": "repository-without-authentication",
"status": "ONLINE"
},
{
"name": "repository-with-file-ldap",
"status": "OFFLINE"
}
]
}
-
500 Internal server error if something unexpected happened
{
"message": "An error occurred.",
"status": 500,
"error": "...."
}
1.1.3. DELETE /api/{version}/repositories/{repositoryId}
This request will allow you to delete a repository that was created using the web service to create a repository. The delete removes the folder and all of its content in the directory that contains the repositories. This directory can be configured in the properties files of the administration server as described in the configuration of the administration server.
Delete the "repository-without-authentication" repository
The body of the response can be:
-
200 OK if everything went well.
{
"message": "The repository repository-without-authentication has been completely deleted.",
"status": 200,
"repository": {
"name": "repository repository-without-authentication"
},
"isDatabaseDeleted": true
}
-
400 Bad request if the repository name is not valid
{
"message": "The repository has not been deleted.",
"status": 400,
"error": "The repository name is empty."
}
-
404 Not found if the repository does not exist
{
"message": "The repository repository-without-authentication has not been deleted.",
"status": 404,
"error": "The repository repository-without-authentication has not been found."
}
-
500 Internal server error if something unexpected occurred
{
"message": "The repository repository-without-authentication has not been deleted.",
"status": 500,
"error": "Something happens during the repository deletion: ..."
}
1.1.4. GET /api/{version}/repositories/start/{repositoryId}
This request will allow you to start a repository that was created using the web service to create a repository. The life cycle hooks will be called before and after its start.
Start the "repository-with-userprofile" repository
The body of the response can be:
-
200 OK if everything went well
{
"message": "The repository repository-with-userprofile is running.",
"status": 200,
"repository": {
"name": "repository-with-userprofile"
}
}
-
400 Bad request if the repository name is not valid or the repository is not stopped
{
"message": "The repository repository-with-userprofile has not been started.",
"status": 400,
"error": "The repository repository-with-userprofile is not stopped."
}
-
404 Not found if the repository does not exist
{
"message": "The repository repository-with-userprofile has not been started.",
"status": 404,
"error": "The repository repository repository-with-userprofile has not been found."
}
-
500 Internal server error if something unexpected occurred
{
"message": "The repository repository-with-userprofile has not been started.",
"status": 500,
"error": "An error occurred while starting the repository: ..."
}
1.1.5. GET /api/{version}/repositories/stop/{repositoryId}
This request will allow you to stop a repository that was created using the web service to create a repository. The life cycle hooks will be called before and after its stop.
Stop the "repository-with-userprofile" repository
The body of the response can be:
-
200 OK if everything went well
{
"message": "The repository repository-with-userprofile has been stopped.",
"status": 200,
"repository": {
"name": "repository-with-userprofile"
}
}
-
400 Bad request if the repository name is not valid or the repository is not started
{
"message": "The repository repository-with-userprofile has not been stopped.",
"status": 400,
"error": "The repository repository-with-userprofile is not started."
}
-
404 Not found if the repository does not exist
{
"message": "The repository repository-with-userprofile has not been stopped.",
"status": 404,
"error": "The repository repository repository-with-userprofile has not been found."
}
-
500 Internal server error if something unexpected occurred
{
"message": "The repository repository-with-userprofile has not been stopped.",
"status": 500,
"error": "An error occurred while stopping the repository: ..."
}
1.1.6. POST /api/{version}/repositories/export/{repositoryId}
This request will allow you to export the database of the repository into an xml file. The body of the request take two parameters: needsEncryption which is mandatory and password which is optional but needed if needsEncryption is set to true.
As the export of the database can take time, the web service will schedule an asynchronous job and return the link where you will be able to download the file in the response under the url attribute.
If needsEncryption is set to false the export of the database will create an xml file representing the cdo database in the export folder which can be configured in the properties files of the administration server as described in the configuration of the administration server.
If needsEncryption is set to true, an encrypted zip file containing the xml file will be created instead.
Export the "repository-with-userprofile" repository data
This example will export the database of the repository "repository-with-userprofile" into an encrypted zip file. The body of the request:
{
"needsEncryption": true,
"password": "password"
}
The body of the response can be:
-
202 Accepted if the export job has been scheduled
{
"message": "The export for the repository repository-with-userprofile as been launched. You will be able to retrieved the exported data at the url: http://localhost:8080/export/path/to/the/zipfile.zip",
"status": 200,
"url": "http://localhost:8080/export/path/to/the/zipfile.zip",
"repository": "repository-with-userprofile"
}
-
400 Bad request if the repository name is not valid, not started, or if an encrypted export is requested but without providing a password:
{
"message": "The repository repository-with-userprofile will not be exported.",
"status": 400,
"error": "The export encryption has been requested but no password has been provided."
}
-
404 Not found if the repository does not exist
{
"message": "The repository repository-with-userprofile will not be exported.",
"status": 404,
"error": "The repository repository-with-userprofile has not been found."
}
-
500 Internal server error if something unexpected occurred
{
"message": "An error occurred.",
"status": 500,
"error": "..."
}
1.1.7. POST /api/{version}/repositories/import/{repositoryId}
This request will allow you to upload an xml file, which must be a backup of the database. As this API needs a file, we suggest that you use the input file of your favorite browser in order to let it set the correct headers for the upload of the file.
As the import of the database can take time, the web service will schedule an asynchronous job.
The state of the repository will be the same after the import as before the import.
Import data in the "repository-with-userprofile" repository
This example will upload an xml file and will import it in the database of the repository "repository-with-userprofile".
The body of the response can be:
-
200 Accepted if the import job has been scheduled
{
"message": "The data are being imported to the repository repository-with-userprofile. The state of the repository will be the same after and before the import.",
"status": 200,
"repository": "repository-with-userprofile"
}
-
400 Bad request if the no data to import are not provided, the repository name is invalid, in some kind of repositories if remote connection is active
{
"message": "The import of the repository repository-with-userprofile will not be launched.",
"status": 400,
"error": "The import will not be executed because some connections remains (alice, bob)"
}
-
404 Not found if the repository does not exist
{
"message": "The import of the repository repository-with-userprofile will not be launched.",
"status": 404,
"error": "The repository repository-with-userprofile has not been found."
}
-
500 Internal server error if something unexpected occurred
{
"message": "An error occurred.",
"status": 500,
"error": "..."
}
2. Projects
This section describes the API to create your shared modeling projects.
2.1. Rest endpoint
-
/api/{version}/projects
2.1.1. POST /api/{version}/projects
This request will allow you to create an empty shared modeling project. The repository where you want to create the shared modeling project should be started.
The post created project life cycle hook will be called after the project is created. For example, the user profile extension life cycle hook will create roles for users. The name of the created role will have the project name and will authorize a user to create, read, update and delete resources inside the project.
Create the "Awesome-project" shared modeling project in the "repository-with-userprofile" repository
This example will create the shared modeling project named "Awesome-project" in the repository named "repository-with-userprofile". As this repository uses the user profile to authenticate its users, the post created project life cycle hook will create roles that will give write access to users for the project. The body of the request:
{
"projectName": "Awesome-project",
"repositoryName": "repository-with-userprofile"
}
The body of the response can be:
-
201 Created if everything goes well
{
"message": "The project Awesome-project has been successfully created in the repository repository-with-userprofile.",
"status": 201,
"projectName": "Awesome-project"
}
-
400 Bad request if the repository name or project name are empty, or if the repository does not exist or is not started
{
"message": "The project has not been created",
"status": 400,
"error": "The repository repository-with-user-profile is not started"
}
-
500 Internal server error if something unexpected happens
{
"message": "The project has not been created",
"status": 500,
"error": "Something happens while creating the shared modeling project: ..."
}
3. Users
This section describes the API to create, delete, list and modify users on a repository.
3.1. Rest endpoints
-
/api/{version}/users?repositoryName={repositoryId}
-
/api/{version}/users/{userName}?repositoryName={repositoryId}
3.1.1. POST /api/{version}/users?repositoryName={repositoryId}
This request will allow you to create a user in the repository. The body of the request take a JSON object with the following parameters: id, isAdministrator, password and permissions. The id and isAdministrator are mandatory. The password can be avoided if the repository authentication is managed with LDAP. The permissions parameter is used for repositories with authorization managed with user profiles. This parameter is an array of project name which will be used to grant writing rights to the user for those projects.
Creates the user "John Fryer" in the "repository-with-userprofile" repository
This example will create the user "John Fryer" in the repository named "repository-with-userprofile". As authentication is not managed with LDAP we should provide a password. We don’t want "John Fryer" to be an administrator and we want give him the writing rights to the "Awesome-project" project.
The body of the request:
{
"id": "John Fryer",
"password": "password",
"isAdministrator": false,
"permissions": [
"Awesome-project"
]
}
The body of the response can be:
-
201 Created if everything went well
{
"message": "The user John Fryer has been created in the repository repository-with-userprofile with the permissions [Awesome-project].",
"status": 201,
"user": {
"id": "John Fryer",
"isAdministrator": false,
"permissions": [
"Awesome-project"
]
},
"repositoryName": "repository-with-userprofile",
"projectNames": [
"Awesome-project"
]
}
-
400 Bad request if the repository name is not valid, the repository has not been found or is not started, or data about user to create are not valid (the validity of user data belongs to the extension that manage the authentication)
{
"message": "The user John Fryer cannot be created",
"status": 400,
"error": "The list of administrators is empty."
}
-
500 Internal server error if something unexpected occurred while creating the user
{
"message": "The user John Fryer cannot be created",
"status": 500,
"error": "An error occurred while creating the user: ..."
}
3.1.2. GET /api/{version}/users?repositoryName={repositoryId}
This request will allow you to retrieve the list of users of a repository.
Retrieves all users registered in the "repository-with-userprofile" repository
The body of the response can be:
-
200 OK if everything went well
{
"message": "The list of users for the repository repository-with-userprofile.",
"status": 200,
"repositoryName": "repository-with-userprofile",
"users": [
{
"id": "John Fryer",
"isAdministrator": false,
"permissions": [
"Awesome-project"
]
}
]
}
-
400 Bad request if the repository name is not valid or the repository has not been found or not started
{
"message": "Users cannot be listed on repository repository-with-userprofile.",
"status": 400,
"error": "The repository repository-with-userprofile has not been found."
}
-
500 Internal server error if something unexpected occurred
{
"message": "An error occurred.",
"status": 500,
"error": "..."
}
3.1.3. PUT /api/{version}/users/{userName}?repositoryName={repositoryId}
This request will allow you to update user data. As the behavior of the update of the user will delete then create the user with the new data, The body of the request take the same parameters as the body of the request that create users.
Updates the user "John Fryer" in the "repository-with-userprofile" repository
This example will update the password of "John Fryer". The body of the request:
{
"id": "John Fryer",
"password": "pass",
"isAdministrator": false,
"permissions": [
"Awesome-project"
]
}
The body of the response can be:
-
201 Created if everything went well
{
"message": "The user John Fryer has been updated in the repository repository-with-userprofile.",
"status": 201,
"user": {
"id": "John Fryer",
"isAdministrator": false,
"permissions": [
"Awesome-project"
]
},
"repositoryName": "repository-with-userprofile"
}
-
400 Bad request if the repository name is not valid, the repository has not been found or is not started, or data about user to update are not valid (the validity of user data belongs to the extension that manage the authentication)
{
"message": "The user John Fryer has not been updated in the repository repository-with-userprofile.",
"status": 400,
"error": "Administrators must be a collection of administrators."
}
-
404 Not found if the user has not been found
{
"message": "The user John Fryer has not been updated in the repository repository-with-userprofile.",
"status": 404,
"error": "The user John Fryer has not been found in the repository repository-with-userprofile."
}
-
500 Internal server error if something unexpected occurred
{
"message": "The user John Fryer has not been updated in the repository repository-with-userprofile.",
"status": 500,
"error": "An error occurred while updating the user: ..."
}
3.1.4. DELETE /api/{version}/users/{userName}?repositoryName={repositoryId}
This request will allow you to delete a user from a repository.
Deletes the user "John Fryer" from the "repository-with-userprofile" repository
This example will delete the user "John Fryer" from the repository named "repository-with-userprofile".
The body of the response can be:
-
200 OK if everything went well
{
"message": "The user John Fryer has been deleted from the repository repository-with-userprofile.",
"status": 200,
"repositoryName": "repository-with-userprofile"
}
-
400 Bad request if the repository name is not valid, the repository has not been found or is not started, or the username is not valid
{
"message": "The user John Fryer has not been deleted from the repository repository-with-userprofile.",
"status": 400,
"error": "The repository repository-with-userprofile has not been found."
}
-
404 Not found if the user has not been found
{
"message": "The user John Fryer has not been deleted from the repository repository-with-userprofile.",
"status": 404,
"error": "The user John Fryer has not been found in the repository repository-with-userprofile."
}
-
500 Internal server error if something unexpected occurred
{
"message": "The user John Fryer has not been deleted from the repository repository-with-userprofile.",
"status": 500,
"error": "An error occurred while deleting the user: ..."
}
4. Example of API use
In this section, we took the request to create a user in a repository with authorization managed with user profile.
In the following examples, the Authorization header value is taken from the administration server configuration sample in the realm.properties file and corresponds to the base64 encoded value of the sampleuser credentials. The body of the request:
{
"id": "John Fryer",
"password": "password",
"isAdministrator": false,
"permissions": [
"Awesome-project"
]
}
4.1. cURL example
curl --request POST \
--url 'http://localhost:8080/api/v1.0/users?repositoryName=repository-with-userprofile' \
--header 'Authorization: Basic c2FtcGxldXNlcjpzYW1wbGVwYXNzd29yZA==' \
--header 'Content-Type: application/json' \
--data '{
"id": "John Fryer",
"password": "password",
"isAdministrator": false,
"permissions": [
"Awesome-project"
]
}'
4.2. jQuery example
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:8080/api/v1.0/users?repositoryName=repository-with-userprofile",
"method": "POST",
"headers": {
"Authorization": "Basic c2FtcGxldXNlcjpzYW1wbGVwYXNzd29yZA==",
"Content-Type": "application/json"
},
"processData": false,
"data": "{\n \"id\": \"John Fryer\",\n \"password\": \"password\",\n \"isAdministrator\": false,\n \"permissions\": [\n\t\"Awesome-project\"\n ]\n}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
4.3. Ruby example
require 'uri'
require 'net/http'
url = URI("http://localhost:8080/api/v1.0/users?repositoryName=repository-with-userprofile")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic c2FtcGxldXNlcjpzYW1wbGVwYXNzd29yZA=='
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"John Fryer\",\n \"password\": \"password\",\n \"isAdministrator\": false,\n \"permissions\": [\n\t\"Awesome-project\"\n ]\n}"
response = http.request(request)
puts response.read_body
4.4. Python Requests example
import requests
url = "http://localhost:8080/api/v1.0/users"
querystring = {"repositoryName":"repository-with-userprofile"}
payload = "{\n \"id\": \"John Fryer\",\n \"password\": \"password\",\n \"isAdministrator\": false,\n \"permissions\": [\n\t\"Awesome-project\"\n ]\n}"
headers = {
'Authorization': "Basic c2FtcGxldXNlcjpzYW1wbGVwYXNzd29yZA==",
'Content-Type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)
4.5. Node example
var http = require("http");
var options = {
"method": "POST",
"hostname": [
"localhost"
],
"port": "8080",
"path": [
"api",
"v1.0",
"users"
],
"headers": {
"Authorization": "Basic c2FtcGxldXNlcjpzYW1wbGVwYXNzd29yZA==",
"Content-Type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ id: 'John Fryer',
password: 'password',
isAdministrator: false,
permissions: [ 'Awesome-project' ] }));
req.end();
4.6. PHP example
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "8080",
CURLOPT_URL => "http://localhost:8080/api/v1.0/users?repositoryName=repository-with-userprofile",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n \"id\": \"John Fryer\",\n \"password\": \"password\",\n \"isAdministrator\": false,\n \"permissions\": [\n\t\"Awesome-project\"\n ]\n}",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic c2FtcGxldXNlcjpzYW1wbGVwYXNzd29yZA==",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
4.7. Go example
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "http://localhost:8080/api/v1.0/users?repositoryName=repository-with-userprofile"
payload := strings.NewReader("{\n \"id\": \"John Fryer\",\n \"password\": \"password\",\n \"isAdministrator\": false,\n \"permissions\": [\n\t\"Awesome-project\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic c2FtcGxldXNlcjpzYW1wbGVwYXNzd29yZA==")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}