Create or update a password
  • 5 minutes to read
  • Dark
    Light
  • PDF

Create or update a password

  • Dark
    Light
  • PDF

Article summary

This article presents how to create or update a password in MySafe via API, the available endpoints, the parameters needed, example requests, and responses on success or in case of errors.

Authorization

The authorization for MySafe APIs is performed directly in the module. For more information, access the How to add an access key authorization document.

Authentication

Authentication in MySafe APIs is conducted using the OAuth 2.0 authentication method. To initiate this process, users need to provide the Client ID and Client Secret, as well as obtain their authentication token from the endpoint:

GET /api/oauth2/token

For more information on how to obtain the Client ID and the Client Secret, access the How to view an access key authorization document.

Methods

Create a password

Request

To add a password to MySafe, send a request to the following endpoint:

POST /api/mysafe/password
Info

When a password is added to MySafe, it’s automatically associated with the creator, identifying them as the owner.

Request parameters

Body

FieldTypeRequiredDescriptionExample
nameStringYesName assigned to the password.senseg account
urlStringNoURL of the website where the password is being used.www.senhasegura.com
usernameStringYesUsername used to access this account.npass
passwordStringYesThe password being added.8jhfy@3789
secret_keyStringNoSeed to automatically generate the TOTP.JBSWY3DPEHPK3PXP
notesStringNoAdditional notes to this password.Access details
tagsStringNoKeywords to help identify the password.tag1, tag2
users_allowedArray of objectsNoInformation about the users allowed to access the password.
usernameStringNoUsername of the user who can access the password.pduarte
can_editBooleanNoEditing permission. If left empty, the user will have only viewing permission.
groups_allowedArray of objectsNoInformation about the groups allowed to access the password.
nameStringNoName of the group that can access the password.Test group
can_editBooleanNoEditing permission. If left empty, group members will have only viewing permission.false

Example request

{
    "name": "senseg account",
    "url": "www.senhasegura.com",
    "username": "npass",
    "password": "8jhfy@3789",
    "secret_key": "JBSWY3DPEHPK3PXP",
    "notes": "Access details",
    "tags": "tag1, tag2",
    "users_allowed": [
        {
            "username" : "pduarte"
        }
    ],
    "groups_allowed": [
        {
            "name" : "Test group",
            "can_edit" : false
        }
    ]
}

Return

Adds a password to MySafe, and returns a message with information about the password-adding process.

Expected response

HTTP/1.1 201 Created
{
    "code": 201,
    "response": {
        "status": 201,
        "message": "Password successfully registered",
        "error": false,
        "error_code": 0,
        "detail": "",
        "mensagem": "Password successfully registered",
        "erro": false,
        "cod_erro": 0
    },
    "password_entity": {
        "identifier": "312",
        "name": "senseg account",
        "url": "www.senhasegura.com",
        "username": "npass",
        "note": "Access details",
        "tags": "tag1, tag2",
        "users_allowed": [
            {
                "username": "pduarte",
                "can_edit": false
            }
        ],
        "groups_allowed": [
            {
                "name": "Test group",
                "can_edit": false
            }
        ],
        "shared_error": []
    }
}

In case of error - missing a required parameter

HTTP/1.1 400 Bad Request
{
    "response": {
        "status": 400,
        "mensagem": "1001: Parameter 'username' was not informed!",
        "erro": true,
        "cod_erro": 0,
        "message": "1001: Parameter 'username' was not informed!",
        "error": true,
        "error_code": 0
    },
    "exception": {
        "code": 1001,
        "message": "1001: Parameter 'username' was not informed!",
        "detail": ""
    }
}

Update a password

Request

To update a password stored in MySafe, send a request to the following endpoint:

PUT /api/mysafe/password/update/[identifier]

Request parameters

Path

FieldTypeRequiredDescriptionExample
identifierStringYesUnique code identifier associated with each entry in the password table. This value is automatically assigned by senhasegura when creating a password and is obtained in the response to the List all the passwords or List a password request.312

Body

Info

When sending an update request, it’s not necessary to include parameters you don’t want to update.

FieldTypeRequiredDescriptionExample
nameStringNoName assigned to the password.sensegura account
usernameStringNoUsername used to access this account.senhapass
urlStringNoURL of the website where the password is being used.www.url.com
passwordStringNoThe password being added.x%8jhfy@3789a
notesStringNoAdditional notes to this password.Access details for this key
tagsStringNoKeywords to help identify the password.access
secret_keyStringNoSeed to automatically generate TOTP.3DPEHPK3PXPGHODADA
users_allowedArray of objectsNoInformation about the users allowed to access the password. Note: if you send an empty array, it removes sharing permissions.
usernameStringNoUsername of the user who can access the password.pduarte
can_editBooleanNoEditing permission. If left empty, the user will have only viewing permission.true
groups_allowedArray of objectsNoInformation about the groups allowed to access the password. Note: if you send an empty array, it removes sharing permissions.
nameStringNoName of the group that can access the password.Test group
can_editBooleanNoEditing permission.If left empty, group members will have only viewing permission.true

Example request

{
    "name": "senhasegura account",
    "username": "senhapass",
    "url": "www.url.com",
    "password": "x%8jhfy@3789a",
    "notes": "Access details for this key.",
    "tags": "access",
    "secret_key": "3DPEHPK3PXPGHODADA",
    "users_allowed": [
        {"username": "pduarte", 
        "can_edit": true
        }
    ],
    "groups_allowed": [
        {
            "name": "Test group",
            "can_edit": true
        }
    ]
}

Return

Updates a password stored in MySafe, based on its identifier, and returns a message with information about the updating process.

Expected response

HTTP/1.1 200 OK

{
    "code": 200,
    "response": {
        "status": 200,
        "message": "Password successfully updated",
        "error": false,
        "error_code": 0,
        "detail": "",
        "mensagem": "Password successfully updated",
        "erro": false,
        "cod_erro": 0
    },
    "password_entity": {
        "identifier": "312",
        "name": "senhasegura account",
        "url": "www.url.com",
        "username": "senhapass",
        "note": "Access details for this key.",
        "tags": "access",
        "users_allowed": [
            {
                "username": "pduarte",
                "can_edit": true
            }
        ],
        "groups_allowed": [
            {
                "name": "Test group",
                "can_edit": true
            }
        ],
        "shared_error": []
    }
}

In case of error - user has no access to the password

HTTP/1.1 400 Bad Request
{
    "code": 400,
    "response": {
        "status": 400,
        "message": "1005: Password not found",
        "error": true,
        "error_code": 1,
        "detail": "",
        "mensagem": "1005: Password not found",
        "erro": true,
        "cod_erro": 1
    },
    "exception": {
        "code": 1005,
        "message": "1005: Password not found",
        "detail": null
    }
}

In case of error - password not found

HTTP/1.1 400 Bad Request
{
    "response": {
        "status": 400,
        "mensagem": "1005: Password not found",
        "erro": true,
        "cod_erro": 0,
        "message": "1005: Password not found",
        "error": true,
        "error_code": 0
    },
    "exception": {
        "code": 1005,
        "message": "1005: Password not found",
        "detail": ""
    }
}


Was this article helpful?