Send Email in SharePoint Hosted App without using VS workflow - sharepoint-2013

I have created a SharePoint Hosted app which uses a visual studio workflow to send email within same domain.
Since I am in process of migrating custom aspx forms in SP2010 to SharePoint Online, each form is redeveloped as a SP Hosted app and I don't want to include a workflow every time to send email.
Is there any other workaround to handle email in SP Hosted app?
Thanks!

You can use javascript REST API to send email from hosted app.
See the code below:
var urlTemplate = SPAppWebUrl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
contentType: 'application/json',
url: urlTemplate,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'From': from,
'To': { 'results': [to] },
'Body': emailBody,
'Subject': subject
}
}
),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
//console.log('success')
alert('email send successfull..');
},
error: function (err) {
//console.log(JSON.stringify(err));
alert(JSON.stringify(err));
}
});

Related

AWS API Gateway -> Lambda -> Github Pages

I am trying to point a domain to Github pages site.
I am very new to working with domains and AWS services so I am finding it difficult to troubleshoot issues.
I have created an AWS ApiGateway that points to a lambda function which I would like to use to serve the content from Github pages, but currently, it is giving me the error:
{"message":"Internal Server Error"}
so when trying to fix this issue, I found instructions to make it log additional debug information. (instructions found at: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-troubleshooting-lambda.html)
this is telling me that my configuration for the lambda function is incorrect.
The response from the Lambda function doesn't match the format that API Gateway expects. Lambda body contains the wrong type for field "headers"
I don't know what is expected so I don't know what needs to be changed... my entire lambda function is configured as:
exports.handler = async (event, context, callback) => {
let domain = 'https://github-org-name.github.io/my-repo-with-gh-pages/';
return {
statusCode: '301',
statusDescription: 'Moved Permanently',
headers: {
'location': [{
key: 'Location',
value: domain,
}],
'cache-control': [{
key: 'Cache-Control',
value: "max-age=3600"
}]
},
}
};
I am completely new to using AWS services, so I don't know if anything else needs to be configured. any help is appreciated.
The values in your headers dict must be strings, e.g:
{
"cookies" : ["cookie1", "cookie2"],
"isBase64Encoded": true|false,
"statusCode": httpStatusCode,
"headers": { "headername": "headervalue", ... },
"body": "Hello from Lambda!"
}
See the bottom of this page:
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html

Send an ajax request in javascript to AWS API Gateway using raw body

The following body can be successfully sent to an AWS API Gateway, using Body -> Raw in Postman
{
"toEmails": ["foo#example.com"],
"subject": "test email from Postman",
"message": "Hello World!"
}
How do I adjust the following JQuery snippet to send the request to the same API Gateway?
$.ajax({
type: "POST",
url: URL,
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
data: JSON.stringify(data),
success: function(res){
console.log('Email was sent.');
},
error: function(res){
console.log(res);
}
});

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.

Sending http request from aws lambda to google firebse funcitons

I have set up firebase functions to receive http requests and have verified that the same is working. Now im trying to send http request to firebase from aws lambda function. But there is no response either in aws lambda or in the firebase functions log. This is my aws lambda code:
const postData = JSON.stringify({
"queryresult" : {
"parameters": {
"on": "1",
"device": "1",
"off": ""
}
}
});
const options = {
hostname: 'https://<the firebase function endpoint>',
port: 443,
path: '',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = https.request(options, postData)
.then((response) => {
console.log(response);
})
.catch((err) => {
console.log(err);
});
// Write data to request body
req.write(postData);
req.end();
}
The promise part here is suppose to execute the console logs but it is not getting executed. Is there something that i'm missing here. The host is the URL that we obtain when we deploy a function. Or is there some firebase or aws related plan problem. I'am using the spark plan in firebase. Thankyou.

I have an app with react as frontend and django rest framework as backend, i use axios to send my response, but the data is empty

I have an app with react and Django rest framework. I use Django allauth for login and registration. when I want to log in, everything is ok, and the response is 201 but the data is empty and I don't get token. I send this request with the postman and I get the token. what should i do?
React Request:
axios({
method: 'post',
url: 'http://localhost:8000/rest-auth/login/',
data: {
username: 'admin',
email: '',
password: 'admin123456'
},
headers: { 'content-type': 'application/json' }
})
.then(response => {
console.log(response.data.key);
})
.catch(error => {
console.log(error);
});
the response is:
{data: "", status: 200, statusText: "OK", headers: {…}, config: {…}, …}
postman request: http://localhost:8000/rest-auth/login/
{
"username": "mahtab",
"email": "",
"password": "mahtab23"
}
postman response:
{
"key": "f75b9f54848a94ac04f455321118aff5d5a7e6f8"
}