I am trying to send a message to slack from Scala using CURL command. It gives error invalid payload
val slackurl = "https://hooks.slack.com/services/<something here>
val cmd = Seq(
"curl",
"-d",
"testdata",
"-H",
"Content-Type: application/x-www-form-urlencoded",
"-X",
"POST",
slackurl
)
cmd.!
i am getting the error "invalid_payload"
or
val cmd = Seq(
"curl",
"-d",
s"#$testData",
"-H",
"Content-Type: application/x-www-form-urlencoded",
"-X",
"POST",
slackurl
)
when I am trying to send some data, the error is : "cant read from the file"
i used the following: Runtime.getRuntime.exec( Array[String]( "curl", "-X", "POST", "-H", "Content-type: application/json", "--data", actData, slackurl ) ) Its working for me now. [space issue in CURL with Runtime
But when i send the a json to slack, message was displayed as "Array".
Related
I wanted to create a REST service in XQuery who are able to receive zip file with documents.
I try to use the API REST extension, but the input is a document-node and is unable to receive zip file.
Is there a way to do that?
I have to receive a very big number of files, and I want to zip them by 1000 documents to limit the network time.
I use ml-gradle to create my database services
I do an other try :
XQ :
declare function he.insertMedia:put(
$context as map:map,
$params as map:map,
$input as document-node()*
) as document-node()?
{
let $id := map:get($params,"id")
let $uri := map:get($params,'uri')
return ( xdmp:document-insert($uri,$input),
document { <ok/> }
)
};
CURL call :
curl --location --request PUT 'http://localhost:8175/LATEST/resources/he.insertMedia?rs:id=TestMarc&rs:uri=/test/testMarc' \
--header 'Content-type: application/xslt+xml' \
--data-binary '#/D:/Travail/3-1-ELS/cep-lss-octo-exampledata/DATA/ACTUEL_ARTICLE/media/000_1wy606.jpg'
Result :
{
"errorResponse": {
"statusCode": 400,
"status": "Bad Request",
"messageCode": "XDMP-DOCUTF8SEQ",
"message": "XDMP-DOCUTF8SEQ: xdmp:get-request-body() -- Invalid UTF-8 escape sequence at line 1 -- document is not UTF-8 encoded"
}
}
ML version : 10.0-6.1
You send binary but tells the server it is XML (XSLT as XML.) Try the following in cURL:
Content-Type: application/octet-stream
I am trying to run Kafka workers in distributed mode. Unlike standalone mode, we cannot pass the connector property file while starting the worker in distributed mode. In Distributed mode, workers are started separately and we deploy and manage the connectors on those workers using REST API
Reference Link - https://docs.confluent.io/current/connect/managing/configuring.html#connect-managing-distributed-mode
I tried building a connector by passing the below values in curl command and execued it
curl -X POST -H "Content-Type: application/json" --data '{"name":"sailpointdb","connector.class":"io.confluent.connect.jdbc.JdbcSourceConnector","tasks.max":"1","connection.password " : " abc","connection.url " : "jdbc:mysql://localhost:3306/db","connection.user " : "abc" ,"query" : " SELECT * FROM (SELECT NAME, FROM_UNIXTIME(completed/1000) AS
TASKFAILEDON FROM abc WHERE COMPLETION_STATUS = 'Error') as A","mode" : " timestamp","timestamp.column.name" : "TASKFAILEDON","topic.prefix" : "dbevents","validate.non.null" : "false" }}' http://localhost:8089/connectors/
I am getting below error - curl: (3) URL using bad/illegal format or missing URL
Please let me know what is wrong with the above curl statement, am i missing anything here
You had an extra closing curly brace in your JSON which won't help
If you're POSTing to /connectors you need the name and config root level elements. But, I recommend using PUT /config because you can re-run it to update the config if you need to
Try this:
curl -X PUT -H "Content-Type:application/json" \
http://localhost:8089/connectors/source-jdbc-sailpointdb-00/config \
-d '{
"connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
"tasks.max": "1",
"connection.password ": " abc",
"connection.url ": "jdbc:mysql://localhost:3306/db",
"connection.user ": "abc",
"query": " SELECT * FROM (SELECT NAME, FROM_UNIXTIME(completed/1000) AS TASKFAILEDON FROM abc WHERE COMPLETION_STATUS = 'Error') as A",
"mode": " timestamp",
"timestamp.column.name": "TASKFAILEDON",
"topic.prefix": "dbevents",
"validate.non.null": "false"
}'
Need Equivalent gatling scala code from postman curl url
could you please just logically write a equivalent gatling scala code for below authentication request,first thing first is i need to get a auth request and its response using gatling scala .Below is the authentication curl request in PostMan which is working fine,i mean giving 201 response ,but i am getting 400 response in Gatling using git url github
Generated from a curl request:
curl 'https://api.platform.com/auth/oauth/token' -H 'Accept: application/json, text/plain, */*' -H 'Referer: https://api-origin.cloud/dev/reservations-web/signin' -H 'Origin: https://api.origin.cloud' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' -H 'Authorization: Basic aWtyd3VnaDM4NzFnaHc4cmduN3E4M2c2c3I=' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'grant_type=password&username=abc.xyc1%40abc.com&password=Password1%21' --compressed
Below is the scala equivalent code i tried generating but getting 400 response
package simulations
import baseConfig.BaseSimulation
import io.gatling.core.Predef._
import io.gatling.core.session
import io.gatling.http.Predef._
import scala.concurrent.duration.DurationInt
import scala.util.Random
class ogrebattledriverPostAccessToken extends BaseSimulation {
exec(
http("HTTP Request auth")
.post("https://api.platform.com/auth/oauth/token")
.header("Content-Type","application/x-www-form-urlencoded")
.formParam("grant_type","password")
.formParam("username", "TableTopEng%40xxxs.com")
.formParam("password", "actual password")
.check(status is 200)
.check(jsonPath("$.access_token").saveAs("access_token"))
.check(jsonPath("$.token_type").saveAs("token_type"))
)
//val PostData=jsonFile("input-json.json").circular
def name() = Random.nextInt(Integer.MAX_VALUE).toString
//val headers_10 = Map("Content-Type" -> """application/json""","Authorization","${token_type} + ${access_token}" )
def getSpecificOgreID()={
repeat(140000){
exec(flushHttpCache)
feed(usersDataSource)
.exec(http("PostRequestPerformanceTestingOgreBattleDriver")
.post("https://api.tabletop-stage.tiamat-origin.cloud/dev/ogre-battledriver/Organizations")
// .headers(headers_10)
.header("Authorization", "${token_type} + ${access_token}")
.body(StringBody(session =>
s"""
|{
| "name": "${name()}",
| "latitude": 66.256538,
| "longitude": -95.934502,
| "phoneNumber": "555-555-5555",
| "emailAddress": "perftest1#perftest1.com",
| "website": "https://perftest1",
| "streetLine1": "123 perftest1.",
| "streetLine2": "Ste 400",
| "city": "Omaha",
| "state": "NE",
| "zipCode": "98002"
|}
""".stripMargin)).asJSON
.check(status.in(200,201))//checkforaspecificstatus
.check(jsonPath(path="$.name").saveAs(key="name")))//checkforaspecificstatus
.exec{session=>println(session);session}//parameterfortheorgIdgoeshere
.pause(1)
}
}
// add a scenario
val scn = scenario("Battle Driver Get Orgs ")
.forever() { // add in the forever() method - users now loop forever
exec(getSpecificOgreID())
}
Error i am getting in Intellij Editor
20:22:56.563 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'access_token' is defined
Can someone please write a logical gatling scala code from above postman curl request??
I am able to build a Jenkins job with its parameters' default values by sending a POST call to
http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters
and I can override the default parameters "product", "suites" and "markers by sending to this URL:
http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=ALL&suites=ALL&markers=ALL
But I saw examples were the parameters can be override by sending a JSON body with new values. I am trying to do that by sending the following json bodies. Neither of them works for me.
{
'product': 'ALL',
'suites': 'ALL',
'markers': 'ALL'
}
and
{
"parameter": [
{
"name": "product",
"value": "ALL"
},
{
"name": "suites",
"value": "ALL"
},
{
"name": "markers",
"value": "ALL"
}
]
}
What JSON to send if I want to override the values of parameters "product", "suites" & "markers"?
I'll leave the original question as is and elaborate here on the various API calls to trigger parameterized builds. These are the calls options that I used.
Additional documentation: https://wiki.jenkins.io/display/JENKINS/Remote+access+API
The job contains 3 parameters named: product, suites, markers
Send the parameters as URL query parameters to /buildWithParameters:
http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=ALL&suites=ALL&markers=ALL
Send the parameters as JSON data\payload to /build:
http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build
The JSON data\payload is not sent as the call's json_body (which is what confused me), but rater in the data payload as:
json:'{
"parameter": [
{"name":"product", "value":"123"},
{"name":"suites", "value":"high"},
{"name":"markers", "value":"Hello"}
]
}'
And here are the CURL commands for each of the above calls:
curl -X POST -H "Jenkins-Crumb:2e11fc9...0ed4883a14a" http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build --user "raameeil:228366f31...f655eb82058ad12d" --form json='{"parameter": [{"name":"product", "value":"123"}, {"name":"suites", "value":"high"}, {"name":"markers", "value":"Hello"}]}'
curl -X POST \
'http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=234&suites=333&markers=555' \
-H 'authorization: Basic c2hsb21pb...ODRlNjU1ZWI4MjAyOGFkMTJk' \
-H 'cache-control: no-cache' \
-H 'jenkins-crumb: 0bed4c7...9031c735a' \
-H 'postman-token: 0fb2ef51-...-...-...-6430e9263c3b'
What to send to Python's requests
In order to send the above calls in Python you will need to pass:
headers = jenkins-crumb
auth = tuple of your (user_name, user_auth_token)
data = dictionary type { 'json' : json string of {"parameter":[....]} }
curl -v POST http://user:token#host:port/job/my-job/build --data-urlencode json='{"parameter": [{"name":"xx", "value":"xxx"}]}
or use Python request:
import requests
import json
url = " http://user:token#host:port/job/my-job/build "
pyload = {"parameter": [
{"name":"xx", "value":"xxx"},
]}
data = {'json': json.dumps(pyload)}
rep = requests.post(url, data)
I am trying to execute the curl command through scala for scalatest,
CURL :
curl -H "Content-Type: application/json" --data #/home/examples/demo/demo.json http://localhost:9090/job
which works aas expected while I tried doing it with scala ,like
import scala.sys.process._
val json = getClass.getClassLoader.getResource(arg0).getPath
val cmd = Seq("curl", "-H", "'Content-Type: application/json'","-d", s"#$json","http://localhost:9090/job")
cmd.!
and it produces following error
Expected 'application/json'
You're quoting too much:
Seq("curl", "-H", "'Content-Type: application/json'","-d", s"#$json","http://localhost:9090/job")
// !^! !^!
Should be:
Seq("curl", "-H", "Content-Type: application/json", "-d", s"#$json","http://localhost:9090/job")
// ! !
The reason you need to quote the content-type in the shell is because the shell will break it up if it isn't quoted. Curl doesn't know how to deal with quotes, because quotes aren't its business. Scala won't do any word-splitting, either, because that's your job.