Центр помощи / Администратор / 4. Интеграции / Использование API для синхронизации пользователей

Использование API для синхронизации пользователей

В статье:
1. Аутентификация (Auth)
2. Создание пользователя (Create User)
3. Получение данных о пользователе (Get User)
4. Получение списка пользователей (Get User List)
5. Обновление данных пользователя (Update User)
6. Удаление пользователя (Delete User)
7. Создание группы (Create Group)
8. Получение данных о группе (Get Group)
9. Обновление данных группы (Update Group)
10. Удаление группы (Delete Group)

С помощью документа API администратор может настроить синхронизацию пользователей и групп.

1. Аутентификация (Auth)

В запросах POST, PATCH Content-Type должен быть application/scim+json
Authorization должен быть Bearer {номер токена}

2. Создание пользователя (Create User)

Request
Post – api/scim/Users

{
   "schemas":[                                           // required                                
      "urn:ietf:params:scim:schemas:core:2.0:User"       // required
   ],
   "externalId": "0a21f0f2-8d2a-4f8e-bf98-7363c4aed4ef", // optional
   "userName": "[email protected]",                        // required
   "name":                                               // required
   {                                             
      "familyName": "familyName",                        // required
      "givenName": "givenName"                           // required
   }
   "active" : true,                                      // optional
   "phoneNumbers": [                                     // optional
   {
      "type": "work",
      "value": "9111111111"
   }
   ],
   "title": "position",                                 // optional
   "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": 
   {
      "department": "Company Department"                // optional
   }
}

Response
HTTP 201

{
   "schemas":[                                           // required                                
   {
      "schemas": [
            "urn:ietf:params:scim:schemas:core:2.0:User"
      ],
      "externalId": "0a21f0f2-8d2a-4f8e-bf98-7363c4aed4ef",
      "userName": "[email protected]",
      "active" : true,
      "id" : "9a21f0f2-8d2a-4f8e-bf98-7363c4aedww4"
      "name": {
            "formatted": "givenName familyName",
            "familyName":"familyName",
            "givenName":"givenName"
      }, "meta": {
            "resourceType": "User",
            "created": "2018-03-27T19:59:26.000Z",
            "lastModified": "2018-03-27T19:59:26.000Z"
      },
      "phoneNumbers": [
      {
             "type": "work",
             "value": "9111111111" }
                      ],
      "title": "position",
      "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": {
                   "department": "Company Department"
      }
   }

3. Получение данных о пользователе (Get User)

Request
Get – api/scim/Users/{id}

Response

  {
    "schemas": [
            "urn:ietf:params:scim:schemas:core:2.0:User"
      ],
    "id": "5b1e2d805-62cd-4738-8611-1cfd46f3e89b",
    "externalId": "58342554-38d6-4ec8-948c-50044d0a33fd",
    "active" : true ,
    "meta": {
        "resourceType": "User",
        "created": "2018-03-27T19:59:26.000Z",
        "lastModified": "2018-03-27T19:59:26.000Z"
    },
    "userName": "[email protected]",
    "name": {
        "formatted": "givenName familyName",
        "familyName": "familyName",
        "givenName": "givenName",
    },
    "phoneNumbers": [
    {
       "type": "work",
       "value": "9111111111" }
                    ],
    "title": "position",
    "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": {
                   "department": "Company Department"
    }
}

4. Получение списка пользователей (Get User List)

Request
Get – api/scim/Users
Get – api/scim/Users?filter=userName eq “[email protected]
it is possible to use a filter to search for a specific user Support attribute startIndex and count

Response

  {
      "schemas": [
          "urn:ietf:params:scim:api:messages:2.0:ListResponse"
      ],
      "totalResults": 28,
      "startIndex": 1,
      "itemsPerPage": 20,
      "Resources": [
      {
          "schemas": [
             "urn:ietf:params:scim:schemas:core:2.0:User"
           ],
          "id": "2441309d85324e7793ae",
          "externalId": "7fce0092-d52e-4f76-b727-3955bd72c939",
          "meta": {
             "resourceType": "User",
             "created": "2018-03-27T19:59:26.000Z",
             "lastModified": "2018-03-27T19:59:26.000Z"
      },
          "userName": "[email protected]",
          "name": {
             "familyName": "familyName",
             "givenName": "givenName"
          },
          "active": true
          "phoneNumbers": [
          {
            "type": "work",
            "value": "9111111111" 
          }
                      ],
          "title": "position",
          "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": {
                   "department": "Company Department"
          }
     },
     ... //другие пользователи
     ]
}

5. Обновление данных пользователя (Update User)

Request
PATCH – api/scim/Users/{id} – HTTP/1.1

Use op for:
Replace:

          active,
          externalId,
          name.familyName,
          name.givenName,
          userName,
          phoneNumbers[type eq "work"].value,
          title,
          urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:department

Add:

          externalId,
          name.familyName,
          name.givenName,
          userName,
          phoneNumbers[type eq "work"].value,
          title,
          urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:department
Для удаления атрибута отправляется Replace с value пустая строка
Value for active may be: "False", “0”, “True”, “1”
 {
      "schemas": [
            "urn:ietf:params:scim:api:messages:2.0:PatchOp"          // required
      ],
      "Operations": [                                                // required
            {
                  "op": "Replace",
                  "path": "userName",
                  "value": "[email protected]"
            },
            {
                  "op": "Replace",
                  "path": "name.familyName",
                  "value": "updatedFamilyName"
            },
            {
                  "op": "Replace",
                  "path": "name.givenName",
                  "value": "updatedgivenName"
            },
            {
                  "op": "Replace",
                  "path": "externalId",
                  "value": “externalNumber”
            },
            {
                  "op": "Replace",
                  "path": "active",
                  "value": "False"
            },
            {
                  "op": "Replace",
                  "path": "title",
                  "value": "replace Position"
            },
            {
                  "op": "Replace",
                  "path":"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:department",
            }, 
            {
                  "op": "Replace",
                  "path": "phoneNumbers[type eq \"work\"].value",
                  "value": "9111111111"
            }
       ]
}

Response
HTTP/1.1 200 OK

{
      "schemas": [
            "urn:ietf:params:scim:schemas:core:2.0:User"
      ],
      "id": "6764549bef60420686bc",
      "externalId": "6c75de36-30fa-4d2d-a196-6bdcdb6b6539",
      "meta": {
            "resourceType": "User",
            "created": "2018-03-27T19:59:26.000Z",
            "lastModified": "2018-03-27T19:59:26.000Z"
       },
    "userName": "[email protected]",
    "name": {
        "formatted": "givenName updatedFamilyName",
        "familyName": "updatedFamilyName",
        "givenName": "givenName"
    },
    "active": true,
    "phoneNumbers": [
    {
      "type": "work",
      "value": "9111111111" }
                    ],
    "title": "position",
    "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": {
                   "department": "Company Department"
     }
}

6. Удаление пользователя (Delete User)

Request
DELETE – api/scim/Users/{id} – HTTP/1.1

Response
HTTP/1.1 204 No Content

7. Создание группы (Create Group)

Request
POST – /api/scim/Groups – create group

POST /Groups HTTP/1.1

{
    "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
    "externalId": "8aa1a0c0-c4c3-4bc0-b4a5-2ef676900159",
    "displayName": "GroupName",
    "meta": {
        "resourceType": "Group"
    }
}

Response
HTTP/1.1 201 Created

{
    "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
    "id": "927fa2c08dcb4a7fae9e",
    "externalId": "8aa1a0c0-c4c3-4bc0-b4a5-2ef676900159",
    "meta": {
        "resourceType": "Group",
        "created": "2018-03-27T19:59:26.000Z",
        "lastModified": "2018-03-27T19:59:26.000Z"
    },
    "displayName": "GroupName",
    "members": []
}

8. Получение данных о группе (Get Group)

Request
GET – api/scim/Groups – get groups list

Response
HTTP/1.1 200 OK

{
    "schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
    "totalResults": 1,
    "resources": [{
        "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
        "id": "8c601452cc934a9ebef9",
        "externalId": "0db508eb-91e2-46e4-809c-30dcbda0c685",
        "meta": {
            "resourceType": "Group",
            "created": "2018-03-27T22:02:32.000Z",
            "lastModified": "2018-03-27T22:02:32.000Z",
        },
        "displayName": "GroupName",
    }],
    "startIndex": 1,
    "itemsPerPage": 20
}

9. Обновление данных группы (Update Group)

Request
PATCH – /api/scim/Groups/{id} – update group
PATCH /Groups/a99962b9f99d4c4fac67 HTTP/1.1

path: members 
op: Remove
{
    "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
    "Operations": [{
        "op": "Remove",
        "path": "members",
        "value": [{
            "$ref": null,
            "value": "f648f8d5ea4e4cd38e9c"
        }]
    }] 
}
op: Add
{
    "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
    "Operations": [{
        "op": "Add",
        "path": "members",
        "value": [{
            "$ref": null,
            "value": "f648f8d5ea4e4cd38e9c"
        }]
    }] 
}
op: Replace
{
    "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
    "Operations": [{
        "op": "Replace",
        "path": "members",
        "value": [{
            "$ref": null,
            "value": "f648f8d5ea4e4cd38e9c"
        }]
    }] 
}
path: displayName
{
    "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
    "Operations": [{
        "op": "Replace",
        "path": "displayName",
        "value": "updatedDisplayName"
    }] 
}
пример:
{
      "schemas": [
            "urn:ietf:params:scim:api:messages:2.0:PatchOp"     // required 
      ],
      "Operations": [                                           // required
            {
                  "op": "Replace",
                  "path": "displayName",
                  "value": "updatedDisplayName"
            },
      ]
}

Response
HTTP/1.1 204 No Content

10. Удаление группы (Delete Group)

Request
DELETE – /api/scim/Groups/{id} – delete group

Response
HTTP/1.1 204 No Content

Оставьте заявку, и мы свяжемся с вами в течение 30 минут.

Загрузка