How to set reference variables in Catalog API posts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 11:52 AM
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);
WorkgroupAssignment is of type reference. Is there something special I have to do to set variables of type reference?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 06:09 AM
One more question:
This is the information about the WorkgroupAssignment variable:
{
"8": "sys_user_group",
"label": "Choose a Workgroup Assignment",
"type": 8,
"mandatory": true,
"displayvalue": "",
"friendly_type": "reference",
"display_type": "Reference",
"render_label": true,
"ref_qualifier": "typeISEMPTY^active=true^EQ",
"read_only": false,
"name": "WorkgroupAssignment",
"attributes": "edge_encryption_enabled=true",
"id": "c42c0de337b007408c0ddaa543990e6b",
"value": "",
"help_text": "",
"max_length": 0
}
Am I correct in saying that the body of the Post should then look like this?:
{'sysparm_quantity': 1,'variables': {'short_description': 'Test description','WorkgroupAssignment':'89e10e5d1f654ec9a627bbef202af78c'}
Just asking because this isn't setting the value either.
Thanks again

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 07:53 AM
I would validate in ServiceNow that you have the correct sys_id and also that you're able to select that group through the ui. From your json response the variable looks like it has a reference qualifier of typeISEMPTY^active=true so you would need to make sure that this group is active and the type has a value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 07:59 AM
Will do...thanks again!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 06:37 AM
i see that you are using add_to_cart end point. Do you have a checkout cart REST call later?
Use below endpoint to submit a catalog item
/api/sn_sc/servicecatalog/items/{sys_id}/order_now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 06:42 AM
Hi,
Yes...I'm able to add an item to the cart and then call the checkout endpoint. The ticket gets created and all the mandatory variables get set other than variables of type reference. That's the part I'm trying to figure out.