Reputation: 1
I am having a difficulties integrating our 3rd party application with the Service Catalog via WebService (SOAP or REST).
My main goal: Send a REST or SOAP request to ServiceNow and order a Service Catalog item/Run the associated workflow to create tasks for specified groups.
I've attempted to run an OrderGuide from a WebService, but I started by just trying to hit the sample inbound WebService, under 'Scripted SOAP Services' , 'Order a BlackBerry', with no success.
Here is the Sample Code for 'Order a BlackBerry' with only the last line modified:
var cart = new Cart();
var item = cart.addItem('e2132865c0a8016500108d9cee411699');
cart.setVariable(item, 'original', request.phone_number);
// set the requested for
var gr = new GlideRecord("sys_user");
gr.addQuery("user_name", request.requested_for);
gr.query();
if (gr.next()) {
var cartGR = cart.getCart();
cartGR.requested_for = gr.sys_id;
cartGR.update();
}
var rc = cart.placeOrder();
response.request_number = rc.number;
response.test = "You ran the Script!";
I was able to send a SOAP request with PHP using a service account with all security roles(dev instance, don't worry!), and received ONLY the response.test contents. The request_number was blank, and no items inserted in the ServiceNow instance.
Questions(if someone would be so kind to help me out!! An answer to any question would help greatly.):
What configuration am I missing that would allow me to run the WebService, but not complete the order?
What is the suggested method for ordering a catalog item, creating a task or running the associated workflow from a WebService if this is not it?
Does anyone have a working example request for the 'Order a BlackBerry' sample script (preferably PHP, but I can work with others), or running an Order Guide from an inbound SOAP/REST request?
Thanks for any information!
Upvotes: 0
Views: 824
Reputation: 3284
I think the suggested Method to this would be to use the Service Catalog API. You would just make a HTTP Post to the following URL
https://instance_name.service-now.com/api/sn_sc/servicecatalog/items/sys_id_of_your_item/order_now
For variables you would send them in the request body as json object, like:
{
'your_var1': 'value1',
'your_var2': 'value2'
}
I don't have a working PHP Example, only cURL command but I think you could use this in PHP ^^
curl "https://instance_name.service-now.com/api/sn_sc/servicecatalog/items/item_sys_id/order_now" \
--request POST \
--header "Accept:application/json"\
--header "Content-Type:application/json" \
--data "{ 'your_var1': 'value1', 'your_var2': 'value2' }" \
--user 'admin':'admin'
Upvotes: 0