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

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)

Related

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

Postman is seemingly ignoring my POST in the pre-request

I am trying to set up a DELETE call, but to do this I first need to create the data to delete so I am trying to call a POST in the pre-request. I have run the POST as a normal request and it works fine, but inside the pre-request it just seems to be getting ignored. I know this because I can alter the URL to something that should not work and it makes no difference and raises no errors.
This is what I have in my pre-request: -
pm.sendRequest({
url: "http://someurl/test",
method: 'POST',
header: {
'Authorization': 'Basic Tmlfefe89899eI='
},
body: {
"ClientId": 594,
"Name": null,
"Disabled": false
}, function (err, res) {
console.log(res);
}
});
Is there anything special I have to do to use a POST as a pre-request?
Any help would be greatly appreciated.
Seems strange that nothing is happening, might be returning a 400 but you're only going to see that in the Postman Console.
You can open this by hitting this icon, you'll find it in the bottom left of the app:
This is an example view from the Console, the icon next to the timing on the first request will show that a pm.sendRequest() function was used:
I would suggest just changing your request a little bit to something like the one below and it should be fine:
pm.sendRequest({
url: 'http://someurl/test',
method: 'POST',
header: {
'Authorization': 'Basic Tmlfefe89899eI=',
'Content-Type': 'application/json'
},
body: {
mode: 'raw',
raw: JSON.stringify({ ClientId: 594, Name: null, Disabled: false})
}
}, function (err, res) {
console.log(res);
});
There is a trick to get request information for the pre-request script.
Save the request in a separate collocation (temporary) and export that collection. And then check that json collection using IDE or notepad, you'll get all the information there, use that as it is for your request.
Using given information in the question, here is how your pre-request script looks like,
pm.sendRequest({
url: "http://someurl/test",
method: "POST",
header: [{
"key": "Authorization",
"value": "Basic Tmlfefe89899eI=",
"type": "text",
},
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}],
body: {
mode: 'raw',
"raw": ""raw": "{\n \"ClientId\": 594,\n \"Name\": null,\n \"Disabled\": false\n}"
}
}, function(err, res) {
console.log(res);
});
Also check Postman console, you'll get all the information there, including request, response and errors if any.

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)

Searching in ElasticSearch using Get Request

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.

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