Solved

Create SharePoint Group with Contribute permissions


 

 

I Followeb the blog Create SharePoint Group with Contribute permissions but I received an error when I call Query XML.

 

1313i973EB9DA3628C5DD.png

The Digest Token variable is:

{"d":{"GetContextWebInformation":{"__metadata":{"type":"SP.ContextWebInformation"},"FormDigestTimeoutSeconds":1800,"FormDigestValue":"0x6A9282CB6D5AF6D75CDAFDBD2D4B4617968675505F540AC7965E48D67746A965983370BF20046CC0A0504BD133A93F573F2D1ABEF8944A40FD206E2E73856BFA,03 Apr 2019 10:48:44 -0000","LibraryVersion":"16.0.8720.1224","SiteFullUrl":"https://server.sharepoint.com/sites/poc","SupportedSchemaVersions":{"__metadata":{"type":"Collection(Edm.String)"},"results":["14.0.0.0","15.0.0.0"]},"WebFullUrl":"https://server.sharepoint.com/sites/poc/nintex"}}}

On the "web request" action I use the user with domain

1314i4C306DC09AB3B982.png

If I remove the domain in the username, the error is on web request action:

Digest Token: {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}

The initiator and the user specify in the web request are site collection administrators.

Any idea how to solve this?

 

 

 

icon

Best answer by nico 25 April 2019, 10:44

View original

13 replies

Userlevel 7
Badge +17

can you show the Query XML action, as that is where the error is occuring?

This is the action that shows the error, but maybe the web request response is already wrong

The first error is on the "Query XML" action where we try to read the object "FormDigestValue". I have changed this action by dictionaries to get the value as indicated in this post: how to parse json data in nintex workflow for office 365

 

Now, when I call to ‌/_api/web/sitegroups using "Call HTTP Web Service" action received "BadRequest"

Userlevel 7
Badge +17

I'm confused on your response. When does which error occur? You made a change, but what was the result?

 

It looks like your attempt to get the digest worked fine. If it didn't you would have received an unauthorized error, but in your image of the history a digest is there and you quoted a value that has the digest. So that doesn't seem to be the issue.

The first problem was to obtain the digest value using query XML but I resolved them using dictionaries.

Now, when I call Call HTTP Web Service ({Workflow Context:Current site URL}‌/_api/web/sitegroups)  to create the group the result is " Bad request" 

 

Userlevel 4
Badge +10

Hi,

For your first post, you receive this error ("XML content is invalide .....") because the return of your WebService is in JSON. So you pass JSON to the action "query XML", and that's why you got this error. 

 

In you action, you specify the header : "Accept" : "application/json;odata=verbose", with this you say : "I want the result of this query in JSON format"

You just have to Remove your Header "Accept", and your result will be in XML format. (by default, the /_api/contextinfo will return XML format)

Like : 

 

 

In your action query XML, you can use this XPath to get the Digest: 

//*[local-name()='FormDigestValue']

 

 

For your secund error, 

I think you error is in your content, may be it's not well formated.

 

To query this REST end point, you must at least have in your header

"content-type""application/json; odata=verbose" 

"Accept": "application/json;odata=verbose",
"X-RequestDigest":"......."

 

And in your content : 

{
            "__metadata": {
                "type": "SP.Group"
            },
            "Title": "groupName",
            "Description": "group desc"

}

 


@nico wrote:

...

For your secund error, 

I think you error is in your content, may be it's not well formated.

 

To query this REST end point, you must at least have in your header

"content-type""application/json; odata=verbose" 

"Accept": "application/json;odata=verbose",
"X-RequestDigest":"......."

 

And in your content : 

{
            "__metadata": {
                "type": "SP.Group"
            },
            "Title": "groupName",
            "Description": "group desc"

}

 


Thanks a lot @nico but the second part continues to fail.

 

 

And the result is:

According to the post I followed, it is not necessary to specify any parameters for the creation of the group.

Any idea what is missing?
Thank you

Userlevel 4
Badge +10

I don't see the error too ...

 

May be nintex build and pass your parameter with a wrong format (the "request content"). 

Have you try to use the "web request" action (instead of a "call http web ervice") and pass your JSON in the "body" of your request ? (and not use build dictionnary to create your JSON)

 

Hi @nico 

I used "web request" and pass my JSON on the body directly and the result is bad with different text

@fhunthAny idea? 

 

Userlevel 4
Badge +10

Be carful, you pass a wrong content type in your request.

Your body is in JSON format, and in your query Content type (in the header) the value is XML. 

Change your "content type" value with : "application/json;odata=verbose"

(I have just test it, and I have sucess full create a SPGroup)

Thanks @nico . It must have been some proof. I have reviewed all the headers and I have the same as the photo you send. The result is the same

If I use web request:

Store response Content: {"error":{"code":"-2130575251, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your

If I use Call http Web Service:

 headers: {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The property '__metadata' does not exist on type 'SP.Group'. Make sure to only use property names that are defin

The only difference is that Web request I can pass the contents of the body and headers directly and with call I have to use dictionaries.

 

If you have a solution that works, there would be a possibility that you would export that WF and send it to me and I'll try it (deleting your username and password)

Userlevel 4
Badge +10

No problem for exporting the Workflow, see it in attachment (I have renamed the package with .zip, remove it before import)

 

An exemple of the result : 

 

Note : In my 2 "Web Request" actions, I set my Email / password, else I have an UnauthorizedAccessException

 

Be carefull, there is actualy a bug when you want to use JSON and workflow varariable. 

You can find some workaround here : 

https://community.nintex.com/t5/Nintex-for-Office-365/Build-string-jSon-and-workflow-variables-not-working/m-p/24979#M3405

https://community.nintex.com/t5/Nintex-for-Office-365/Changing-Site-URL-and-Title-via-Nintex-Workflow/m-p/35921#comment-34390

 

Good luck

@nico  Your solution works!
I think the difference (and the error) is in passing the content in a string and not in a dictionary.

 

Thank you very much for your time and help.

 

Reply