Is it possible to create catalog item via REST API?

Anant Garg1
Kilo Contributor

I am unable to see any end-point for catalog item creation in API doc. Is it possible to create a catalog item via API? If not, then how can we add items into the cart and submit an order? as for an order we first need to create item 

17 REPLIES 17

you can use  table API here to create record in sc_cat_item table. 

 

doc link for further details. 

 

https://developer.servicenow.com/app.do#!/rest_api_doc?v=jakarta&id=c_TableAPI

 

once you will create the record then use below api to submit the item. 

 

API name: service catalog API 

Version: Latest 

Buy Item : Post. 

 

Reference: 

https://community.servicenow.com/community?id=community_question&sys_id=038055a91b86c810a59033f2cd4b...

Harsh Vardhan
Giga Patron

another way. 

adding hi article for further details. 

 

https://hi.service-now.com/kb_view.do?sysparm_article=KB0686272

I think I am having some understanding glitch. I am considering it in terms of e-commerce where the first admin creates some items and then the buyer adds it into the cart and then creates order. Though here I am only able to add an item directly and purchase it. Isn't it that I need to create an item first as a store admin before any buyer can purchase it? Does ServiceNow work in the same manner?

AbhishekGardade
Giga Sage

Hello Anant,

You can make use of cart API. here I have used cart API to create a service Request from script:

Creating a Service Request: Using Service Catalog Script API with Inbound Emails and Attachment.

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade

Thank you,
Abhishek Gardade

Ganesh Pardhe
Kilo Guru

Hello here is small utility which can handle reference variables in REST API request for all catalog Items.

var  variables = {"user":"Abraham Lincoln","company":"Yahoo!","comments":"This is testing Text","requested_for":"System Administrator","needed_by":"Today"};
var itemId = "b5c3c1084f10330005ec00fe9310c7eb";    //myTestItem Catalog item

    for(var key in variables)
    {
        if(variables.hasOwnProperty(key) && variables[key] && typeof(variables[key]) !== 'string')
        variables[key]=variables[key].toString();
    
        var varGr = new GlideRecord('item_option_new');
    var qr = varGr.addQuery('cat_item', itemId);
    var variableSet = new sn_sc.CatItem(itemId).getVariableSet();
    if(variableSet.length > 0)
        qr.addOrCondition("variable_set", variableSet);
    varGr.addActiveQuery();
   // varGr.addQuery('mandatory', true);
    varGr.query();
   // gs.print(variable[key] + ':' + varGr.reference);
    while(varGr.next()) {
        if(varGr.type == 8)
        {
            var objTable = new TableUtils(varGr.reference);
            tableName = objTable.getAbsoluteBase();
            gs.print(objTable.getAbsoluteBase());
            if (tableName!='task')        //Check if parent table is task
                gQuery = 'name='+variables[key]; else gQuery = 'number='+variables[key];
            var tb = new GlideRecord(tableName);
            gs.print(varGr.reference);
            tb.addQuery(gQuery);
            tb.query();
            if(tb.next())
            {
                variables[key]=tb.getValue('sys_id');
            }
        }else { variables[key]=variables[key]; }
    }
}gs.print(JSON.stringify(variables));

  

Regards,

Ganesh pardhe