Search the Community
Showing results for tags 'rest api'.
-
Have this following input parameter(Complex list of inputs) that need to be SEND as part of HTTP POST Request. Have been searching forums to find an AutoIT equivalent to enapsulate the following data, but unsuccessful. Below given Working Code is failing with 400-Bad Request for obvious reason of incomplete input - unable to send ip_list and other array type parameters Questions: 1. How to encapsulate the below given data for $oHttp.Send() 2. How to enapsulate special data types like null - aligned_device_tempate parameter White sapced values - () and empty array? - hostname or device_groups Input Parameter in JSON format to be converted & sent in AutoIT compatible { "name": "SnmpSIM", "description": "EM7 device created by BDD test case", "credentials":"{{feature.credential.body.result_set[*].URI}}", "organization": "/api/organization/0", "aligned_device_template": null, "aligned_collector": "{{feature.appliance_id[0].id[0]}}{{feature.appliance_id[0].id[1]}}", "discover_non_snmp": "1", "scan_ports": [ "21", "22", "23", "25", "80" ], "ip_lists": [ { "start_ip": "{{feature.json.ip}}", "end_ip": "{{feature.json.ip}}" } ], "dhcp_enabled": "0", "duplicate_protection": "1", "model_device": "1", "log_all": "1", "scan_all_ips": null, "port_scan_timeout": null, "initial_scan_level": null, "scan_throttle": null, "interface_inventory_timeout": "600000", "max_interface_inventory_count": "10000", "bypass_interface_inventory": "0", "hostnames": [], "device_groups": [] } Working Code ; The data to be sent $sPD = 'name=SnmpSIM&description=EM7 device created by BDD test case&credentials=37&organization=/api/organization/0&aligned_device_template=null&aligned_collector=1&discover_non_snmp=1&dhcp_enabled=0&duplicate_protection=1&model_device=1&log_all=1&scan_all_ips= null&port_scan_timeout= null&initial_scan_level= null&scan_throttle= null&interface_inventory_timeout=600000&max_interface_inventory_count=10000&bypass_interface_inventory=0&hostnames=&device_groups=&scan_ports=21' ; Creating the object $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "http://10.2.4.18/api/discovery_session", False) $oHTTP.SetCredentials("username","password",0) $oHTTP.SetRequestHeader("Content-Type", "application/em7-resource-uri") ; Performing the Request $oHTTP.Send($sPD) ; Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) FileClose($file) SAMPLE VBA CODE for Reference Dim Items As New Collection Dim Item As Dictionary Dim Id As Long For Id = 1 To 2 Set Item = New Dictionary Item("iditem") = Id Item("amount") = 1 Items.Add Item Next Id Request.AddBodyParameter "id", 5633 Request.AddBodyParameter "items", Items $oDictionary = ObjCreate("Scripting.Dictionary") $oDictionary.ADD("start_ip", "10.20.7.31") $oDictionary.ADD("end_ip", "10.20.7.33")
-
Hello, I'm in the making of a script that needs to post XML data through HTTPS to our ServiceDesk Plus MSP service. I'm running into trouble because I have never made any scripts using HTTP with POST and I cannot see what I'm doing wrong here. Can someone help me or should I find help somewhere else? $URLSDP="" ;REMOVED - cannot publish this. this is the HTTPS url to our ServiceDesk $TechnicianKey="" ;REMOVED $ID="" ; Request ID $sPostData = "OPERATION_NAME=ADD_NOTE&INPUT_DATA=<Operation><Details><Notes><Note><isPublic>false</isPublic><notesText>Text added to the note</notesText></Note></Notes></Details></Operation>&format=XML" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $URLSDP & "/sdpapi/request/"& $ID & "/note?TECHNICIAN_KEY="& $TechnicianKey, False) $oHTTP.SetRequestHeader("Content-Type", "xml") $oHTTP.Send($sPostData) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status ConsoleWrite($oStatusCode & @CRLF) ConsoleWrite($oReceived & @CRLF) If $oStatusCode = 200 Then ;Process the response $oReceived ;ConsoleWrite(@CRLF & "Response" & @CRLF & $oReceived & @CRLF) Else MsgBox(16, "Error " & $oStatusCode, $oReceived, 7) EndIf Response: <operation name="POST"><result><status>Failed</status><message>Invalid operation</message></result></operation>REST API guide. https://www.manageengine.com/products/service-desk-msp/help/adminguide/api/notes-operations.html#add
-
I'm trying t upload a file to dropbox using the dropbox RESTful API. In the last section on the page at http://cgeers.com/2012/03/11/dropbox-rest-api-part-5-file-upload/ , the author uses a method "GetRequestStream" Everything I've done so far with the dropbox API has utilised a winhttp object, with the structure below: $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $URL, false) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $authString = 'OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="'& $key & '", oauth_token="' & $accessToken & '", oauth_signature="' & $secret & '&' & $accessSecret & '"' $oHTTP.SetRequestHeader("Authorization",$authString) ; Performing the Request $oHTTP.Send() ; Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status Now I need a GetRequestStream() mehod, I'm not sure if there is a facility to do this. I've tried $oHTTP.GetRequestStream() but it just threw an error If anybody can offer some insight It would be a great help
-
- winhttphttp
- dropbox
-
(and 1 more)
Tagged with:
-
I've been trying all day to get a "request token" from the dropbox rest-api. Basically I'm trying to perform step 1 at https://www.dropbox.com/developers/blog/20/using-oauth-in-plaintext-mode: " 1. Make an API call for a request token: POST https://api.dropbox.com/1/oauth/request_token Your HTTP request should have the following header: Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="<app-key>", oauth_signature="<app-secret>&" The response body will be a url-encoded string: oauth_token=<request-token>&oauth_token_secret=<request-token-secret> Parse out the request token and secret and save them somewhere." I'm really struggling with how to send the header properly. Copying the example at http://brugbart.com/http-post-request-autoit, I have: ; The data to be sent $sPD = 'Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="h9y2pwy1nbvzy5e", oauth_signature="imrgkd8i80c2b8g&"' ; Creating the object $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://api.dropbox.com/1/oauth/request_token", False) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") ; Performing the Request $oHTTP.Send($sPD) ; Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) FileClose($file) I think my Authorisation string should be used in the "SetRequestHeader" function, but am worried about replacing the "content-type" already there as it looks important. If anybody can help it would be an enormous help