Sendgrid - Email Formatting - sendgrid

I am new to API's. I have created an API using curl command:
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header 'Authorization: Bearer <<YOUR_API_KEY>>' \
--header 'Content-Type: application/json' \
--data '{"personalizations":[{"to":[{"email":"john.doe#example.com","name":"John Doe"}],"subject":"Hello, World!"}],"content": [{"type": "text/plain", "value": "Heya!"}],"from":{"email":"sam.smith#example.com","name":"Sam Smith"},"reply_to":{"email":"sam.smith#example.com","name":"Sam Smith"}}'
It worked perfectly for me and it sent out the email.
I was wondering, how do I send an email body with html tags and images. Sorry if this is a basic question and asking here.

In your data that you are sending to the API, you have
"content": [{"type": "text/plain", "value": "Heya!"}]
This is sending your plain text email. To add HTML to this you can add another object to that array with the "type": "text/html".
"content": [{"type": "text/plain", "value": "Heya!"}, { "type": "text/html", value: "<h1>Heya!</h1>" }]
Sending images requires you to base 64 encode the contents of the image and add it to the "attachments" key within the JSON data, along with the filename, content type and content ID if you want to use it for embedding in the email.
"content": [ ... ], "attachments": [{ "content": BASE64_ENCODED_STRING, "type": "image/jpeg", "filename": "catsinhats.jpeg" }]
This blog post has more specifically on how to embed images in emails.

Related

How to fetch Github workflows yaml files using Github Actions API

I am following this documentation:
https://docs.github.com/en/rest/reference/actions#list-repository-workflows
/repos/{owner}/{repo}/actions/workflows
My sample output looks like this:
{
"total_count": 1,
"workflows": [
{
"id": 161335,
"node_id": "MDg6V29ya2Zsb3cxNjEzMzU=",
"name": "CI",
"path": ".github/workflows/blank.yaml",
"state": "active",
"created_at": "2020-01-08T23:48:37.000-08:00",
"updated_at": "2020-01-08T23:50:21.000-08:00",
"url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/161335",
"html_url": "https://github.com/octo-org/octo-repo/blob/master/.github/workflows/161335",
"badge_url": "https://github.com/octo-org/octo-repo/workflows/CI/badge.svg"
}
]
}
How do I fetch the workflow yaml file from this output
Given the filename, use the Get repository content API to fetch the file.
For your file, that'd be:
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octo-org/octo-repo/contents/.github/workflows/blank.yaml
The response JSON will contain a field content, which contains the encoded contents of that workflow.
Workflow yaml file in plain text:
curl \
-H "Accept: application/vnd.github.v3+json" \
https://raw.githubusercontent.com/octo-org/octo-repo/master/.github/workflows/blank.yaml

Invalid story format failed to parse story while posting Rasa X Http API

I am trying to create a story using POST in Postman tool and below is my story format .
I am using below format because in GET request I got the story in the same format.
{
"id": 65,
"name": "interactive_story_65",
"story": "35 interactive_story_65\n* emp_info\n - utter_employee",
"annotation": {
"user": "me",
"time": 1597919151.8836874962
},
"filename": "data\\stories.md"
}
But, I am getting below error:
{
"version": "0.31.0",
"status": "failure",
"message": "Failed to parse story.",
"reason": "StoryParseError",
"details": "Invalid story format. Failed to parse '## {\r\n \"id\": 65,\r\n \"name\": \"interactive_story_65\",\r\n \"story\": \"## interactive_story_65\\n* emp_info\\n - utter_employee\",\r\n \"annotation\": {\r\n \"user\": \"me\",\r\n \"time\": 1597919151.8836874962\r\n },\r\n \"filename\": \"data\\\\stories.md\"\r\n }'",
"help": null,
"code": 400
}
Attached is below screenshot:
enter image description here
Please help.
This endpoint is actually expecting plain markdown, with text/x-markdown as the content-type header. If you look closely at the docs, you'll see that you're using the response schema as the request schema - I did that too at first. The request schema is just a markdown string e.g.
curl --request PUT \
--url http://localhost:5002/api/stories \
--header 'authorization: Bearer <Token>' \
--header 'content-type: text/x-markdown' \
--data '## greet
* greet
- utter_greet\n'

dynamic_template_data not working when sending dynamic template using curl request - Sendgrid API

I'm making a curl request to send dynamic template with handlebar but it's not working properly.
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header 'Authorization: Bearer SG.xxxxxxxx.v-8xxxxxxxxxxxxI' \
--header 'Content-Type: application/json' \
--data '{"personalizations": [{"to": [{"email": "mrrobot#mail.com"}]}],"from": {"email": "contact#evilcorp.com"},"dynamic_template_data":{"fname":"elliot"}, "subject": "Hello, World!","content": [{"type": "text/html", "value": "Heya!"}], "template_id" : "d-xxxxxxxxxa1f"}}'
In my dynamic template I've used fname as {{fname}} but it's coming as empty when I make the curl request.
dynamic_template_data should be inside personalizations.
E.g:
{
"personalizations": [
{
"to": [
{
"email": "mrrobot#mail.com"
}
],
"dynamic_template_data": {
"fname": "elliot"
}
}
],
"from": {
"email": "contact#evilcorp.com"
},
"subject": "Hello, World!",
"content": [
{
"type": "text/html",
"value": "Heya!"
}
],
"template_id": "d-xxxxxxxxxa1f"
}

Cannot create a new Group in alfresco using the REST API (/groups) POST

Greetings to the community! I am trying to create a new user group on alfresco using the REST API following this guide https://api-explorer.alfresco.com/api-explorer/#!/groups/createGroup. I am using Postman to make the REST calls. I have successfully so far managed to create new users using the (/people) (POST) method like shown below:
POST: http://localhost:8080/alfresco/s/api/people?alf_ticket=TICKET_<<my_alf_ticket>>
and the following JSON in the Body:
{
"userId": "user",
"password": "pass",
"userName": "user",
"firstName": "user",
"lastName": "user",
"email": "user#user.com"
}
Unfortunately, when I am similarly trying to create a new group like following
POST: http://localhost:8080/alfresco/s/api/groups?alf_ticket=TICKET<<my_alf_ticket>>
and in the body section
{
"authorityType": "GROUP",
"shortName": "GROUP1",
"fullName": "GROUP_GROUP1",
"displayName": "GROUP_GROUP1"
}
I am facing the following error
Any help would be greatly appreciated :)
This is old api:
1) POST http://localhost:8080/alfresco/s/api/rootgroups/{shortName} to create group
2) POST http://localhost:8080/alfresco/s/api/groups/{shortName}/children/{fullAuthorityName} Adds a group or user to a group.
For new api you should use:
POST http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/groups
CURL
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '{
"id": "TEST_GROUP_ID",
"displayName": "Group for tests"
}' 'https://api-explorer.alfresco.com/alfresco/api/-default-/public/alfresco/versions/1/groups'
Response
{
"entry": {
"isRoot": true,
"displayName": "Group for tests",
"id": "GROUP_TEST_GROUP_ID"
}
}

Orion notification complex payload

I'm trying to use Orion notification to send SMS with Plivo.
This is how I send an SMS directly with Plivo:
curl -X POST https://api.plivo.com/v1/Account/MAMDA5ZDJIMDM1/Message/ -L -u MAMDA5ZDJIM:YzhiNDJjODNhNDkxMjhiYTgxZD -H 'Content-Type: application/json' -d #- <<EOF
{
"src": "0039414141414",
"dst": "0039414747111",
"text": "test SMS"
}
EOF
How should I encode it in Orion? I tried:
curl localhost:1026/v2/subscriptions -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d #- <<EOF
{
"description": "A subscription to get info about WS_UPPA_Sensor2",
"subject": {
"entities": [
{
"id": "Sensor1",
"type": "SensingDevice"
}
],
"condition": {
"attrs": [
"temperature"
]
}
},
"notification": {
"httpCustom": {
"url": "https://api.plivo.com/v1/Account/MAMDA5ZDJIMDM1NZVMZD/Message/",
"headers": {
"Authorization": "Basic TUFNREE1WkRKSU1ETTFOWlZNWkQ6WXpoaU5ESmpPRE5oTkRreE1qaGlZVGd4WkRkaE5qYzNPV1ZsTnpZMA=="
},
"payload": "{%22src%22%3A%2200393806412092%22%2C%22dst%22%3A%2200393806412093%22%2C%22text%22%3A%22test%20SMS%20from%20Waziup%22}"
},
"attrs": [
"temperature"
]
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
Is there another way than percent encoding?
URL encoding (I understand is the one you refer by "percent encoding") is the only one which have an special treatment in custom notifications (details described as part of the Orion documentation).
In fact, taking into account the existing one is complete (I mean, any text can be expressed in the terms of URL encoding) there is no need of adding any other.