Searching in ElasticSearch using Get Request - amazon-web-services

I am trying to search for documents in ElasticSearch .
I want to pass the query string as JSON . I am unable to do that.
How can I do that?
I want to pass this JSON request body in my search request.
{"query": {
"bool": {
"must": [
{ "match": { "last_name": "Doe" }}
]
}
}}

In order to send a request, you would need to define the header as application/json and send a POST/GET request to _search endpoint. Below is a sample CURL request for reference which can be run in the terminal.
curl -X POST -H "Content-Type: application/json" -d '{"query": {"bool": { "must": [{ "match": { "last_name":"Doe" }}]}}}' "http://localhost:9200/index_name/_search"
Link for reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html
Hope it helps.

Related

Using google app script to send a message with my PMS's API

Im using google app script to hopefully sent a message to my guests using my PMS (Smoobu). I think I have an issue with my syntax.
var smoobuPostOptions = {
"method": 'post',
"muteHttpExceptions": false,
"headers": {
"Api-Key": "???????????????????????????????????",
"cache-control": "no-cache",
"ContentType": "application/json",
},
"data": {
"subject": "Test Subject",
"messageBody": "Test Message"
}
}
var txTresponse = UrlFetchApp.fetch("https://login.smoobu.com/api/reservations/31418467/messages/send-message-to-guest", smoobuPostOptions);
var txtData = JSON.parse(txTresponse.getContentText());
The error I am getting is:
Exception: Request failed for https://login.smoobu.com returned code 500. Truncated server response: {"status":500,"title":"Internal Server Error","detail":"Zend\Form\Form::setData expects an array or Traversable argument; received "NULL""} (use muteHttpExceptions option to examine full response)
API Docs - https://docs.smoobu.com/#send-message-to-guest
I do believe I just need an example and I will be able to work it out!
From your provided document, it seems that you wanted to convert the following curl command to Google Apps Script.
curl -X POST \
'https://login.smoobu.com/api/reservations/1/messages/send-message-to-guest' \
-H 'Api-Key: secretApiKey' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{"subject" : "Test subject","messageBody" : "test"}'
In this case, how about the following modification?
From:
var smoobuPostOptions = {
"method": 'post',
"muteHttpExceptions": false,
"headers": {
"Api-Key": "???????????????????????????????????",
"cache-control": "no-cache",
"ContentType": "application/json",
},
"data": {
"subject": "Test Subject",
"messageBody": "Test Message"
}
}
To:
var smoobuPostOptions = {
"method": 'post',
"headers": {
"Api-Key": "???????????????????????????????????",
"cache-control": "no-cache",
},
"contentType": "application/json",
"payload": JSON.stringify({
"subject": "Test Subject",
"messageBody": "Test Message"
})
};
Note:
I think that the request of the above-modified script is the same as the sample curl command. But, if an error occurs, please confirm your endpoint, "Api-Key" and the request body again.
Reference:
fetch(url, params)

wso2 is Redirect to client application login page after user clicks on account confirmation email link

I'm trying to redirect to client application login page when the user clicks on the Account Confirmation email link. The URL which i'm redirecting to is
https:///accountrecoveryendpoint/confirmregistration.do?confirmation=54166133-0e00-463a-9ecf-ce26b516190a&userstoredomain=USERS&username=user#xyz.com&tenantdomain=carbon.super&callback=http://(applicationdomain)/context/openid-connect/wso2_oauth
but actually i should be able to get the client id and state parameters in the email link.but these values are missing. Any help would be appreciated
If you are trying to invoke account confirmation using the default identity server UIs, you won't be able to send any additional query parameters in the email because the OOTB UIs does not support sending additional request parameters. Identity server UIs are designed to cater a specific userstories. But this can be easily done using customization.
Example: If you are trying self-registering using the REST API, instead of the default self-registration page, you can do this easily by making a small change to the request. Sample API request as follows. Note here that I have added a custom param to the request.
curl -L -X POST 'https://localhost:9443/api/identity/user/v1.0/me' -H 'Authorization: Basic YWRtaW46YWRtaW4=' -H 'Content-Type: application/json' --data-raw '{
"user": {
"username": "sominda",
"realm": "PRIMARY",
"password": "sominda!",
"claims": [
{
"uri": "http://wso2.org/claims/givenname",
"value": "sominda"
},
{
"uri": "http://wso2.org/claims/emailaddress",
"value": "user1#gmail.com"
},
{
"uri": "http://wso2.org/claims/lastname",
"value": "gamage"
}
]
},
"properties": [
{
"key": "callback",
"value": "<url_here>"
},
{
"key": "custom-param",
"value": "templated-custom-param"
}
]
}'
If you are making the above request, then you can edit the AccountConfirmation email template to have the above custom-param templated.
{{carbon.product-url}}/accountrecoveryendpoint/confirmregistration.do?confirmation={{confirmation-code}}&userstoredomain={{userstore-domain}}&username={{url:user-name}}&tenantdomain={{tenant-domain}}&callback={{callback}}&{{custom-param}}
Also, you can customize the existing self-registration page to send the above request (but I think this involves a little effort).

Create issue API for jira giving 404 from postman

I am trying to call jira rest API from postman for creating a issue
Follwing is my curl from postman
url --location --request POST 'https ://mydomain.com/jira/rest/api/2/issue' \
--header 'Authorization: Basic XXXXXXXX' \
--header 'Accept: application/json' \
--data-raw '{
"fields": {
"project": {
"id": "12019"
},
"issuetype": {
"id": "10002"
},
"customfield_12404" : {
"id": "12444"
},
"customfield_12394" : {
"id": "12421"
},
"summary": "Test of rest API",
"customfield_12391" : 1,
"customfield_11143": "test"
}
}'
I am getting bad request in response
<body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
I am not sure what is wrong in this. I tried searching on this but did not get proper solution for my issue Can anyone help me on this ?
Thanks

Flink rest api error: Request did not match expected format JarRunRequestBody

Trying to run a flink job remotely using the below rest api but its throwing error
curl -X POST -H 'Content-Type: application/json' --data '
{
"type": "object",
"id": "urn:jsonschema:org:apache:flink:runtime:webmonitor:handlers:JarRunRequestBody",
"properties": {
"programArgsList" : {
"type" : "array",
"items" : [
"input-kafka-server": "****",
"input-kafka-topics": "****",
"input-job-name": "****"
}
}
}
' http://x.x.x.x:8081/jars/810ac968-5d5f-450d-aafc-22655238d617.jar/run
{"errors":["Request did not match expected format JarRunRequestBody."]}
The description of the request body for the jar run handler you find here is the JSON schema specification of the jar run message. What you need to specify in your request are only the properties and not the "type" and "id" fields. Thus, your request should look like:
curl -X POST -H 'Content-Type: application/json' --data '
{
"programArgsList" : [
"--input-kafka-server",
"value-input-kafka-server",
"--input-kafka-topics",
"value-kafka-topics",
"--input-job-name",
"value-job-name"
],
"parallelism": 30
}
' http://x.x.x.x:8081/jars/810ac968-5d5f-450d-aafc-22655238d617.jar/run
If anyone is looking for Python code to submit Flink job through REST API.
import json
url = base_url + "/jars/" + jar_id + "/run"
myheader = {'content-type': 'application/json'}
mydata = {
"programArgsList": [
"--input-kafka-server", "value-input-kafka-server",
"--input-kafka-topics", "value-kafka-topics",
"--input-job-name","value-job-name"
],
"parallelism": 30
}
x = requests.post(url, data=json.dumps(mydata), headers=myheader)

Keystone v3 auth error

I am following keystone ocata installation guide https://docs.openstack.org/ocata/install-guide-ubuntu/keystone-install.html
Post installation, I am able to get the user list using openstack user list command.
openstack --os-auth-url="[keystone_url]" --os-identity-api-version="3" --os-password="mypwd123" --os-project-domain-name="Default" --os-project-name="admin" --os-username="admin" --os-user-domain-name="Default" user list
Outputs the User list properly.
But when I take auth token with below command :
curl -si -d '{"auth": {"identity": {"methods": ["password" ],"password": {"user": {"domain": {"id": "default" },"name": "admin","password": "mypwd123" }}}}}' -H "Content-type: application/json" [keystone_url]/v3/auth/tokens
and then use the token from the output of above command in below command to list the users:
curl -s -H "X-Auth-Token: gAAAAABZlAN0NPibgBLcUW3aAcgNYIGaRH98M7w6b4tRliXC4LQB4dr5cGxTJmF5-iKvY2U_AU3c71uJUqgaQJP-iyURCBzBqYHlHtTGqofzzVndVncBRU5z4iLbArBdbJCI2Wd-1No9C0cq4iWB6RBNa9wqXWm-Gw" "[keystone_url]/v3/users" | python -mjson.tool
Returns :
{
"error": {
"code": 403,
"message": "You are not authorized to perform the requested action: identity:list_users.",
"title": "Forbidden"
}
}
Any help would be appreciated.
Thanks,
Viral
because list users need token with scopeļ¼Œ you should add scope for query, like this:
curl -i http://ip:5000/v3/auth/tokens -H "Content-
Type: application/json" -d '
{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "admin",
"domain": {
"name": "Default"
},
"password": "secret"
}
}
},
"scope": {
"domain": {
"id": "default"
}
}
}
}'
then use X-Subject-Token to query users.
See the official documentation for details.https://docs.openstack.org/keystone/pike/api_curl_examples.html#tokens