[midPoint] Bulk Assignment of Roles to Users via JSON API Request

Pavol Mederly mederly at evolveum.com
Tue Jun 21 13:16:40 CEST 2022


Hello Alexander,

actually, there was a couple of problems in your JSON code, mainly 
related to namespace.

This one is parseable:

{
     "@ns" : "http://midpoint.evolveum.com/xml/ns/public/model/scripting-3",
     "pipeline": [
         {
             "@element": "search",
             "type": "c:UserType",
             "searchFilter": {
"@ns" : "http://prism.evolveum.com/xml/ns/public/query-3",
                 "inOid": {
                     "value": [
                         "c38dc04a-e780-4475-ad51-f42dd054f622",
                         "cd244459-81fe-4208-a51c-111cae039185",
                         "12d665c0-7114-4b49-97ba-94c4cd154f8a"
                     ]
                 }
             }
         },
         {
             "@element": "sequence",
             "@value": [
                 {
                     "@element": "action",
                     "type": "assign",
                     "parameter": {
"name": "role",
                         
"http://midpoint.evolveum.com/xml/ns/public/common/common-3#value": {
"@type": "string",
"@value": "a6afcd50-5f33-4250-8b93-62cb72e1a39a"
                         }
                     }
                 }
             ]
         }
     ]
}

(the changes are highlighted)

Note that since 4.2 it's possible to write the actions in more compact, 
statically-typed way. See 
https://docs.evolveum.com/midpoint/reference/misc/bulk/actions/ or 
https://github.com/Evolveum/midpoint/blob/30e5a166e566a99517dedb48680622a8c651c1ea/model/model-intest/src/test/resources/scripting/assign-pirate-manager-to-will.xml 
for an XML sample.

Like this (I have also removed "sequence" as it superfluous here):

{
     "@ns" : "http://midpoint.evolveum.com/xml/ns/public/model/scripting-3",
     "pipeline": [
         {
             "@element": "search",
             "type": "UserType",
             "searchFilter": {
                 "@ns" : "http://prism.evolveum.com/xml/ns/public/query-3",
                 "inOid": {
                     "value": [
                         "00000000-0000-0000-0000-000000000002"
                     ]
                 }
             }
         },
         {
             "@element": "assign",
             "targetRef": {
                 "oid": "00000000-0000-0000-0000-000000000008",
                 "type": "RoleType"
             }
         }
     ]
}

Best regards,

-- 
Pavol Mederly
Software developer
evolveum.com

On 21/06/2022 12:12, Alexander Bruckner via midPoint wrote:
>
> Hello,
>
> thank you for your suggestions!
>
> I am not sure if the pipeline itself is the problem since the request 
> seems to work as an XML request, only when attempting to send it in 
> JSON format the mentioned error happened.
>
> Kind regards,
>
> Alexander
>
> *Von:*Emil Militzer <emil.militzer at posteo.de>
> *Gesendet:* Mittwoch, 15. Juni 2022 17:46
> *An:* midPoint General Discussion <midpoint at lists.evolveum.com>
> *Cc:* Alexander Bruckner <alexander.bruckner at ventum.com>
> *Betreff:* Re: [midPoint] Bulk Assignment of Roles to Users via JSON 
> API Request
>
> Hi,
>
> I think this will not work because the pipeline is not working correctly:
>
> *
>
> *
>
> https://jira.evolveum.com/browse/MID-7965?orderby=updated+DESC%2C+priority+DESC
>
> Kind regards
>
> Emil
>
>
>
>     Am 15.06.2022 um 15:08 schrieb Alexander Bruckner via midPoint
>     <midpoint at lists.evolveum.com>:
>
>     
>
>     Hello everyone,
>
>     we are currently trying to assign one role to multiple users via a
>     JSON API request. We’ve already managed to do this over XML with
>     this request body:
>
>     <s:pipelinexmlns:s=http://midpoint.evolveum.com/xml/ns/public/model/scripting-3
>     <http://midpoint.evolveum.com/xml/ns/public/model/scripting-3>
>
>     xmlns:c=http://midpoint.evolveum.com/xml/ns/public/common/common-3
>     <http://midpoint.evolveum.com/xml/ns/public/common/common-3>
>
>     xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
>     <http://www.w3.org/2001/XMLSchema-instance>
>
>     xmlns:xsd=http://www.w3.org/2001/XMLSchema
>     <http://www.w3.org/2001/XMLSchema>
>
>     xmlns:q=http://prism.evolveum.com/xml/ns/public/query-3
>     <http://prism.evolveum.com/xml/ns/public/query-3>>
>
>     <s:search>
>
>     <s:type>c:UserType</s:type>
>
>     <s:searchFilter>
>
>     <q:inOid>
>
>     <q:value>c38dc04a-e780-4475-ad51-f42dd054f622</q:value>
>
>     <q:value>cd244459-81fe-4208-a51c-111cae039185</q:value>
>
>     <q:value>12d665c0-7114-4b49-97ba-94c4cd154f8a</q:value>
>
>     </q:inOid>
>
>     </s:searchFilter>
>
>     </s:search>
>
>     <s:sequence>
>
>     <s:action>
>
>     <s:type>assign</s:type>
>
>     <s:parameter>
>
>     <s:name>role</s:name>
>
>     <c:valuexsi:type="xsd:string">a6afcd50-5f33-4250-8b93-62cb72e1a39a</c:value>
>
>     </s:parameter>
>
>     </s:action>
>
>     </s:sequence>
>
>     </s:pipeline>
>
>     But similar approaches do not seem to work for JSON. We attempted
>     the recommended method via heterogenous lists as outlined in
>     https://docs.evolveum.com/midpoint/devel/design/xml-json-yaml-vs-xnode-vs-internal-data/heterogeneous-lists/:
>
>     {
>
>         "@ns" :
>     http://midpoint.evolveum.com/xml/ns/public/model/scripting/extension-3,
>
>         "pipeline": [
>
>             {
>
>     "@element": "search",
>
>                 "type": "c:UserType",
>
>     "searchFilter": {
>
>     "inOid": {
>
>        "value": [
>
>     "c38dc04a-e780-4475-ad51-f42dd054f622",
>
>     "cd244459-81fe-4208-a51c-111cae039185",
>
>     "12d665c0-7114-4b49-97ba-94c4cd154f8a"
>
>     ]
>
>                     }
>
>                 }
>
>             },
>
>             {
>
>     "@element": "sequence",
>
>     "@value": [
>
>                     {
>
>     "@element": "action",
>
>     "type": "assign",
>
>     "parameter": {
>
>     "type": "role",
>
>     "value": "a6afcd50-5f33-4250-8b93-62cb72e1a39a"
>
>     }
>
>                     }
>
>                 ]
>
>             }
>
>         ]
>
>     }
>
>     But received the error message:
>
>     <message>Wrong input value for ExecuteScriptType: RawType: (raw): XNode(list:2 elements))</message>
>
>     <details>java.lang.IllegalArgumentException: Wrong input value for ExecuteScriptType: RawType: (raw): XNode(list:2 elements))
>
>     It seems like Pipeline is not expecting a list of objects.
>
>     Is there some error in our current JSON or is there a different
>     way of writing the query?
>
>     If anyone of you has some advice regarding this, it would be
>     greatly appreciated!
>
>     Thank you and best regards,
>
>     Alexander Bruckner
>
>     _______________________________________________
>     midPoint mailing list
>     midPoint at lists.evolveum.com
>     https://lists.evolveum.com/mailman/listinfo/midpoint
>
>
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com
> https://lists.evolveum.com/mailman/listinfo/midpoint
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20220621/742151ea/attachment-0001.htm>


More information about the midPoint mailing list