Submit a Catalog Item via Service Catalog API with Variables.

jeffD1
Tera Contributor

Hello,

I am trying to find some information on how to create an item from my catalog via rest API. I have many items that have Variables in them that need to be filled out to capture data before submission. I have need to create items via REST. I understand that the Service Catalog API can be used to do this, but I need to set my custom created variables as well.

Example:

I have an Item called "Request Something Else". This item has three variables on the form. Those are Description and User. I need to populate these two variables with plain text. How would one go about setting up this request in the REST API Explorer for example using the Service Catalog API?

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you take a look at the Service Catalog API scripted rest api in your instance, then click into the Add Item To Cart scripted rest resource and click the documentation tab it gives you a request body example that you should be able to use to add an item to the cart with the variables populated:

{  
   'sysparm_quantity': 2,
   'variables': {  
      'carrier': 'at_and_t_mobility',
      'data_plan': '500MB',
      'duration': 'eighteen_months',
      'color': 'black',
      'storage': 'sixtyfour'
   }
}

The documentation for that endpoint can be found here.

View solution in original post

9 REPLIES 9

Hey Brad,

 

How would you set values for Variable Sets? It seems like we're able to set values for variables, but not variable sets.

 

Thanks!

Albert

I believe you would treat the variables on the item and on the item through variable sets the same way.

Hi Brad,

Thanks for the response. I'm trying to use the REST API Explorer with the "add_to_cart" API. I created a simple string variable and the variable and value does not come back in the response body. For this API, the documentation says, "variables Name/value pairs of all mandatory cart item variables. Mandatory variables are defined on the associated form." If I make this variable mandatory at the variable level, then I get a 400 response.

What I'm doing wrong?

Albert

jes3
Giga Contributor

Can you show an example for set values for variable set in json

variable set name - 'process_detail':
value: "[{"prone_to_human_error":"Yes","percent_standardized":"25","access_unstructured_data":"Yes","percent_rule_based":"30%","process_change_frequency":"N/A"}]"


{

'sysparm_quantity':2,

'variables':{
'process_name':'test claysys process',
'process_steps': 'test1',
'notes':'testnote',
'process_name':'processtest'
}

The above is my json.Could you help me embed the variable set in it..

 

pls help...

Thanks in advance..

Hi Brad,

Could you please tell me how I can pass an array of values to a variable?

For eg:

{
'sysparm_quantity': 1,
'variables': {
     'value1': ["k1":"v1", "k2":"v2"]
     'value2': 'some value'
}
}