I have created a very basic Google Apps Script. Here is my doPost() and doGet():
function doPost(e) {
return respond(JSON.stringify({result: "Hello world!"}));
}
function doGet(e) {
return respond(JSON.stringify({result: "Hello world!"}));
}
function respond(response) {
return ContentService
.createTextOutput(response)
.setMimeType(ContentService.MimeType.JSON)
}
I have deployed the app with a new version. It is set to run as me but everyone can run it including anonymous.
I am testing the endpoint by running cURL from the command line, and for GET it works as expected:
Request -
curl -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
Response -
{"result":"Hello world!"}
But for POST:
Request -
curl -H "Content-Length: 0" -D "p=p" -X POST -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
Response -
Sorry, unable to open the file at this time.
Please check the address and try again.
As you can see from the command, I had to manipulate things a bit to get this far: including dummy data, adding a content-length header, and adding the -L flag to consume the redirect.
However, I am stuck. Why can't it "find the file"? Why does it think there is a file?
I suspect you'll need to send data.
This works (I got {"result":"POST request received!"}):
curl -H 'Content-Type: application/json' -d {} -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
As does this:
curl -d "" -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
Related
I am using a script that gives me some data in json format, I want to send this data to splunk.
I can store the output of the script in a file but how can I send it to HTTP Event Collector?
Couple of things I tried but did not work:
FILE="output.json"
file1="cat answer.txt"
curl -k "https://prd-pxxx.splunkcloud.com:8088/services/collector" -H "Authorization: Splunk XXXXX" -d '{"event": "$file1", "sourcetype": "manual"}'
-----------------------------------------------------------
curl -k "https://prd-pxxx.splunkcloud.com:8088/services/collector" -H "Authorization: Splunk XXXXX" -d '{"event": "#output.json", "sourcetype": "manual"}'
curl -k "https://prd-p-w0gjo.splunkcloud.com:8088/services/collector" -H "Authorization: Splunk d70b305e-01ef-490d-a6d8-b875d98e689b" -d '{"sourcetype":"_json", "event": "#output.json", "source": "output.json}
-----------------------------------------------------------------
After trying this I understand that it literally sends everything specified in the event section. Is there a way I can send the content of the file or use a variable?
Thanks in advance!
(Note - I haven't tried this specifically, but it should get you close)
According to Docs.Splunk on HTTP Event Collector Examples #3, it would seem you can do something very similar to this:
curl -k "https://mysplunkserver.example.com:8088/services/collector/raw?channel=00872DC6-AC83-4EDE-8AFE-8413C3825C4C&sourcetype=splunkd_access&index=main" \
-H "Authorization: Splunk CF179AE4-3C99-45F5-A7CC-3284AA91CF67" \
-d < $FILE
Presuming the content of the file is formatted correctly, it should go straight in.
How is the file being created? Is it in a Deployment App on a managed endpoint? If so, it will likely be simpler to setup a scripted input for the UF to run on whatever schedule you choose.
I need help because I'm not good with HTTP Requests.
I am trying to create a Release on my XL Release server with a HTTP request. Right now I'm doing it with Curl, in a batch file, like that
curl "https://{ID}:{password}#{IP}:{port}/api/v1/templates/Applications/Folder{IDFolder}/create" -i -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d %0\..\ReleaseConfig.json
The data file, which is in the same directory as the script, I'm calling is a json like that :
{ "releaseTitle" : "API Test", "releaseVariables" : { }, "releasePasswordVariables" : { }, "scheduledStartDate" : null, "autoStart" : false }
The problem is, I get an error like that while executing my command :
RESTEASY003065: Cannot consume content type
Do you have any idea what can help my case ?
Thanks
By looking at your filename, it seems that you are on Windows. I suspect you can't escape your Content-type with quote, you have to use double quotes.
Also, to pass a file as POST data, you have to use an #, like this:
curl "https://{ID}:{password}#{IP}:{port}/api/v1/templates/Applications/Folder{IDFolder}/create" -i -X POST -H "Content-Type:application/json" -H "Accept:application/json" -d #%0\..\ReleaseConfig.json
I need to write all the curl arguments in a separate file(myconfig.txt) to be executed and output for each different lines of command in output.txt, output1.txt, output2.txt...so on.
The webservices should be requested with post (multipart/form-data) method.
I am trying this command curl -K myconfig.txt -o output.txt
contents of
myconfig.txt include URL="http://1x2.2x1.x6.1x2:3000/latto/get_notifications"<option="to";mobile="+91999xx6xx3x"> into the output.txt - 'Cannot get /latto/get_notifications'. It seems like web-services are being requested as get method. Please anyone tell me the syntax to write in myconfig file. So that I can get the right output in file.
However, When I run this command sudo curl --form option="to" --form mobile="+9199999yyyxx" 1x2.2x1.x6.1x2:3000/latto/get_notifications, output is successfully printed in terminal.
When I do a curl -k config.txt with config.txt containing this:
URL="http://my.test.domain/index.php"
-d option="to"
-d mobile="+91999xx6xx3x"
I get the result:
POST
array(2) {
["option"]=>
string(4) ""to""
["mobile"]=>
string(15) "" 91999xx6xx3x""
}
So I don't known what you mean with <option ...> but when you put it into your config file as stated above, it should work.
Btw. here is the php script that answered:
<?php
echo $_SERVER['REQUEST_METHOD']."\n";
var_dump($_REQUEST);
?>
This webservice accepts request in POST method and enctype multipart/form-data
URL="http://my.test.domain/get_notifications"
-F option=to
-F mobile=+91999xx6xx3x
After a lot of hit and trial, I got this working: curl -k config.txt with config.txt containing the above.
I'm looking to this snippet of code:
curl -X GET 'https://api.newrelic.com/v2/applications/1622/metrics/data.json' \
-H 'X-Api-Key:30f4ec24a1f7dd9998a536b05840b17f7d42c7c1' -i \
-d 'names[]=EndUser&names[]=EndUser/Apdex&values[]=call_count&values[]=average_response_time&values[]=score&summarize=true'
from "Listing your app ID and metric data".
But curl's man page only talks about -d/--data in the context of POST requests, so, what's really happening here in terms of the HTTP request sent to the server?
-d with GET request just sends a query string, however the endpoint where data are sent must be set to consume application/x-www-form-urlencoded content type - have just checked that.
In general it's weird and I wouldn't implement it in such a way.
When such query is sent to java servlet - the body is accessible via.. getInputStream() method [sic!].
Using REST Server 6.x-2.0-beta3, I'm trying to understand how to post to user.save.
curl -d 'XX' -v http://localhost/services/rest/service_user/save
I've tried to replace XX with:
account{'name':'myname','pass':'mypassword','mail':'my#email.org'}
account = {'name':'myname','pass':'mypassword','mail':'my#email.org'}
account="name=myname,pass=mypassword,mail=myemail.org"
account=name=myname,pass=mypassword,mail=myemail.org
account=myname,mypassword,myemail.org
But none of these seems to be right and finding any documention regarding this is next to impossible.
I've also tried the following:
curl -H "Content-Type: application/json" -d 'account={"name":"myname","pass":"mypassword","email":"123"}' -v http://localhost/services/rest/service_user/save
The error I get in this case is:
HTTP/1.0 406 Not Acceptable: Missing required argument account
Hi I also just started working with this module and wondering how to create content using JSON.
Just been able to create a simple node using this:
Post URL: http://path-to-site/services/rest/node
Request Header: Content-Type: application/json
Request Body: {"type":"story","title":"REST Test","body":"REST using JSON"}
I think you're using the wrong URL
I figured it out:
curl -H “application/x-www-form-urlencoded” -d "sessid=xxxx" -d "account[name]=MyName&account[pass]=mypass&account[mail]=myemail#gmail.com&account[conf_mail]=myemail#gmail.com" -v http://path-to-site/services/rest/service_user/save
You only have to add -d "sessid=xxxx" if you have configured Services to require a session. Make sure in that case to replace xxxx with your actual session id (from system.connect).