Skip to main content

Users API v2

Introduction to the Users API v2

Written by Amanda

NOTE! New documentation site

This API documentation page is deprecated and no longer maintained.
All SameSystem API documentation, including our latest guides and API references, has moved to our new documentation portal:
https://docs.samesystem.dev/

Please update your bookmarks and use the new documentation site going forward.

The SameSystem Users API v2 allows you to manage employee records with more consistency, and an improved structure compared to previous version.
This API provides the essential tools to do user integrations securely and efficiently.

This version introduces new endpoints specifically for user handling. While department data is still retrieved via v1 endpoint, authorization is now also available through a dedicated v2 endpoint. Either v1 or v2 can be used to obtain an access token for performing requests. Only the user-specific data is versioned under /api/v2.

This approach ensures backward compatibility while enabling a gradual migration to the new structure.

Technical documentation for v2 can be found here.


Getting started

To get started, you must have a SameSystem user with correct permissions and with the necessary API access rights enabled by an administrator within the client. Once the setup is complete, you’ll receive API credentials that allow you to authenticate and interact with the system.

The first step will be familiarizing yourself with SameSystem’s API endpoints and the general integration flow. With the correct credentials, you’ll be able to:

  • Use GET requests to retrieve resources like users, contracts or titles.

  • Use POST, PUT or DELETE requests to create, update or delete resources.

All API requests return JSON responses and must include the following headers:

Content-Type: application/json

Authorization: Bearer <your-token>

Note: The Authorization header is required for all endpoints except login.


Authorization & department scope (via v1)

While the Users API itself lives under /api/v2, department scoping is still governed by the SameSystem API v1.

Authorization rules

To use SameSystem API, check the "Enable API" setting in the client's “General settings”, create a user through the UI, and enable the "API access" setting in the employee card, “Security” tab. Grant all necessary permissions for this particular user to accomplish given tasks. API permissions work precisely the same as permissions in web-based SameSystem. Attempting to access or modify users beyond your authorized permissions will not be successful.

Authorization (v1-based)

SameSystem uses OAuth 2.0 protocol for authorization, and it supports Resource Owner Password Credentials and Refresh token grant types.
Password grant type is used to get the access and refresh tokens. The access token is expiring in 1 hour, and the refresh token expires in 6 months. The tokens you'll receive are bearer. Every call you make will require you to have the access token in the Authorization header, so add Bearer and then the access token afterwards. You can get the access and refresh tokens with the API user and password received from SameSystem, and setting the grant_type to password. After the access token expires, you can use the Refresh token grant type to get a new access token.
To swap the refresh token for a new access token, use the same endpoint, but add this in the request body instead:

{ "refresh_token": "eyJhbGciOiJIUzUxMiJ9.eyJpbmZvX2lkIjoiNWU2MDg5NTU3N2Y4OWNiNDg3N2EwMDE4IiwiZXhwIjoxNTk5Mjg1ODEwfQ.g74AIsgaXw0qHydop5X3FKJKGJMefcEnlJTAUD7B5jmNSKtf4sV6_wJQUwIXkrCYz9Xh0Pcvzj4nXWhJeTydnQ", "grant_type": "refresh_token" }

You can also look in the API v1 documentation here.

Alternatively, you can obtain the access token using the v2 endpoint. It works slightly differently, but both methods return a valid token that can be used to make requests.

What is {clientToken} in the URL and how to use it

  • CTX token is a "c\d+d\d+" formatted string and consists of a "c" value and a "d" value where the c identifies the company (client) and the d identifies the department. These values are unique across SameSystem. Note that you for API v2 only need the client part (c) as we utilize Client token.

  • Your client token is not available via API for security reasons, please copy-paste it from SameSystem. It is in URL address when you're logged in, right after domain, for example, "https://api.samesystem.com/c1d10/..."


Department identification

Departments can be referenced in user operations by internal SameSystem IDs and client-defined external identifiers.

Note: In v1, the equivalent of a client-defined external identifier was often called shop_custom_id. In v2, it’s the same field departmentId for both cases.

To use the external department ID simply ensure the value is provided in the department card and use the parameter: useExternalDepartmentId=true. This can be added in the URL like /api/v2/{clientToken}/users/create_with_contract?useExternalDepartmentId=true. This will map the provided departmentId with the according department that has the value set in the setup. Endpoints that support this feature specify it in the Parameters section of the swagger documentation.

You can retrieve department data using:

This endpoint returns both internal and external identifiers so you can confidently reference departments when managing users.


User identification

Users can be referenced in operations by internal SameSystem IDs and client-defined external identifiers as well.

To use the external user IDs ensure the “Use custom IDs for employees” setting in the "General settings" is enabled and the value is provided in the employee card, “Security” tab or customID is present if users are created using the API. Use the parameter: useCustomId=true. This can be added in the URL like /api/v2/{clientToken}/users/{id}?useCustomId=true. This will map the id with the according user that has the custom ID value set. Endpoints that support this feature specify it in the Parameters section of the swagger documentation.


Custom fields

Custom fields can be referenced in operations by internal SameSystem IDs and client-defined external identifiers as well.

To use the external custom field IDs ensure the “Custom ID” field value is provided in the custom field setup. The body could look like this:

  • "customFields": [ { "customId": "12345", "value": "something" } ]

For internal SameSystem IDs the body could look like this:

  • "customFields": [ { "id": "12345", "value": "something" } ]

It’s possible to send multiple values to a multiple choice field by providing an array like this:

  • "customFields": [ { "id": "12345", "value": "[\"value 1\", \"value 2\"]" } ]


Contract hours pr. weekday (hoursWeekWeekdays)
Allows you to define contract hours pr. weekday for an employee’s contract.
This feature is only applied if the following are enabled in the UI:

  • General settings → Schedule

    • Personal settings for contract days pr. week

    • Specifying contract hours pr. weekday

The value is a JSON-encoded string mapping weekday1weekday7 to decimal hour values.

  • Values are hours in decimals (e.g., 8.5 = 8 hours 30 minutes).

  • Use a dot (.) as the decimal separator.

  • Use 0 for non-working days.

Example:
"hoursWeekWeekdays": "{\"weekday1\":1.1, \"weekday2\":3, \"weekday3\":2, \"weekday4\":8.5, \"weekday5\":0, \"weekday6\":0, \"weekday7\":0}",
"workAmountType": "hours_per_weekday"


Fetching users (GET /api/v2/{clientToken}/users, GET /api/v2/{clientToken}/users/{id})

  • Specify in the URL which fields should be returned. Example:

/api/v2/{clientToken}/users?fields[User]=email,fullName,contract.startDate,contract.status, customFields.extraField.id,customFields.extraField.name,customFields.value,contracts.department.id

Available values can be found in the swagger documentation

  • Filtering and sorting users are supported. Refer to the swagger documentation for more details.

In v2 we no longer depend on defined templates done by SameSystem employees as we do in v1.


Note: we use titleId for providing a title on a contract for the user. You can retrieve title data using:


Creating a user (POST /api/v2/{clientToken}/users/create_with_contract, POST /api/v2/{clientToken}/users)

  • We recommend using the create_with_contract endpoint which creates a full user including contract terms.

    • For user to receive a Welcome email to SameSystem ensure to add "SendWelcomeEmail": true.

  • Required fields include personal data such as firstName and lastName, titleId, departmentId. They will be listed in the response of an unsuccessful request if not provided or see schema.

  • The provided department becomes the user’s primary department.

Updating a user (PUT /api/v2/{clientToken}/users/{id})

  • Supports updates to personal information and custom fields (General tab fields).

  • These are not date dependent as they will update as soon as they are received.


Note: a change of start date for employment will need to be done through PUT/api/v2/{clientToken}/users/{id}/update_start_date


Terminating a user (POST /api/v2/{clientToken}/users/{id}/terminate)

  • Termination is tied to the employment lifecycle which means that it’s the date for end of employment.

Rehiring a user (POST /api/v2/{clientToken}/contracts/rehire

  • Supports rehiring a user on the same employee card to keep historical data in the same place. This will create a new employment.

  • We support down to a single day gap in employments.

Removing termination (POST /api/v2/{clientToken}/users/{id}/remove_termination)

  • Continues employment if we have not reached the date for end of employment with existing contract terms or reactivates users that were previously terminated.

  • If termination is removed there will be no gap between contracts.

Inserting a contract (POST /api/v2/{clientToken}/users/{userId}/contracts/insert)

  • If the validity period falls between existing contracts, it adjusts their dates accordingly and inserts the new contract in between.

  • To avoid recreating contracts when the start date matches an existing contract and update that one instead, enable the general setting “Keep same start_date contracts during contract insert in API v2”.

Upserting users with contracts (POST/api/v2/{clientToken}/users/upsert_with_contracts)

  • Requires “Use custom IDs for employees” general setting to be enabled.

  • Supports providing multiple users in a single request.

  • If the user is not found by the provided externalUserId (which is basically a customId), then the create_with_contract is performed that creates the user with contract. If found, then the user update with contract insert is performed.

  • The output is self-explanatory. It's possible for some users to fail while others succeed. Failed users, along with error messages, will be included in the response.

  • It’s recommended to have the general setting “Keep same start_date contracts during contract insert in API v2” enabled to avoid recreating contracts.

  • It does not support rehiring users. A separate endpoint should be used for that.


A quick guide on how to use the API v2 Swagger documentation

2. Click on the required endpoint.

3. Select required fields to be returned in the response, if necessary, from the list.

4. Copy the request body example.

5. Click on "Schema" to view all available fields for the request body, along with their types, by expanding each value.

Did this answer your question?