Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How can I submit request via curl api commands and set requested_for to other user?

ShaMan
Kilo Contributor

Hi All,

I am new to the community and using the SNow API. I am hoping the community can help me resolve an issue with submitting a request using the web api account on behalf of a user.

So my SNow team gave me a web api enabled account for submitting request via rest api. We are using SNow Jakarta. I have been using curl cmds with submitting tests and all the tests expect 1 keeps defaulting 'requested_for' as the web api account. My very first test I submitted was the only test so far in which the code did submit to a correct 'requested_for" of another user.

My curl code I am using:

curl -u username:password -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" https://test.service-now.com/api/sn_sc/v1/servicecatalog/items/sysid/add_to_cart -d '{"sysparm_quantity":"1","requested_for":"sysid","variables":{}'

 

Curl to check cart:

curl -u username:password -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" https://test.service-now.com/api/sn_sc/v1/servicecatalog/cart/checkout

Result of checking the cart before submission:

 result": {
        "cart_id": "",
        "delivery_address": "",
        "none": {
            "items": [
                {
                    "cart_item_id": "",
                    "catalog_item_id": "",
                    "delivery_time": "",
                    "item_name": "Other Request",
                    "localized_price": "$0.00",
                    "localized_recurring_price": "$0.00",
                    "price": "$0.00",
                    "quantity": "",
                    "recurring_frequency": "",
                    "recurring_price": "$0.00",
                    "variables": {
                        "Additional comments": "testing",
                        "Business Justification": "testing",
                        "Cost center": "",
                        "Description of Service Needed": "software",
                        "Grant/Activity not found": "false",
                        "Grant/Activity number": "",
                        "Model after item": "",
                        "My Grant/Activity number": ""
                    }
                }
            ],
            "show_subtotal_price": "false",
            "subtotal_price": "-",
            "subtotal_recurring_frequency": "",
            "subtotal_recurring_price": "$0.00",
            "subtotal_title": "Subtotal",
            "total_title": "Total"
        },
        "requested_for": "1234567890",
        "requested_for_user": "Web API User",
        "show_subtotal_price": "false",
        "special_instructions": "",
        "subtotal_price": "-",
        "subtotal_recurring_frequency": "",
        "subtotal_recurring_price": "$0.00",
        "subtotal_title": "Subtotal",
        "total_title": "Total"
    }

 

Code I use to submit req:

curl -u username:password -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" https://test.service-now.com/api/sn_sc/v1/servicecatalog/cart/submit_order

 

I am hoping someone can give me insight if my code is correct for submitting onbehalf or how I can modify the cart before submit so the "requested_for " can be changed to the correct onbehalf user.

1 REPLY 1

ShaMan
Kilo Contributor

Hi All,

 

I was able to figure out this issue. When you send the submit_order curl code,  you must include the --data param with only the requested_for value as below:

 

curl -u username:password -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" --data '{"requested_for":"sysid"}' https://test.service-now.com/api/sn_sc/v1/servicecatalog/cart/submit_order