I am trying to send email using loopback.io, i am able to send the mails from loopback, but not able to set the signature of the mail. The code for mail sending is
MyModel.app.models.Email.send({
to: 'foo#bar.com',
from: 'you#gmail.com',
subject: 'my subject',
text: 'my text',
html: 'my <em>html</em>'
}, function(err, mail) {
console.log('email sent!');
cb(err);
});
Is there any way to add signature in the json
Thanks in advance
The default model (i.e. documentation here) does not handle any signature field.
What about just add the signature to your email body ?
Otherwise, I guess you could try to extend Email model to handle this custom field.
Related
I am trying to test the /login API via POSTMAN (via FE it works fine) but it doesn't
show anything in the body part even though I am sending body data.
but when printing the request from the BE, the body is empty...
....
body: {},
....
unlike when using FE:
....
body: {data: { username: 'admin', password: 'admin' }},
....
Any idea what's going on? If anything else is needed to be provided - pls let me know
I know it's going through because the server responds with 500 and the message
TypeError: Cannot read property 'username' of undefined
The weird part is, that the data I am sending, are nowhere to be found in the request object at all :(
EDIT:
This is how I call it from the FE:
return axios.post('login', { data: user })
and the user is:
user: {
username: 'admin',
password: 'admin'
}
So the format should be right
data: {
username: 'admin',
password: 'admin'
}
Because that's how I access it on the BE side
req.body.data.username
EDIT2:
The ultra-super-rare-weird part is, that JEST is working fine :)
const creds = {
data: {
username: 'admin',
password: 'admin'
}
}
return request(app)
.post("/api/v1/login")
.send(creds)
.expect(200)
.then(res => {
expect(res.body).toMatchSnapshot()
})
and this test passes .... f**k me guys.. what's going on?
if you are working with an express server try to parse your body in the server as soon as you initialize express app before routing
const app = express();
app.use(express.json());
The syntax of your body looks like JSON, yet you've specified the type of the body as "raw text". This will set the Content-type header of your request to "text/plain", which is probably causing your backend to be unable to actually read the body (because it expects a JSON object).
Simply switch from "Text" to "JSON", wrap your current body in curly braces (so that you're actually sending a single JSON object with a data property set) and try sending the request again. The content-type header will be correctly set to "application/json" this time and your backend will read the data successfully.
Add the following parameters in the request headers configuration in Postman:
Content-Type: application/json
Content-Length
The value of Content-Length is automatically calculated by Postman when a request is sent. Both values are used to identify the media type of the request body and to parse it accurately. When missing, the body may be ignored completely (depending on the server).
React-Django application. User signs in by providing username and password through Axios PUT, if correct JWT and username is returned, both are stored in sessionStorage. User is then automatically routed to /home which should populate with information specific to the user.
/home has componentWillMount() that is supposed to GET via Axios the content for /home from the database. Some is static and some is relevant to the user, for example first_name. I'm trying to send the username along with the JWT to retrieve this information but not sure how to.
This is what I have that is working in retrieving static content like the welcome message. Just want to send username along to so I can add logic server-side to retrieve information for this user and send back in the response.
import axios from 'axios';
import { push } from 'react-router-redux';
import { ROOT_URL } from '../../config/config.json';
// Establish the different types
export const WELCOME_MESSAGE = 'welcome_message';
export function getWelcome() {
return function(dispatch) {
axios
.get(
`${ROOT_URL}/api/home/`,
{ headers:
{
'Content-Type': 'application/json',
'Authorization': 'JWT ' + sessionStorage.getItem('token')
}
}
)
.then(response => {
dispatch({
type: WELCOME_MESSAGE,
payload: response.data
});
})
.catch(error => {
console.log("Broke");
});
}
}
Worst case, I just make another function with POST where I know I can send this information easily.
So you want to send the username in GET request method in AXIOS.
You can send the username in URL as the query so that at the backend you can access username from URL query
example:
${ROOT_URL}/api/home?username=rahulrana
This is how you can achieve this through GET method.
through the query in URL is the only way to send information.
I am building an app with AngularJS and using external API made with Django.
For API calls I'm using Restangular (but it's not the case because even with $http I get the same).
My default content-type for post calls is:
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
This is done just so I could send credentials when signing in win OAuth2:
var data = {
grant_type: 'password',
client_id: clientID,
client_secret: clientSecret,
username: username,
password: password
};
$http.post('http://server.com/api/oauth2/access_token/', data);
GET is done using default AngularJS configuration (application/json I guess).
So far so good, everything was working until... I was making POST requests and sending large JSON objects.
The configuration from above didn't work, so I changed those POST requests to application/json, and getting error response:
400: JSON parse error - No JSON object could be decoded
Tried the same with just jQuery - and it worked although I had to do JSON.strigify and in error debugging on Chrome Request Payload with jQuery looks like a proper object, and with AngularJS looks like this:
type=Feature&geometry=%5Bobject%20Object%5D&properties=%5Bobject%20Object%5D
(yes, by the way, I'm sending a valid GeoJSON object)
So I thought maybe JSON.stringify has something to do with this but after applying this to my object, the Request Payload from AngularJS is a mess:
0=%7B&1=%22&2=t&3=y&4=p&5=e&6=%22&7=%3A&8=%22&9=F&10=e&11=a&12=t&13=u&14=r&15=e&16=%22&17=%2C&18=%22&19=g&20=e&21=o&22=m&23=e&24=t&25=r&26=y&27=%22&28=%3A&29=%7B&30=%22&31=t&32=y&33=p&34=e&35=%22&36=%3A&37=%22&38=P&39=o&40=i&41=n&42=t&43=%22&44=%2C&45=%22&46=c&47=o&48=o&49=r&50=d&51=i&52=n&53=a&54=t&55=e&56=s&57=%22&58=%3A&59=%5B&60=1&61=9&62=.&63=0&64=8&65=3&66=2&67=4&68=1&69=2&70=2&71=4&72=2&73=8&74=8&75=9&76=%2C&77=5&78=0&79=.&80=2&81=4&82=2&83=4&84=0&85=2&86=0&87=7&88=2&89=3&90=6&91=8&92=9&93=%5D&94=%7D&95=%2C&96=%22&97=p&98=r&99=o&100=p&101=e&102=r&103=t&104=i&105=e&106=s&107=%22&108=%3A&109=%7B&110=%22&111=c&112=o&113=n&114=t&115=r&116=i&117=b&118=u&119=t&120=i&121=o&122=n&123=t&124=y&125=p&126=e&127=%22&128=%3A&129=1&130=2&131=1&132=4&133=5&134=%2C&135=%22&136=l&137=o&138=c&139=a&140=t&141=i&142=o&143=n&144=%22&145=%3A&146=%7B&147=%22&148=n&149=a&150=m&151=e&152=%22&153=%3A&154=%22&155=D&156=a&157=n&158='&159=s&160=%20&161=H&162=o&163=u&164=s&165=e&166=%22&167=%2C&168=%22&169=d&170=e&171=s&172=c&173=r&174=i&175=p&176=t&177=i&178=o&179=n&180=%22&181=%3A&182=n&183=u&184=l&185=l&186=%2C&187=%22&188=s&189=t&190=a&191=t&192=u&193=s&194=%22&195=%3A&196=n&197=u&198=l&199=l&200=%2C&201=%22&202=c&203=r&204=e&205=a&206=t&207=e&208=d&209=_&210=a&211=t&212=%22&213=%3A&214=%22&215=2&216=0&217=1&218=4&219=-&220=0&221=4&222=-&223=3&224=0&225=T&226=1&227=0&228=%3A&229=2&230=4&231=%3A&232=5&233=8&234=.&235=9&236=3&237=7&238=Z&239=%22&240=%2C&241=%22&242=i&243=d&244=%22&245=%3A&246=4&247=5&248=%7D&249=%7D&250=%7D
Any help? What I'm doing wrong? Or it has something to do with Django API? Should we change something in it?
SOLVED
The problem was caused by serialiser (my interpretation of jQuery's $.param). Apparently I needed this for sending credentials for the OAuth2 but not for any other POST request.
Although I still don't know why it is like that.
try this
var data = {
grant_type: 'password',
client_id: clientID,
client_secret: clientSecret,
username: username,
password: password
};
$http.post('http://server.com/api/oauth2/access_token/', angular.toJson(data));
Include jquery and try this
$http({
method: 'POST',
url: 'http://server.com/api/oauth2/access_token/',
data: $.param(data)
});
I have the following Facebook Graph API call:
FB.ui({
method: "send",
to: '123123,456456',
name: 'People Argue Just to Win',
link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html'
}, function(response) {
// some stuff
});
Whenever it's invoked, my message's only recipient is the user with id 123123. If I switch the two numbers, the 456456 is the sole recipient.
As far as I can tell, I'm using the API exactly like I'm supposed to, so what could I be doing wrong?
It looks like it's not possible with the send method to specify multiple recipients: http://bugs.developers.facebook.net/show_bug.cgi?id=18806
It does look like it can be done with the apprequests method, though:
FB.ui({
method: 'apprequests',
message: 'My message',
data: {},
title: "My Title",
to: [123123, 456456]
});
For my purposes, that's close enough.
I am not familiar with using Facebook Javascript SDK.
My story is when I access to the website It displays all my friends(pic and name) on a webpage.
I registered Facebook API and App ID
I put website URL as http://localhost:81/ because I am testing my own local machine.
Do you have any good example website or good examples?
Please share with me
Thank you.
First your app should use required permissions like,
user_birthday, friends_birthday, user_location , friends_location...
( for more permissions)
Get info about current user:
FB.api('/me', function(response) {
// Stuff here
});
Get info about current user's friends:
FB.api('/me/friends', function(response) {
// Stuff here
});
you will get the response like,
{data: [{id: "FRIEND1_ID", name: "FRIEND1_NAME"}, {id: "FRIEND2_ID", name: "FRIEND2_NAME"}]....}
If you want get some more properties of your friends, use FIELDS parameter, like
FB.api('/me/friends', {fields: 'name,id,location,birthday'}, function(response) {
// Stuff here
});
If want to get individual user's friend info:
FB.api('/FRIEND1_ID', function(response) {
// Stuff here
});
Try this Example Site
Direct Access Method:
Log into Facebook under your name. If you need an "Access Token", Click on the Extended Permissions and click the "read_friendlist" check box to get your Access Token and then
submit your query. You may need to "Allow" access, so just follow the prompts given.
Voila! You now have the usernames for everyone on your Friends List. The "username" parameter in the query will give you the contact email "message to that person" and you append #facebook.com and send them a message. Very simple.
http://developers.facebook.com/tools/explorer?fql=SELECT%20username%20FROM%20user%20WHERE%20uid%20IN%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me%28%29%29%20ORDER%20BY%20name
-SAB