Sharepoint 2013: EnsureUser via REST API

前端 未结 2 1683
悲&欢浪女
悲&欢浪女 2021-01-03 16:44

I\'m trying to ensure some users automatically via REST API. My REST call:

$.ajax({
url: \"blablabla/_api/web/ensureuser\",
type: \"POST\",
data: \"{ \'logon         


        
2条回答
  •  梦毁少年i
    2021-01-03 17:21

    ALTERNATIVE SOLUTION:

    You could also perform a REST query in the following way:

            $.ajax({
            url: "http://[website]/_api/web/ensureuser('"+user_name+"')",
            type: "POST",
            headers: {             
                'accept': 'application/json;odata=verbose;charset=utf-8',
                'Content-Type': 'application/json;odata=verbose;charset=utf-8',
                'X-RequestDigest': $("#__REQUESTDIGEST").val()                    
            },
            success: function(response_data){ [your custom success action]
            },
            error: function(response_data){[your custom fail action]}
          });
    

    var user_name will contain target AD username.

    NOTE:

    • When using the ensureUser method against an AD user, just use its username. So, user_name would be something like this: "username". No need to add "domain\" before neither any other kind of prefix/suffix. Just the username

    • ContentType & accept headers MUST be application/json;odata=verbose;charset=utf-8

提交回复
热议问题