# SCIM Operations

## HTTP Method

<table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" id="bkmrk-get-retrieves-one-or" role="grid"><tbody><tr style="height: 29px;"><td style="width: 16.6667%; height: 29px;">GET

</td><td style="width: 83.3333%; height: 29px;">Retrieves one or more complete or partial resources.

</td></tr><tr style="height: 29px;"><td style="width: 16.6667%; height: 29px;">POST

</td><td style="width: 83.3333%; height: 29px;">Depending on the endpoint, creates new resources, creates a search request, or MAY be used to bulk-modify resources.

</td></tr><tr style="height: 29px;"><td style="width: 16.6667%; height: 29px;">PUT

</td><td style="width: 83.3333%; height: 29px;">Modifies a resource by replacing existing attributes with a specified set of replacement attributes (replace). PUT MUST NOT be used to create new resources.

</td></tr><tr style="height: 29px;"><td style="width: 16.6667%; height: 29px;">PATCH

</td><td style="width: 83.3333%; height: 29px;">Modifies a resource with a set of client-specified changes

(partial update).

</td></tr><tr style="height: 29px;"><td style="width: 16.6667%; height: 29px;">DELETE

</td><td style="width: 83.3333%; height: 29px;">Deletes a resource.

</td></tr></tbody></table>

### Get

A HTTP Get request is used to fetch a resource or a set of resources.

#### Read

```
http://<your-domain>/soffid/webservice/scim2/v1/{Resource}/{id}
```

- id: is the identifier of a specific resource

#### Search

```
http://<your-domain>/soffid/webservice/scim2/v1/{Resource}/?ﬁlter={attribute}{op}{value}&sortBy={attributeName}&sortOrder={ascending|descending}&attributes={attributes}
```

- **filter**: allows you to add filter to query. 
    - attribute
    - op: SCIM has support for the filter operations equals, contains, starts with, and more.
    - value
- **sortBy**: the attribute used to sort the response.
- **sortOrder**: order to sort, ascending or descending. Ascending is the default order.

In addition, you can request specific attributes of the resource, or exclude attributes (separated by commas if there is more than one).

- **attributes**={attributes}
- **excludedAttributes**={attributes}

Example:

```
http://<your-domain>/soffid/webservice/scim2/v1/User?filter=lastName co ada and active eq true &sortOrder=descending&sortBy=userName&attributes=userName,lastName&filter=userName co admin
```

#### Sorting

<table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" id="bkmrk-parameter-descriptio" role="grid"><thead class="tableFloatingHeaderOriginal"><tr class="tablesorter-headerRow" role="row" style="height: 35px;"><th aria-disabled="false" aria-label="Data type: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col" style="width: 110px; height: 35px;" tabindex="0">**Parameter**

</th><th aria-disabled="false" aria-label="Value: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col" style="width: 698.182px; height: 35px;" tabindex="0">**Description**

</th></tr></thead><tbody aria-live="polite" aria-relevant="all"><tr role="row" style="height: 29px;"><td class="confluenceTd" colspan="1" style="width: 110px; height: 29px;">sortBy</td><td class="confluenceTd" colspan="1" style="width: 698.182px; height: 29px;">Specifies the attribute whose value will be used to order ther returned responses.</td></tr><tr role="row" style="height: 29px;"><td class="confluenceTd" colspan="1" style="width: 110px; height: 29px;">sortOrder</td><td class="confluenceTd" colspan="1" style="width: 698.182px; height: 29px;">Allowed values are "ascending" and "descending".

If sortBy is provided, and sortOrder is nos provided, sortOrder will be "ascending" by default.

</td></tr></tbody></table>

Sorting example:

```
http://<your-server>/soffid/webservice/scim2/v1/User?sortBy=lastName&sortOrder=descending
```

#### Pagination

<table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" id="bkmrk-parameter-descriptio-0" role="grid"><thead class="tableFloatingHeaderOriginal"><tr class="tablesorter-headerRow" role="row" style="height: 35px;"><th aria-disabled="false" aria-label="Data type: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col" style="width: 110px; height: 35px;" tabindex="0">**Parameter**

</th><th aria-disabled="false" aria-label="Value: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col" style="width: 704.545px; height: 35px;" tabindex="0">**Description**

</th></tr></thead><tbody aria-live="polite" aria-relevant="all"><tr role="row" style="height: 29px;"><td class="confluenceTd" colspan="1" style="width: 110px; height: 29px;">startIndex</td><td class="confluenceTd" colspan="1" style="width: 704.545px; height: 29px;">Index of the first query result. Default 1</td></tr><tr role="row" style="height: 29px;"><td class="confluenceTd" colspan="1" style="width: 110px; height: 29px;">count</td><td class="confluenceTd" colspan="1" style="width: 704.545px; height: 29px;">Maximun numer of query results per page</td></tr></tbody></table>

Pagination example:

```XML
http://<your-server>/soffid/webservice/scim2/v1/User?startIndex=1&count=10
```

```JSON
{
     "totalResults":100,
     "itemsPerPage":10,
     "startIndex":1,
     "schemas":["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
     "Resources":[{
       ...
     }]
}
```

### Post

A HTTP Post request is used to create a new resource

```
http://<your-domain>/soffid/webservice/scim2/v1/{Resource}
```

```
Content-Type: application/json
```

You must send the JSON with the attributes of the resource you want to create.

```JSON
{
  "schemas":[{schema}],
  "attribute1":"value1",
  "attribute2":"value2",
  "attribute3":{
    "subattribute1":"valueX",
    "subattribute1":"valueX",
  },
  .......
}
```

- schema: is the schema url of the resource you are creating.
- attributes: name of the resource attributes.
- values: values for each attribute.

### Put

A HTTP Put request is used to update resources. This operation replace all values of the resource

```
http://<your-domain>/soffid/webservice/scim2/v1/{Resource}/{id}
```

```
Content-Type: application/json
```

You must send the JSON with the attributes of the resource you want to update, which includes the ID.

```JSON
{
  "schemas":[{schema}],
  "id": "idValue",
  "attribute1":"value1",
  "attribute2":"value2",
  "attribute3":{
    "subattribute1":"valueX",
    "subattribute1":"valueX",
  },
  .......
}
```

- schema: is the schema url of the resource you are creating.
- id: identifier of the resource
- attributes: name of the resource attributes.
- values: values for each attribute.

### Patch

A HTTP Patch request is used to update partial resources

```
http://<your-domain>/soffid/webservice/scim2/v1/{Resource}/{id}
```

```JSON
{
    "Operations": [
        {
            "op": "operation",
            "path": "attribute",
            "value": "value"
        },
        ............
    ]
}
```

- op: available operations to realize: 
    - add: allows you to add a new value to an attribute.
    - remove: allows you to delete the value of an attribute.
    - replace: allows you to replace (update) the value of an attribute.

<p class="callout info">More information about the operations on [https://www.rfc-editor.org/rfc/rfc6902](https://www.rfc-editor.org/rfc/rfc6902)</p>

- path: to indicate the attribute on which the operation is to be performed.
- value: the new value for the attribute.

### Delete

A HTTP Delete request is used to delete a resource.

```
http://<your-domain>/soffid/webservice/scim2/v1/{Resource}/{id}
```

- id: is the identifier of a specific resource

## Request

In the PUT and PATCH methods, a JSON stream with the data model is required (please see this format in the following link: [ Resource data model](https://bookstack.soffid.com/books/scim/chapter/resource-data-model "Resource data model")).

## Response

The response format will be represented as a SCIM JSON response, but all the keys in the response will depend on the method requested and the result of the operation.

### HTTP Status

The most commons responses

#### Successful Responses

<table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" id="bkmrk-200-ok-201-created" role="grid"><tbody><tr style="height: 29px;"><td style="width: 79px; height: 29px;">200

</td><td style="width: 728px; height: 29px;">OK

</td></tr><tr style="height: 29px;"><td style="width: 79px; height: 29px;"><div>201</div></td><td style="width: 728px; height: 29px;">Created

</td></tr><tr><td style="width: 79px;"><div>204 </div></td><td style="width: 728px;">No Content

</td></tr></tbody></table>

#### Error Response

<table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" id="bkmrk-400-bad-request-401-" role="grid"><tbody><tr style="height: 29px;"><td style="width: 79px; height: 29px;">400

</td><td style="width: 728px; height: 29px;">Bad Request

</td></tr><tr style="height: 29px;"><td style="width: 79px; height: 29px;"><div>401</div></td><td style="width: 728px; height: 29px;">Unauthorized

</td></tr><tr style="height: 29px;"><td style="width: 79px; height: 29px;">403

</td><td style="width: 728px; height: 29px;">Forbidden

</td></tr><tr style="height: 29px;"><td style="width: 79px; height: 29px;">404

</td><td style="width: 728px; height: 29px;">Not Found

</td></tr><tr style="height: 29px;"><td style="width: 79px; height: 29px;">500

</td><td style="width: 728px; height: 29px;"><div>Internal Server Error</div></td></tr></tbody></table>

For instance, when you search by id but no resource is found, only a 404 HTTP code is included in the response (the body is empty, no JSON is provided).

User cases:

- Search by id but no resource is found (404 code).
- Update all, the id is not found (404 code).
- Update partial, the id is not found (404 code).
- Delete, the id is not found (404 code).
- A "/&lt;resource&gt;" (in the URL) not exist (404 code).
- Other errors (404 or 500 code).

<p class="callout info">More detail about [SCIM JSON error](#bkmrk-scim-json-error)</p>

## SCIM JSON Response


### SCIM JSON list

For instance, when a list of resources is requested, this is the JSON output format:

*Note, to simplify the JSON output every resource has been replaced by {...}*

```JSON
{
  "totalResults": 3,
  "schemas": [
    "urn:ietf:params:scim:api:messages:2.0:ListResponse"
  ],
  "resources": [
    {...},
    {...},
    {...}
  ]
}
```

This is the description of this type of response:

<div id="bkmrk-attribute-descriptio"><table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" role="grid"><thead class="tableFloatingHeaderOriginal"><tr class="tablesorter-headerRow" role="row"><th aria-disabled="false" aria-label="Attribute: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col" style="width: 120px;" tabindex="0"><div>Attribute</div></th><th aria-disabled="false" aria-label="Description: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col" style="width: 693px;" tabindex="0"><div>Description</div></th></tr></thead><tbody aria-live="polite" aria-relevant="all"><tr role="row"><td class="confluenceTd" colspan="1" style="width: 120px;">totalResults</td><td class="confluenceTd" colspan="1" style="width: 693px;">Number of the resources returned in the response</td></tr><tr role="row"><td class="confluenceTd" style="width: 120px;">schemas</td><td class="confluenceTd" style="width: 693px;">Defined by SCIM protocl. Always: "[urn:ietf:params:scim:api:messages:2.0:ListResponse](http://urnietfparamsscimapimessages:2.0:ListResponse)"</td></tr><tr role="row"><td class="confluenceTd" colspan="1" style="width: 120px;">resources<span class="hiddenGrammarError"> </span></td><td class="confluenceTd" colspan="1" style="width: 693px;">List of resources returned</td></tr></tbody></table>

</div>User cases:

- A list all operation (200 code).
- A search by filter operation (200 code).
- The delete operation (204 code).

### SCIM JSON resource

For instance, when a resource by id is requested, this is the JSON format:

*Note, to simplify the JSON output every resource has been replaced by {...}*

```JSON
{
  "id": 11345
  "organizational": true,
  ...
}
```

In this case, the JSON stream of the resource is included directly in the response.

User cases:

- Search by id operations (200 code).
- Successful create operations (201 code).
- Successful complete update operations (200 code).
- Successful partial update operations (200 code).

### SCIM JSON error

For instance, if an attempt to delete a resource is made, but this resource is not found the following JSON response will be obtained:

```JSON
{
  "schemas": [
    "urn:ietf:params:scim:api:messages:2.0:Error"
  ],
  "detail": "User 1234 not found",
  "status": "404"
}
```

This is the description of this type of response:

<table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" id="bkmrk-attribute-descriptio-0" role="grid"><thead class="tableFloatingHeaderOriginal"><tr class="tablesorter-headerRow" role="row"><th aria-disabled="false" aria-label="Attribute: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col" style="width: 123px;" tabindex="0"><div>**Attribute**</div></th><th aria-disabled="false" aria-label="Description: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col" style="width: 678px;" tabindex="0"><div>**Description**</div></th></tr></thead><tbody aria-live="polite" aria-relevant="all"><tr role="row"><td class="confluenceTd" style="width: 123px;">schemas</td><td class="confluenceTd" style="width: 678px;">Defined by SCIM protocl. Always: "[urn:ietf:params:scim:api:messages:2.0:Error](http://urnietfparamsscimapimessages:2.0:Error)"</td></tr><tr role="row"><td class="confluenceTd" colspan="1" style="width: 123px;">detail</td><td class="confluenceTd" colspan="1" style="width: 678px;">Returns the description on the validation, problem, error, etc</td></tr><tr role="row"><td class="confluenceTd" colspan="1" style="width: 123px;">status</td><td class="confluenceTd" colspan="1" style="width: 678px;">Is the HTTP status, that is the same that the HTTP code of the HTTP response</td></tr></tbody></table>

User cases:

- When you try to delete a resource but it's not found (404 code).
- When you try to delete a group, the solution is to disable it by PATCH (500 code).
- Generic errors (500 code).