I programmed a Node.JS Server with FCM and POST Protocol and my Client app is made with Swift code.
In Terminal, It prints success code like this
id=0:1476620858011270%00f7ba1cf9fd7ecd
But In my Client App, there is no notification. So I tried with the notification tab in my Firebase Console, and it worked very well.
This is my header in my server file
var headers = {
'Content-Type': 'application/json',
'Authorization': 'key=<Server Key>',
'project_id': '<Project ID>'
}
and This is my Request Code
request({
headers: headers,
url: "https://fcm.googleapis.com/fcm/send",
method: "POST",
form: {
"notification" :{
"title": "titie",
"body": "body"
},
"content-available": true,
"priority": "high",
"to": "<Firebase Token>"
}
}, function(error, response, body) {
console.log(body);
});
Related
I have Android Client application which runs and E-comm app and my backend server handles the data with MongoDB now I want to use push Notifications on my android app using FCM maybe using REST API which will be triggered from backend and i am not able to do so .
Please guide on how to use FCM from backend to android application.
I tried using FCM documentation and the following code:
var request = require('request');
var options = { method': 'POST', 'url': 'https://fcm.googleapis.com/fcm/send', 'headers': { 'Content-Type': 'application/json' },
body: JSON.stringify({ "to": "YOUR_FCM_TOKEN_WILL_BE_HERE", "collapse_key": "type_a",
"data": { "body": "Sending Notification Body From Data",
"title": "Notification Title from Data" }})};
request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
I am trying to call 2 3rd party apis. 1st to login and receive Bearer token and 2nd to post message. 1st works fine and I get the token. but when I try to call second api to post message it fails, probably because I dont know how to set the received token in 2nd api
here is my code
var myJSONObject = {
"email": auth[0],
"password": auth[1]
};
req.post({
url: "{{server_url}}/auth/login",
method: "POST",
json: true,
body: myJSONObject
}, function (error, res, body){
if(error){
console.log(error.message);
} else {
var myJSONObject1 = {
"category":"SYSTEM",
"type": "ALERT",
"keywords":"FUNCTION|createSomethingLvl1",
"status":"UNREAD",
"from": "tenantadmin#tenantadmin.com",
"to": "someemail#gmail.com",
"subject": "Some nice subject",
"body": "Some detailed body that contains information that informs the person"
};
req.post({
url: "{{server_url}}/api/message",
method: "POST",
headers: {
"Authorization": res.body.access_token,
"Content-Type": "application/json"
},
json: true,
body: myJSONObject1
}, function (err, res1, body){
if(error){
console.log(err.message);
} else {
console.log(res1.body);
}
});
}
});
If this is a "typical" http bearer token, then you need the word "Bearer" in front of the token like this:
"Authorization": "Bearer " + res.body.access_token,
You can see examples of a Bearer token in the OAuth RFC 6750 where it shows the grammar as:
b64token = 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) *"="
"Bearer" 1*SP b64token
And, here's an example from a Google API doc:
Authorization: Bearer AbCdEf123456
And, another example from an OAuth doc:
Authorization: Bearer vF9dft4qmT
Fetch function works in postman, but not in react-native, while trying to send an SMS with twilio API
I am trying to make an app that sends an sms when a button is pressed. In my onPress, i use this function.
SendMessage = () => {
try {
fetch("https://api.twilio.com/2010-04-01/Accounts/[AccountSID]/Messages.json", {
body: "To=[toPhoneNumber]&From=[fromPhoneNumber]&Body=[message]=",
headers: {
Authorization: "Basic [Auth]",
"Cache-Control": "no-cache",
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST"
})
}
catch (err) {
console.log("Error fetching data-----------", err);
}
}
When i press the button nothing happens. please bear over with me because i am new to react native.
I'm facing a problem with the validation of the notification url when I want to register a subscription with the outlook API.
The options passed in the request are :
var optionsSubscription = {
url: "https://outlook.office.com/api/v2.0/me/subscriptions",
method: "POST",
headers: {
"authorization": "Bearer " + user.outlookCalAccessToken,
"accept": "application/json",
"ContentType": "application/json",
},
json: {
"#odata.type": "#Microsoft.OutlookServices.PushSubscription",
"Resource": "me/events",
"NotificationURL": "https://xxx/callback",
"ChangeType": "Created,Deleted,Updated"
},
"Content-Type": "application/json"
}
The response is the following :
Notification URL 'https://xxx/callback?validationtoken=N2FhY2JhNmItYTc2MC00MGUwLThmOGItZWQ2N2Q5Nzg5Y2Y2' verification failed System.Net.WebException:
The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.Exchange.OData.Model.Notifications.PushNotification.PushSubscriptionCallbackUrlValidationHelper.SendRequestAndVerifyResponse (Uri callbackUrl, PushSubscription pushSubscription).
When I request the notification url with Postman, it works and returns the validation token with a 200 status as expected.
The SSL certificate is generated with let's encrypt.
I want to send a request to the server with postData.(JSON)
I tried the following $http request,
var jsonData = {"id": 1,
"name": "xxx",
"designation": "developer",
"department": "IT"};
$http({method: 'POST',
url: url,
data: jsonData,
headers: {'contentType': 'application/json'}
}).success(function() {
$scope.sucess = "Success";
}).error(function() {
$scope.errorMessage = "Failure";
});
and
$resource('/path/to/the/server',{},{update:{method: 'POST', headers:
{'Content-Type': 'application/json'}}});
But i'm getting "No content to map to Object due to end of input Error for both $http and $resource request.
Additional Information: *My client side application is running on Express serve with node.js*
Can anyone help me how to achieve this in anyone of the above methods?