现在服务api如何以特定用户身份发表评论 [英] Service now api how to comment as specific user

查看:63
本文介绍了现在服务api如何以特定用户身份发表评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个使用Service Now API(Rest)的项目.为此,我们的客户已将我们注册为用户,以便登录并拨打我们需要的所有服务电话.该项目具有一个界面,用户一旦在立即服务"上拥有一个帐户,便可以登录,顺便说一下,他们键入的登录用户名与现在的服务无关,但后来他们将其现在的服务用户与该用户相关联.他们可以通过此界面执行一些操作,所有这些操作都是使用集成用户/通过而不是通过他们的服务(现在是他们自己)来完成的,即使他们不需要与我们共享密码.但是需要跟踪正确的用户以立即注册服务,而我在针对事件进行评论时遇到了麻烦.注释端点如下:

I'm working on a project that consumes Service Now API (Rest). To do so our client has registered us as a user in order to login and make all service calls we need to. This project has an interface where users can login once they have an account on Service Now as well, the username they type to log in has nothing to do with service now by the way, but later they associate theirs service now users to it. They can do some operations through this interface, where all of them are done using the integration user/pass not their service now users theirselves, even because they do not need to share their passwords with us. But it's needed to track the correct user to register on service now and I'm in trouble specifically about commenting on an incident. The endpoint to comment is the following :

http://hostname/api/now/table/incident/ {sys_id}

其中请求正文是一个json对象,就像:

where request body is a json object just as simple as :

{
"comments": "My comment is foo bar"
}

但是当此评论在立即服务"上注册时,它属于集成用户,而不是评论的用户.考虑到我已经在Service Now上准备好了该用户ID,可以使用任何方式保留特定的用户,以便在请求时以应有的方式通知该用户.我尝试阅读《立即服务》文档,但不知道如何解决,应该我已经找到了有关模拟的内容

but when this comment is registered on Service Now it is under integration user instead the user which commented. Is there any way I could keep a specific user, considering I already have the user id on Service Now ready to inform it on the request the way it should be. I tried reading Service Now documentation but had no clue how to solve it, altought I've found something about impersonate

推荐答案

首先,您需要具有足够权限的集成用户.我们的集成用户具有开箱即用的充分权利,但是您的故事可能会有所不同.快速检查是尝试使用菜单模拟为其他用户.

Firstly, you need an integration user with suffient rights. Our integration user has suffient rights out of the box, but your story could be different. A quick check is to try impersonate as other user using menu.

  1. 以集成用户身份登录ServiceNow实例.
  2. 转到https://{instance} .service-now.com/nav_to.do
  3. 单击右上角的用户名.这是一个下拉列表.
  4. 应该至少有三个菜单项:配置文件",模拟用户"和注销".如果您没有模拟用户",则在此菜单中,您的集成用户错过了一些权限.如果您错过此菜单项,请与系统管理员联系以配置适当的权限.

然后,您需要找到要模拟的用户的sys_id.例如:

Then you need to find sys_id of user that you want to impersonate. For example:

https://{instance} .service-now.com/api/now/table/sys_user?sysparm_query = user_name = {username}& sysparm_fields = sys_id

https://{instance}.service-now.com/api/now/table/sys_user?sysparm_query=user_name={username}&sysparm_fields=sys_id

如果具有足够的特权,则可以使用要模拟的用户的sys id调用以下端点:

If you have suffient privileges, you could invoke the folling endpoint with sys id of user that you want to impersonate:

  • HTTP POST到正文为"{}"的https://{instance} .service-now.com/api/now/ui/impersonate/{user_sys_id};和内容类型"application/json".您需要以集成用户身份对此查询提供HTTP基本身份验证.

成功时的响应代码为200.响应正文可以忽略.该响应的有趣结果是在响应标头中为模拟用户设置了一组cookie.这些cookie可以用于后续的REST API调用,直到它们过期为止.使用一些依赖HTTP Rest客户端的方法来捕获它们并将它们提供给下一次调用.

The response code on success is 200. The response body could be ignored. The interesting result of this response is a set of cookies for impersonated user in response headers. These cookies could be used for subsequent REST API calls until they expire. Use some HTTP rest client dependent method to capture them and to provide them to next calls.

对于Apache HTTP客户端(Java),我正在使用以下方法创建http客户端上下文:

For Apache HTTP Client (Java), I'm creating http client context using:

    HttpClientContext context = HttpClientContext.create();
    context.setCookieStore(new BasicCookieStore());

将事物上下文传递给模拟请求和后续的API调用,直到得到401答复为止,此后,我正在获取cookie.设置新的Cookie存储非常重要,否则将使用一些默认的Cookie存储.

Pass thing context to impersonation request and to subsequent API calls until I get 401 reply, after that I'm reaquiring cookies. Setting new cookie store is important, as otherwise some default cookies store is used.

需要注意的两件事:

  • 此API看起来像内部API,因此可以随时更改.如果发生这种情况,请寻找什么过分用户".菜单项执行,然后重复执行.
  • ServiceNow权限非常精细,因此目标用户可能缺少执行操作的权限.在某些情况下,如果没有更新字段的权限,则对对象的操作PATCH将返回响应200,但不会更新字段.使用模拟时,这会带来令人惊讶的失败模式.

这篇关于现在服务api如何以特定用户身份发表评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆