I am trying to build a simple Logic App in Azure, that sends an email with a zip attachment using cURL from a Linux VM.
In the Logic App, without the attachment it is working fine.
But it breaks once Attachment is configured.
JSON schema, When a HTTP request is received:
{
"properties": {
"Attachments": {
"type": "array"
},
"cc": {
"type": "string"
},
"from": {
"type": "string"
},
"html": {
"type": "string"
},
"subject": {
"type": "string"
},
"to": {
"type": "string"
}
},
"type": "object"
}
Config for Outlook Send an email v2, Logic App, Azure
Commands to send email from Linux VM:
# create attachment
echo "abcd" > test.txt
zip test.zip test.txt
# curl to send json to azure logic app, with attachment
curl -vvv --request POST \
--header 'Content-Type: application/json' \
--url 'https://prod-21.southeastasia.logic.azure.com:443/workflows/xxx/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=xxx' \
--data '{"from": "xxx#outlook.com", "cc": "xxx#outlook.com, "Attachments": [{ "Content-Type": "BASE64_ENCODED_CONTENT", "Name": "test.zip" }], "to": "xxx#outlook.com", "subject": "Hello, World!", "html": "Hey, test email." }'
Error message from the Run History, Logic App, Azure
Full error from the log:
{
"status": 400,
"message": "Parameter 'Attachment Content' cannot be null or empty.\r\nclientRequestId: 40d2dc9c-549b-4608-xxxxxxxxxxxxxxx",
"error": {
"message": "Parameter 'Attachment Content' cannot be null or empty."
},
"source": "office365-sea.azconn-sea.p.azurewebsites.net"
}
Would like to know how to handle the attachment on this scenario. Any documentation would be helpful as well.
Thank you.
Would be also interested in this topic!
Did you try to use --form instead of --data? Or do you already have a solution for this?
I also tried to specify the "Attachments" property in logic apps as:
"properties": {
"Attachment": {
"contentEncoding": "base64",
"contentMediaType": "image/png",
"type": "string"
},
}
...
Related
My Dialogflow project is not making proper webhook calls. I ran the curl command, given to you while testing, in command prompt.
curl -H "Content-Type: application/json; charset=utf-8" -H "Authorization: Bearer ya29.c.Ko8BvQcQFJJgEzKprtZn9kWStTWE5trMyYN8_oilT_4LInyASeCGiBcrrSepTvrjomVCZKSaFF_RaCYoC_yBU0LWM8ODzRlliAHQv1C97veQuxNjq_aeWLEN361drz6Rk_WEn7hl52DRN32ee4xmV97rW8nqBVFsbPykXdkjj83iKWjwKv9FKVhNJNOfMaejMH4" -d "{\"queryInput\":{\"text\":{\"text\":\"run\",\"languageCode\":\"en\"}},\"queryParams\":{\"timeZone\":\"America/New_York\"}}" "https://dialogflow.googleapis.com/v2/projects/weathersample-ifjqjr/agent/sessions/ed2ec645-d8da-55b7-f71e-d0ee8d7ff2bb:detectIntent"
The response I got back was:
{
"responseId": "5eea8256-8771-4db1-8b51-2c82e31c7bf4-2e39b744",
"queryResult": {
"queryText": "run",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "Error: Speed test has not been called properly",
"fulfillmentMessages": [
{
"text": {
"text": [
"Error: Speed test has not been called properly"
]
}
}
],
"outputContexts": [
{
"name": "projects/weathersample-ifjqjr/agent/sessions/ed2ec645-d8da-55b7-f71e-d0ee8d7ff2bb/contexts/location",
"lifespanCount": 5
},
{
"name": "projects/weathersample-ifjqjr/agent/sessions/ed2ec645-d8da-55b7-f71e-d0ee8d7ff2bb/contexts/weathercontext-followup",
"lifespanCount": 2
}
],
"intent": {
"name": "projects/weathersample-ifjqjr/agent/intents/98199125-8fc6-466f-98b6-7648e14b06e7",
"displayName": "runSpeedTest"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 2439
},
"languageCode": "en"
},
"webhookStatus": {
"code": 14,
"message": "Webhook call failed. Error: UNAVAILABLE."
}
At the bottom of this response there is a "webhookStatus" object with an unavailable error and code of 14. Does anyone know what that code means?
Webhook is basically HTTP callback which will be triggered when the web-hook enabled intents are matched. Code:14 UNAVAILABLE means that it is looking for a handling function mapped to "runSpeedTest" intent which is not present in the web-hook provided. You can test it in Fulfilment->Inline Editor before deploying it externally.
I am trying to test sending an event to the Amazon's Event Gateway for my Alexa Smart Home skill using Postman but I keep receiving an 'invalid access token exception.' I have read the Amazon's documentation on this but apparently I am missing something.
When I enable my skill, my Smart Home Lambda receives the AcceptGrant.
{
"directive": {
"header": {
"namespace": "Alexa.Authorization",
"name": "AcceptGrant",
"messageId": "b2862179-bc56-4bb2-ac05-ce55c7a3e977",
"payloadVersion": "3"
},
"payload": {
"grant": {
"type": "OAuth2.AuthorizationCode",
"code": "ANSVjPzpTDBsdfoRSyrs"
},
"grantee": {
"type": "BearerToken",
"token": "Atza|IwEB..."
}
}
}
}
My lambda sends a POST to 'https://api.amazon.com/auth/o2/token' to receive the Access and Refresh tokens. It then stores those tokens. Next, my Lamdba responds with the following:
{
"event": {
"header": {
"namespace": "Alexa.Authorization",
"name": "AcceptGrant.Response",
"messageId": "b2862179-bc56-4bb2-ac05-ce55c7a3e977",
"payloadVersion": "3"
},
"payload": {}
}
}
I then get a message web page that I have successfully linked my skill - all is good.
Next, I try to send an event to Amazon's Alexa event gateway using the Postman app. I put the Access token (I also tried the Refresh token) in the header as a 'BearerToken' type and the in the 'scope' of the 'endpoint' object.
POST https://api.amazonalexa.com/v3/events?Content-Type=application/json&charset=UTF-8
with a header that specifies a Bearer Token (Access token received earlier) and a body that contains the following:
{
"event": {
"header": {
"messageId": "abc-123-def-456",
"namespace": "Alexa",
"name": "ChangeReport",
"payloadVersion": "3"
},
"endpoint": {
"scope": {
"type": "BearerToken",
"token": "<access token>"
},
"endpointId": "MySmartSwitch-001"
},
"payload": {
"change": {
"cause": {
"type": "RULE_TRIGGER"
},
"properties": [
{
"namespace": "Alexa.ModeController",
"name": "mode",
"value": "Backup",
"timeOfSample": "2020-01-02T09:30:00ZZ",
"uncertaintyInMilliseconds": 50
}
]
}
}
},
"context": {
"properties": [
{
"namespace": "Alexa.PowerController",
"name": "powerState",
"value": "ON",
"timeOfSample": "2020-01-02T09:30:00Z",
"uncertaintyInMilliseconds": 60000
},
{
"namespace": "Alexa.EndpointHealth",
"name": "connectivity",
"value": {
"value": "OK"
},
"timeOfSample": "2020-01-02T09:30:00Z",
"uncertaintyInMilliseconds": 0
}
]
}
}
The response received is '401 Unauthorized'
{
"header": {
"namespace": "System",
"name": "Exception",
"messageId": "95bd23c3-76e6-472b-9c6d-74d436e1eb61"
},
"payload": {
"code": "INVALID_ACCESS_TOKEN_EXCEPTION",
"description": "Access token is not valid."
}
}
I figured out the issue. I was mistakenly sending parameters: Content-Type=application/json and charset=UTF-8 as well including them in the header - my bad. You just need to include them in the header.
Packages :
hapi-swagger: 9.0.1
joi: 13.0.2
Context :
I use the swagger-ui with a swagger.json file generated by hapi-swagger.
I use for hapi-swagger the jsonEditor option set to true.
Which means that i don't enter myself the body in a single text area but i use directly the generated inputs of the UI.
Issue :
Only the key "name" is required in the payload, the other ones are optional by default if i refer to the Joi doc.
Actually the Swagger-UI sends :
curl -X POST
--header 'Content-Type: application/json'
--header 'Accept: application/json'
-d '{
"name":"fzef",
"idsUser": [],
"idsUsergroup":[]
}'
Instead i want that the Swagger-UI to send a request like :
curl -X POST
--header 'Content-Type: application/json'
--header 'Accept: application/json'
-d '{
"name":"fzef",
}'
Swagger UI
Joi Schema
Joi.object().keys({
request: Joi.object().keys({
name: Joi.string().required(),
idsUser: Joi.array().items(Joi.string()),
idsUsergroup: Joi.array().items(Joi.string()),
}),
}),
});
Swagger.json
...
"paths": {
"/addCompany": {
"post": {
"operationId": "postAddcompany",
"parameters": [{
"type": "string",
"default": "1",
"pattern": "/^v[0-9]+$/",
"name": "apiVersion",
"in": "path",
"required": true
},
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/Model 208"
}
}
],
"tags": ["api", "CompanyCommandsAPIPart"],
"responses": {
"default": {
"schema": {
"type": "string"
},
"description": "Successful"
},
}
}
}
}
"definitions": {
...
"Model 208": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"idsUser": {
"$ref": "#/definitions/Model 13",
"type": "array",
"x-alternatives": [{
"$ref": "#/x-alt-definitions/idsFunctionality",
"type": "array"
}, {
"type": "string"
}]
},
"idsUsergroup": {
"$ref": "#/definitions/Model 13",
"type": "array",
"x-alternatives": [{
"$ref": "#/x-alt-definitions/idsFunctionality",
"type": "array"
}, {
"type": "string"
}]
},
},
"required": ["name"]
},
...
}
What can i do to get this request body ?
Do i need to precise a joi method in order that the hapi-swagger parser add a parameter like 'optional' to the swagger.json ?
I found the same issue for the query of a GET method but found no solution:
https://github.com/swagger-api/swagger-editor/issues/684
The JSON Editor component provides the "Properties" and "Edit JSON" buttons to customize the JSON payload, as you can in the component demo here: http://jeremydorn.com/json-editor/. However, Swagger UI 2.x (the version used by hapi-swagger at the time of writing) initializes the JSON Editor with disable_properties: true and disable_edit_json: true so that these buttons are hidden, and the UI does not expose any configuration options to change the JSON Editor options. There is an open issue in the hapi-editor repository on GitHub: https://github.com/glennjones/hapi-swagger/issues/332.
A possible workaround is to tweak the Swagger UI code. Assuming your Swagger UI's index.html uses unminified swagger-ui.js, find the following lines in <hapi-swagger>/public/swaggerui/swagger-ui.js:
disable_properties:true,
disable_edit_json:true,
and replace them with:
disable_properties:false,
disable_edit_json:false,
Now the JSON Editor will have the "Object Properties" button. Click this button to select the properties to be displayed in the form editor and included in the request body. Unselected properties will not be sent in the request body.
I have logic app that is triggered by a service bus. The message content is not usable as it is just random characters. I suspect that perhaps it needs to be parsed but it is not clear how to do this.
I have the following:
Not enough reputation to add an image - but screen shot from Azure
"Insert_Entity": {
"inputs": {
"body": {
"PartitionKey": "deviceID",
"RowKey": "#variables('curDate')",
"content": "#triggerBody()?['ContentData']"
},
When I look at the data that I am getting for the "content" coming from the "#triggerBody()?['ContentData']" it looks like this:
"W3sidHlwZSI6ImxvZyJ9LF...." I deleted most of this as it 100's of characters long.
I suspect that this needs to be parsed or something to look at the actual message body. I have checked this out but don't know where to insert code like this: Getting content from service bus in logic apps
Can you please explain how to see the message body.
Can you please explain how to see the message body.
The string W3sidHlwZSI6ImxvZyJ9LF.... you mentioned is base64string. If we want to see the message body we need to convert the base64string to string
We could do that with base64ToString(triggerBody()?['ContentData']) details please refer to the screenshot.
Body info:
After getting the value as Tom Sun solution, i had had to extract the json part of the result to be able to parse it, Logic App Expression :
substring(
variables('result'),sub(indexOf(variables('result'),'{'),1),
sub(lastIndexOf(variables('result'),'}'),indexOf(variables('result'),'{'))
)
Then use Parse JSON function to parse the result using the schema :
{
"properties": {
"data": {
"type": "string" // Change As Required
},
"dataVersion": {
"type": "string"
},
"eventTime": {
"type": "string"
},
"eventType": {
"type": "string"
},
"id": {
"type": "string"
},
"metadataVersion": {
"type": "string"
},
"subject": {
"type": "string"
},
"topic": {
"type": "string"
}
},
"type": "object"
}
I asked another question in another thread that gave me start on Swagger POST, but here I am stuck with another problem.
Here is my parameter definitions in my config json file
"/people/postTest": {
"post": {
"summary": "post test.",
"description": "Test.",
"operationId": "postTest",
"consumes": [
"application/json"
],
"tags": [
"test post"
],
"parameters": [
{
"in":"body",
"name":"body",
"description": "body for the POST request",
"required":true,
"schema": {"$ref":"#/definitions/inBody"}
}
] }}
"definitions": {
"inBody": {
"properties": {
"RequestSystem": {
"type": "string"
}}}}
(copied it from a big file so only took a small part but there is no issues with syntax)
and I am using CURL to post my request
curl -H "Content-Type: application/json" -X POST -d '{"RequestSystem":"IVR"}' http://localhost:8016/people/postTest
and this is the validation error I am getting when I try to start my node server
**ValidationError: "body" is required**
I know I am passing "RequestSystem" parameter but I am not sure where I am making mistakes in setting up my params in my config json file's "parameters". Any help would be appreciated.
I think you need to make required=false
[
{
"in":"body",
"name":"body",
"description": "body for the POST request",
"required":false,
"schema": {"$ref":"#/definitions/inBody"}
}
]
}
}
Try this It should work.