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 07:47 AM
The only issue i see here is you are missing closing brace } in the body
Here is the format
{
'sysparm_quantity': 1,
'variables': {
'short_description': 'Test description',
'WorkgroupAssignment':'89e10e5d1f654ec9a627bbef202af78c'
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 07:53 AM
Sorry...in my actual code I have that closing brace. I guess when I copied and pasted I left it out

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 07:57 AM
and is '89e10e5d1f654ec9a627bbef202af78c' sys_id from groups table?
and does the integration user has access to the particular group record?