Get request headers at doGet() - google-apps-script

I want to get the request header when I requested to doGet(). I deployed Web Apps like below.
Condition of Web Apps is
Execute the app as: is "me".
Who has access to the app: is "Anyone, even anonymous".
doGet() is
function doGet(e) {
console.log(e)
}
e is
{
"parameter": {
"key": "value"
},
"contextPath": "",
"contentLength": -1,
"queryString": "key=value",
"parameters": {
"key": [
"value"
]
}
}
e doesn't include the request header. I read here. But there are no information to get it. Perhaps there are no official methods to do. So I am looking for the workarounds. Are there workarounds to get the header?
Thank you so much for your time. And I'm sorry for my immature question.

Related

Webhook event not received from Autodesk Forge API

I'm using the Autodesk Forge API to convert a range of models from various formats into SVF files, and trying to use the Webhooks API to listen for transformation complete events for jobs posted to the Model Derivative service.
I have successfully created the webhook, and verified its existence by calling the get Hooks API endpoint. Below is the basic response i receive.
{
"hookId": "<my-hook-id>",
"tenant": "<my tennant>",
"callbackUrl": "<ngrok url>",
"createdBy": "...",
"event": "extraction.finished",
"createdDate": "2020-11-05T05:48:39.016+0000",
"system": "derivative",
"creatorType": "Application",
"status": "active",
"scope": {
"workflow": "<my-workflow-key>"
},
"urn": "<webhook-urn>",
"__self__": "..."
}
At my ngrok endpoint I have a basic Node ExpressJS server running. The server is set to respond to all methods across my designated callback url. I have also verfied my callback url is valid and active through postman, with POST request being successfully received and returning a valid 2XX reponse.
I then post a translation job like below to the Model Derivative API, and the job successfully starts and processes the job. I can verify this by manually calling to check the status of a job through the Model Derivative API, however my webhook callback endpoint never receives any notification of transformation completion event.
{
"input": {
"urn": "<Input Urn>"
},
"output": {
"destination": {
"region": "us"
},
"formats": [
{
"type": "svf",
"views": ["3d"]
}
],
"misc": {
"wokflow": "<my-workflow-key>"
}
}
}
Is there anything obvious that I might be missing as to why the webhook event never seems to be triggered, or any other way that I could see if the webhook event was even attempted to be fired from Autodesks/Forges side?
There seems to be a typo in the job payload: wokflow should be workflow.
Note that you can also test incoming webhook requests using online tools such as https://webhook.site.

How to call stored painless script function in elastisearch

I am trying to use an example from
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/modules-scripting-using.html
I have created a function and saved it.
POST http://localhost:9200/_scripts/calculate-score
{
"script": {
"lang": "painless",
"source": "ctx._source.added + params.my_modifier"
}
}
Try to call saved function
POST http://localhost:9200/users/user/_search
{
"query": {
"script": {
"script": {
"id": "calculate-score",
"params": {
"my_modifier": 2
}
}
}
}
}
And it returns an error: Variable [ctx] is not defined. I tried to use doc['added'] but received the same error. Please help me understand how to call the function.
You should try using doc['added'].value, let me explain you why and how. In short, because painless scripting language is rather simple but obscure.
Why can't ES find ctx variable?
The reason it cannot find ctx variable is because this painless script runs in "filter context" and such variable is not available in filter context. (If you are curious, there were 18 types of painless context as of ES 6.4).
In filter context there are only two variables available:
params (Map, read-only)
User-defined parameters passed in as part of the query.
doc (Map, read-only)
Contains the fields of the current document where each field is a List of values.
It should be enough to use doc['added'].value in your case:
POST /_scripts/calculate-score
{
"script": {
"lang": "painless",
"source": "doc['added'].value + params.my_modifier"
}
}
Should, because there will be another problem if we try to execute it (exactly like you did):
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['added'].value + params.my_modifier",
"^---- HERE"
],
"script": "calculate-score",
"lang": "painless",
"caused_by": {
"type": "class_cast_exception",
"reason": "cannot cast def [long] to boolean"
}
Because of its context, this script is expected to return a boolean:
Return
boolean
Return true if the current document should be returned as a
result of the query, and false otherwise.
At this point we can understand why the script you were trying to execute did not make much sense for Elasticsearch: it is supposed to tell if a document matches a script query or not. If a script returns an integer, Elasticsearch wouldn't know if it is true or false.
How to make a stored script work in filter context?
As an example we can use the following script:
POST /_scripts/calculate-score1
{
"script": {
"lang": "painless",
"source": "doc['added'].value > params.my_modifier"
}
}
Now we can access the script:
POST /users/user/_search
{
"query": {
"script": {
"script": {
"id": "calculate-score1",
"params": {
"my_modifier": 2
}
}
}
}
}
And it will return all documents where added is greater than 2:
"hits": [
{
"_index": "users",
"_type": "user",
"_id": "1",
"_score": 1,
"_source": {
"name": "John Doe",
"added": 40
}
}
]
This time the script returned a boolean and Elasticsearch managed to use it.
If you are curious, range query can do the same job, without scripting.
Why do I have to put .value after doc['added']?
If you try to access doc['added'] directly you may notice that the error message is different:
POST /_scripts/calculate-score
{
"script": {
"lang": "painless",
"source": "doc['added'] + params.my_modifier"
}
}
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['added'] + params.my_modifier",
" ^---- HERE"
],
"script": "calculate-score",
"lang": "painless",
"caused_by": {
"type": "class_cast_exception",
"reason": "Cannot apply [+] operation to types [org.elasticsearch.index.fielddata.ScriptDocValues.Longs] and [java.lang.Integer]."
}
Once again painless shows us its obscurity: when accessing the field 'added' of the document, we obtain an instance of org.elasticsearch.index.fielddata.ScriptDocValues.Longs, which Java Virtual Machine denies to add to an integer (we can't blame Java here).
So we have to actually call .getValue() method, which, translated in painless, is simply .value.
What if I want to change that field in a document?
What if you want to add 2 to field added of some document, and save the updated document? Update API can do this.
It operates in update context, which actually has got ctx variable defined, which in turn has access to the original JSON document via ctx['_source'].
We might create a new script:
POST /_scripts/add-some
{
"script": {
"lang": "painless",
"source": "ctx['_source']['added'] += params.my_modifier"
}
}
Now we can use it:
POST /users/user/1/_update
{
"script" : {
"id": "add-some",
"params" : {
"my_modifier" : 2
}
}
}
Why the example from the documentation doesn't work?
Apparently, because it is wrong. This script (from this documentation page):
POST _scripts/calculate-score
{
"script": {
"lang": "painless",
"source": "Math.log(_score * 2) + params.my_modifier"
}
}
is later executed in filter context (in a search request, in a script query), and, as we now know, there is no _score variable available.
This script would kind of make sense only in score context, when running a funtion_score query which allows to twiggle the relevance score of the documents.
Final note
I would like to mention that in general, it's recommended to avoid using scripts because their performance is poor.

{fault.name} - The client_id specified does not have access to the api product

I'm following this tutorial :
https://developer.autodesk.com/en/docs/model-derivative/v2/tutorials/prepare-file-for-viewer/
In previous steps, I get the token, get a token for bucket, create one and upload a file in it.
But, when I try, on the next step, to convert my file to svg, I get this message :
{fault.name} - The client_id specified does not have access to the api product
In Postman, I've do that :
POST https://developer.api.autodesk.com/modelderivative/v2/designdata/job
-- Header
Content-Type:application/json
Authorization:Bearer eyJhbGciOiJIUzI1...
-- Body
{
"input": {
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZGV2c3RlZWxidWNrZXQvc2t5c2NwcjEuXXXX"
},
"output": {
"formats": [
{
"type": "svf",
"views": [
"2d",
"3d"
]
}
]
}
}
And I do not find any solution in Google.
You need to activate your account.
If you face same issue even after activating your account, another possibility could be-
you might have missed "Model derivative API" while creating forge APP.

Parse Dynamic Property name in Azure Logic App

I have been playing around with Azure Logic Apps and trying to retrieve a Pocket (ReadItLater) article so that I can create a new task in my preferred Task Manager. I have Two HTTP Connectors (one for Retrieve Operation using Pocket API and another post data to Todoist (my preferred task manager).
I can retrieve the Article and the response looks like (removed a few properties below for easy reading):
{
"statusCode": 200,
"headers": {
"pragma": "no-cache",
"status": "200 OK"
},
"body": {
"status": 1,
"complete": 1,
"list": {
"586327616": {
"item_id": "586327616",
"resolved_id": "586327616",
"given_url": "http://kenwheeler.github.io/slick/?utm_source=hackernewsletter&utm_medium=email&utm_term=design&mc_cid=58c9499fa2&mc_eid=3aaf6c4e47",
"given_title": "slick - the last carousel you'll ever need",
"time_added": "1396652224",
"time_updated": "1405156517",
"resolved_title": "slick",
"resolved_url": "http://kenwheeler.github.io/slick/?utm_source=hackernewsletter&utm_medium=email&utm_term=design&mc_cid=58c9499fa2&mc_eid=3aaf6c4e47",
"excerpt": "Add slick.js before your closing <body> tag, after jQuery (requires jQuery 1.7 +) <script type=\"text/javascript\" src=\"slick/slick.min.",
"word_count": "22"
}
}
}
}
Now I want to parse the above response to retrieve individual article properties (i.e. resolved_title). The issue here is the object under the list "586327616" is dynamic and changes for every article, and I can't seem to parse this as an expression in Logic App. My current action in Logic App looks like:
"postToTodoist": {
"conditions": [
{
"expression": "#equals(outputs('getPocketArticles')['statusCode'], 200)"
},
{
"dependsOn": "getPocketArticles"
}
],
"inputs": {
"body": "#{outputs('getPocketArticles')['body']['list'][0]['resolved_title']}",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"method": "POST",
"repeat": {},
"uri": "https://todoist.com/API/v6/add_item"
},
"type": "Http"
}
For the expression I have tried converting the response to string, using coalesce and trying to access using an index, but nothing seem to work. In the error, it tells me what that the available property is i.e.:
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'postToTodoist' inputs at line '1' and column '11': 'The template language expression 'coalesce(body('getPocketArticles')['list']).resolved_title' cannot be evaluated because property 'resolved_title' doesn't exist, available properties are '586327616'. Please see https://aka.ms/logicexpressions for usage details.'."}
I feel that it is not possible to construct an expression without knowing the name of the property, has anyone done something similar?

how can i post data using Mozilla rest add-on using mailgun api

I'm using this Mozilla ADD-ON to post the data in mailgun API
RestClient
Content-Type:application/json
URL I'm using
https://api.mailgun.net/v2/sandbox42924.mailgun.org/messages
Json Data I'm posting
[
{
"from": "Kaushik <kaushik#gmail.com>"
},
{
"to": "Kaushik <kaushikfb1#gmail.com>"
},
{
"subject": "Hello This is test mail"
},
{
"text": "Testing some Mailgun !"
},
{
"html": "<html>Hello These <h2>contents belongs</h2> to html content</html>"
}
]
OR
{
"from": "Kaushik <kaushik#gmail.com>",
"to": "Kaushik <kaushikfb1#gmail.com>",
"subject": "Hello This is test mail",
"text": "Testing some Mailgun !",
"html": "<html>Hello These <h2>contents belongs</h2> to html content</html>"
}
In both cases what I'm getting is
{
"message": "'from' parameter is missing"
}
I want to know how i can post the data.
In documentation they have not describe this process.
I'm curious to know how it is working?
Here is the link for the documentation Click Here. They are using library for using in each language. If you know the library in detail you can help.
Finally I found the answer of this so for the sake of other user so they may find a help from this post in future I'm submitting the answer.
the url is this one.
https://api.mailgun.net/v2/yourdoamin.com/messages
username = api
password = {your key}
Now after that set your content type:application/x-www-form-urlencoded.
Now post the data. for formatting the data you can use this link Click Here
Demo data format
from%3D%27Excited%20User%20%3Cme%40yourdoamin.com%3E%27%20%5C%0A%20%20%20%20%20to%3Dbaz%40example.com%5C%0A%20%20%20%20%20to%3Dbar%40example.com%20%5C%0A%20%20%20%20subject%3D%27Hello%27%20%5C%0A%20%20%20%20text%3D%27Testing%20some%20Mailgun%20awesomness!%27