{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1295,"path":"api-reference/web-services/r_DirectRESTMessageV2Example.md","title":"Direct RESTMessageV2 example","bundle":null,"doc_type":null,"release":"australia","body":"\n# Direct RESTMessageV2 example\n\nYou can send an outbound REST message directly to the endpoint.\n\nIn this example, the script sends a REST message requesting a stock quote and waits for a response. If there is no response from the web service provider, or if the specified REST message record is unavailable, the script throws an error, handled in this example by the try-catch block.\n\n```\nvar requestBody;\nvar responseBody;\nvar status;\nvar sm;\ntry{\n\tsm = new sn_ws.RESTMessageV2(\"Yahoo Finance\", \"get\");  // Might throw exception if message doesn't exist or not visible due to scope.\n\tsm.setBasicAuth(\"admin\",\"admin\");\n\tsm.setStringParameter(\"symbol\", \"NOW\");\n\tsm.setStringParameterNoEscape(\"xml_data\",\"<data>test</data>\");\n\tsm.setHttpTimeout(10000); //In milliseconds. Wait at most 10 seconds for response from http request.\n\n\tresponse = sm.execute();//Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.\n\tresponseBody = response.haveError() ? response.getErrorMessage() : response.getBody();\n\tstatus = response.getStatusCode();\n} catch(ex) {\n\tresponseBody = ex.getMessage();\n\tstatus = '500';\n} finally {\n\trequestBody = sm ? sm.getRequestBody():null;\n}\ngs.info(\"Request Body: \" + requestBody);\ngs.info(\"Response: \" + responseBody);\ngs.info(\"HTTP Status: \" + status);\n```\n\n**Parent Topic:**[Scripting outbound REST](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/web-services/c_ScriptingOutboundREST.md)\n\n"}}