在ServiceNow Catalog API中设置参考变量

时间:2019-02-14 19:06:51

标签: java rest http-post servicenow-rest-api

我目前正在使用Java中的ServiceNow Catalog Rest API。我已经成功地将商品添加到购物车并提交了购物车,但是,只要帖子正文中的变量的类型为引用,我就无法设置其值。这些字段中创建的票证只是空的。下面是我的代码的一个小例子。

   HttpPost post = new HttpPost();

   post.setURI(new URI("https://myinstance/api/sn_sc/servicecatalog/items/" + itemId + 
   "/add_to_cart"));

   String encoding =
   Base64.getEncoder().encodeToString(("User:Password").getBytes("UTF-
   8"));

   String authHeader = "Basic " + encoding;

   post.setHeader(HttpHeaders.AUTHORIZATION, authHeader);

   post.setHeader("Content-Type", "application/json");

   /*WorkgroupAssignment is of type reference and never gets set.While 
     short_description' always gets set.*/

   String data = "{'sysparm_quantity': 1,'variables': {'short_description': 
  'Example description','WorkgroupAssignment':'TSU-Middleware'};

   StringEntity entity = new StringEntity(data);

   /**
     * *******************
     * and now the body.. 
     * *******************
   */

   post.setEntity(entity);



   HttpClient client = HttpClientBuilder.create().build();

   /**
     * *******************
     * Parse the response 
     * *******************
   */
   HttpResponse response = client.execute(post);

设置引用类型的变量是否需要做一些特殊的事情?

谢谢

0 个答案:

没有答案