Memberships

An organization can have several users. As long as these users belong to the organization, they are called members and the relation between a user and an organization is called Membership.

Each membership has a role and an importance and responsibility. Below there's a description of each one of them:

  • User: This is the lowest responsibility role. A regular user can only create new Expenses and follow it's updates. He can also follow Reimbursement's updates and Advancement's updates that he is the receiver.
  • Analyst: Can add and remove new members to the organization and promote them to Analysts. It's main responsibility is to manage Expenses.
  • Manager: Can add and remove new members to the organization and promote them to Analysts or Managers. It's main responsibility is to finish Expenses by using Reimbursements or Advancements.
  • Admin: Can add and remove new members to the organization and promote them to Analysts, Managers and Administrators. An Administrator can do any action in related to the organization, even delete it. He is the main responsible for the organization and cannot leave the organization unless it has an another Administrator.

Parameters

role: string
'admin', 'manager', 'analyst' and 'member'
the role of the user in the organization
user: JSON object
organization: JSON object
_links: array of object
array of links of the organization's member

Example Membership

    {
      "role": "admin",
      "user": {
        "id": 1,
        "first_name": "John",
        "last_name": "Rexpense",
        "mention_name": "JohnRexpense",
        "default_currency": "USD",
        "emails": [
          {
            "email": "john@rexpense.com",
            "main": true
          }
        ],
        "avatar": [
          {
            "style": "original",
            "url": "https://rexpense-uploads.s3.amazonaws.com/user_avatar/1/original/avatar.png",
            "width": 716,
            "height": 655,
            "expiration": "2014-06-27T20:31:43Z"
          },
          {
            "style": "medium",
            "url": "https://rexpense-uploads.s3.amazonaws.com/user_avatar/1/medium/avatar.png",
            "width": 300,
            "height": 300,
            "expiration": "2014-06-27T20:31:43Z"
          },
          {
            "style": "thumb",
            "url": "https://rexpense-uploads.s3.amazonaws.com/user_avatar/1/thumb/avatar.png",
            "width": 100,
            "height": 100,
            "expiration": "2014-06-27T20:31:43Z"
          }
          {
            "style": "tiny",
            "url": "https://rexpense-uploads.s3.amazonaws.com/user_avatar/1/tiny/avatar.png",
            "width": 48,
            "height": 48,
            "expiration": "2014-06-27T20:31:43Z"
          }
        ]
      },
      "organization": {
        "id": 1,
        "name": "Organization example 1",
        "created_at": "2014-06-03T14:17:56Z",
        "updated_at": "2014-06-03T14:17:56Z",
        "_links": [
          {
            "rel": "self",
            "method": "GET",
            "url": "https://app.rexpense.com/api/v1/organizations/1"
          },
          {
            "rel": "update",
            "method": "PUT",
            "url": "https://app.rexpense.com/api/v1/organizations/1"
          },
          {
            "rel": "partial_update",
            "method": "PATCH",
            "url": "https://app.rexpense.com/api/v1/organizations/1"
          },
          {
            "rel": "destroy",
            "method": "DELETE",
            "url": "https://app.rexpense.com/api/v1/organizations/1"
          }
        ]
      },
      "_links": [
        {
          "rel": "self",
          "method": "GET",
          "href": "https://app.rexpense.com/api/v1/organizations/1/members/1"
        },
        {
          "rel": "update",
          "method": "PUT",
          "href": "https://app.rexpense.com/api/v1/organizations/1/members/1"
        },
        {
          "rel": "destroy",
          "method": "DELETE",
          "href": "https://app.rexpense.com/api/v1/organizations/1/members/1"
        }
      ]
    }
    

List all memberships

Retrieve the list of memberships of an organization. It will return a JSON containing the name of the resource with an array of the objects requested using the membership representation.

Also, the response is always paginated. To select different pages, you have to pass the following parameters.

Parameters

page: integer
per_page: integer

Definition

GET https://app.rexpense.com/api/v1/organizations/:organization_id/members

Example Request

$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/organizations/:organization_id/members \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json'

Example Response

    {
      "memberships": [
        {
          "role": "admin",
          ...
        }
      ]
    }
    

Show a membership

Retrieve a specific membership of an organization. Returns a detailed representation of the membership.

Definition

GET https://app.rexpense.com/api/v1/organizations/:organization_id/members/:user_id

Example Request

$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/organizations/:organization_id/members/:user_id \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json'

Create a membership

Creates an invitation for each email. Those invitations are processed asynchronously in another job.

Parameters

user[email]: string
required
one or more e-mails, separated by commas

Expired organization

If the organization is expired, it will return an 402 error.

Definition

POST https://app.rexpense.com/api/v1/organizations/:organization_id/members/

Example Request

$ curl -u $YOUR_API_TOKEN:X -X POST https://app.rexpense.com/api/v1/organizations/:organization_id/members \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json' \
      -d '{"user": {"email":"user@email.com, another.user@email.com"}}'
      

Example Response Success

HTTP 201 CREATED
    {
      "total_recipients": "1",
      "not_added_recipients": "0",
      "added_recipients": "1",
      "invalid_recipients": "0"
      ...
    }
    

Example Response Failure

HTTP 422 Unprocessable Entity
    {
      "errors": {
        "message": ["Missing parameters: user"]
      }
    }
    

Example Response Failure when some recipients are correct and others not

HTTP 422 Unprocessable Entity
    {
      "total_recipients": "2",
      "not_added_recipients": "0",
      "added_recipients": "1",
      "invalid_recipients": "1"
      ...
    }
    

Example Response Failure when organization is expired

HTTP 402 Payment Required
    {
      "errors": {
        "message": "This organization is expired and in read-only mode until this situation have been solved."
      }
    }
    

Update a membership

Updates the role of the user in the organization. Returns a detailed representation of the membership.

Parameters

role: string
'admin', 'manager' and 'member'
the role of the user in the organization

Expired organization

If the organization is expired, it will return an 402 error.

Definition

PUT https://app.rexpense.com/api/v1/organizations/:organization_id/members/:user_id

Example Request

$ curl -u $YOUR_API_TOKEN:X -X PUT https://app.rexpense.com/api/v1/organizations/:organization_id/members/:user_id \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json' \
      -d '{"role":"member"}'

Example Response Success

HTTP 200 OK
    {
      "role": "member",
      ...
    }
    

Example Response Failure

HTTP 422 Unprocessable Entity
    {
      "errors": {
        "role": ["can' be blank"]
      }
    }
    

Example Response Failure when organization is expired

HTTP 402 Payment Required
    {
      "errors": {
        "message": "This organization is expired and in read-only mode until this situation have been solved."
      }
    }
    

Remove a membership

Removes a membership from an organization.

Expired organization

If the organization is expired, it will return an 402 error.

Definition

DELETE https://app.rexpense.com/api/v1/organizations/:organization_id/members/:user_id

Example Request

$ curl -u $YOUR_API_TOKEN:X -X DELETE https://app.rexpense.com/api/v1/organizations/:organization_id/members/:user_id \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json'

Example Response Success

HTTP 204 NO CONTENT

Example Response Failure when organization is expired

HTTP 402 Payment Required
    {
      "errors": {
        "message": "This organization is expired and in read-only mode until this situation have been solved."
      }
    }
    

Leave an organization

You can leave an organization. However, if you're the only administrator of the organization, you'll not be able to leave the organization.

Definition

DELETE https://app.rexpense.com/api/v1/organizations/:organization_id/members

Example Request

$ curl -u $YOUR_API_TOKEN:X -X DELETE https://app.rexpense.com/api/v1/organizations/:organization_id/members \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json'

Example Response Success

HTTP 204 NO CONTENT

Example Response Failure

HTTP 422 Unprocessable Entity
    {
      "error": "You cannot leave the organization being the only organization's administrator."
    }