Deleting a member of a multi valued user attribute using scim PATCH - rest

I have a user store where user have multi valued attributes like email.
So the user will have attribute called emails which may have 0 to many emails on it.
"emails" : ["1#xx.x", "2#xx.x",........]
Let's say I need to delete "1#xx.x" email address from the users email list. Can I do it using user PATCH? If so what should I send with request?

You can do it using PATCH. Except when removing a value from a multi-valued attribute, you have to include an "operation" sub-attribute, which in this case should have a value of "delete". It's discussed in section 3.3.2 in the spec:
http://www.simplecloud.info/specs/draft-scim-api-01.html
Here is an example, from that link:
PATCH /Groups/acbf3ae7-8463-4692-b4fd-9b4da3f908ce
Host: example.com
Accept: application/json
Content-Type: application/json
Authorization: Bearer h480djs93hd8
If-Match: W/"a330bc54f0671c9"
{
"schemas": ["urn:scim:schemas:core:1.0"],
"members": [
{
"display": "Babs Jensen",
"value": "2819c223-7f76-453a-919d-413861904646"
"operation": "delete"
}
]
}

Related

How to create permission to read/view files?

How do I pass the permissions hash or json? correctly and maybe access token?
https://www.googleapis.com/drive/v3/files/file_id/permissions
This is the body I want
{
"role": "reader",
"type": "user",
"emailAddress": "cratagg#gmail.com"
}
But I don't know how to include it in postman. I've been trying many ways but none seems to work. I couldn't either with the https://developers.google.com/oauthplayground/ - I may not know how to formulate the request.
The only thing that worked was the https://developers.google.com/drive/api/v3/reference/permissions/create "Try this API" section
The Try this API feature shows the HTTP implementation if expanded
So, in your case, the request would be:
POST https://www.googleapis.com/drive/v3/files/[FILEID]/permissions?key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{
"role": "reader",
"type": "user",
"emailAddress": "cratagg#gmail.com"
}
Whereby you need to specify the API key and the FILEID.

Should the resource ID be put in URL of PUT and PATCH requests?

Should PUT's and PATCH's URL contains ID or could it be put inside the body?
PUT /person/UUID {"name": "Jimmy"}
OR
PUT /person/{"UUID":1, "name": "Jimmy"}
( the same for the PATCH)
?
As PUT is defined as Replace the current document found at the URI location with the one provided in the payload sending a PUT request to /person should probably lead to a removal of any person managed by that particular endpoint, in case that URI represents a collection of persons.
As mentioned in this post one might use a URI without some special entity identifier in case this is an all purpose container. Think of a clipboard where you can copy some data to to later on retrieve it to paste it somewhere else. In such a case the identifier is implicitly given by the URI itself, as after all URI stands for unique resource identifier
Note that a URI as a whole identifies a resource and does not necessarily imply some form of parent-child structure. A client especially should not attempt to extract knowledge from an URI at all.
In regards to PATCH it depends. Usually one should use a media-type that is intended for patching such as JSON Patch or JSON Merge Patch.
The former representation defines certain fields that state that a field should be added, removed or replaced with a given value in a notation like the one listed below:
PATCH /my/data HTTP/1.1
Host: example.org
Content-Length: 326
Content-Type: application/json-patch+json
If-Match: "abc123"
[
{ "op": "test", "path": "/a/b/c", "value": "foo" },
{ "op": "remove", "path": "/a/b/c" },
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
{ "op": "replace", "path": "/a/b/c", "value": 42 },
{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
{ "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
]
JSON Merge Patch however works differently. It defines some default rules that instruct a server on how to apply the changes to the target document. A document like below i.e. will either add or update field a to have value z afterwards while the property f of c's object has to be deleted. All the other remaining properties of that resource remain as they are.
PATCH /target HTTP/1.1
Host: example.org
Content-Type: application/merge-patch+json
{
"a":"z",
"c": {
"f": null
}
}
Both of these media-types could be used to send a request directly to the "collection"-resource as both can target sub-elements by definition. However, in terms of caching I'd try to avoid it.
Caching in HTTP works de facto on the URI of the resource. Any unsafe operation performed on that URI leads to the cache invalidating a stored representation for that target. I.e. if you previously invoked GET /person/1 and now perform a PUT or PATCH, which both are unsafe operations, on /person the data might get updated, though a client requesting GET /person/1 afterwards may still retrieve the cached response via the cache as it is unaware of any changes done to that resource.

Understanding a PATCH request

The following is the structure of my content in MongoDB
{
partnerName: "Zumba Fitness",
supportedProducts: [
"Fitness 1.0",
"Protein Bars"
]
}
I want to modify/update the contents of supportedProducts upon a PATCH request. For example, I want to change Fitness 1.0 to Fitness 2.0
I am unsure how the request for PATCH from the client side will look like. Would be it something as following
PATCH /data/{partnerName}
Content-Type: application/json
[
{ op: "replace", path: "/supportedProducts", value: "Fitness 2.0" }
]
I have tried the above, but it did not modify the content in my database
RFC 6902 says the media type for JSON Patch is
application/json-patch+json
I have tried the above, but it did not modify the content in my database
I wouldn't expect that to happen by magic; you are still going to need to invoke code that will apply the patch. For example: jsonpatch-to-mongodb

How to change ejabberd MUC subject

I've tried to change MUC subject using ejabberd API but didn't work. I use Postman to work with the API
api : /api/change_room_option
request body :
{
"name": "testgroup",
"service": "conference.localhost",
"option": "subject",
"value": "BookNerds"
}
error : "400 Bad Request"
I've enabled change_room_option in my ejabberd.yaml and set allow_change_subj to true. Using this configuration and same request body format, I successfully change 'title' and 'description'.
Note : I ran another test using Adium and successfully change the subject. When I check in database, subject and subject_author have been updated. Do I need to set subject_author too in the request body? If yes - I don't think it's possible since change_room_option will only accept four parameters as stated here

Setting Author Id of sharepoint list item with rest API

I'm trying to create a new list item, but specify the created by to someone other than the account that's inserting the records, it looks like from some of the documentation it should be possible to also set the created by after the fact too, either way is fine with me, the below example is me trying to update an existing record with a new created by.
I've found an example of updating the created by from the .net API http://blogs.msdn.com/b/sowmyancs/archive/2008/03/14/can-we-update-the-values-of-created-by-modified-by-columns-in-sharepoint-lists.aspx
Everything looks like it works with this request, but the value isn't actually updated.
POST http://sp/site/_api/web/lists/getByTitle('listtitle')/items(255) HTTP/1.1
X-HTTP-Method: MERGE
X-RequestDigest: <requestDigest>
IF-MATCH: *
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.1; en-US) WindowsPowerShell/3.0
Content-Type: application/json;odata=verbose
Host: sp
Content-Length: 196
{
"Author": {
"Id": 555
},
"__metadata": {
"type": "SP.Data.listtitleListItem"
}
}
You need to update the Author field to not be read only. You can post to:
/_api/web/lists/getByTitle('listtitle')/Fields('<createdbyguid>')
Updating the field ReadOnlyField to false
After that the updates to AuthorId (but not Author { Id }) will work.