Ionic Push is no longer working 1.x - ionic-framework

Everything has been working great then now I get the following error:
ionic.bundle.js:18463 OPTIONS https://push.ionic.io/api/v1/push net::ERR_NAME_NOT_RESOLVED
i cant seem to send a push using the following:
// Encode your key
var auth = btoa(privateKey + ':');
// Build the request object
var req = {
method: 'POST',
url: 'https://push.ionic.io/api/v1/push',
headers: {
'Content-Type': 'application/json',
'X-Ionic-Application-Id': appId,
'Authorization': 'basic ' + auth
},
data: {
"tokens": devices,
"notification": {
"alert": message,
"ios":{
"priority": 10,
"badge": 1,
"payload": {"path": path}
}
}
}
};
// Make the API call
$http(req).success(function(resp){
// Handle success
console.log("Ionic Push: Push success!");
}).error(function(error){
// Handle error
console.log("Ionic Push: Push error...");
});
everything just stopped working - it was working beautifully before.
thanks for your help

I think they have change the URL and format little bit.
New URL is https://api.ionic.io/push/notifications
Payload
{
"tokens":["device_token_1", "device_token_2"],
"profile": "prod",
"notification": {
"title" : "Title of the message",
"message": "Ur message!"
}
}

Related

Always getting error "requestId is required" when doing POST on quickbooks payment API Apps Script

Im creating a script that will process a credit transaction and I always getting this response:
{
"errors": [
{
"code": "PMT-4002",
"type": "invalid_request",
"message": "requestId is required.",
"detail": "requestId",
"infoLink": "https://developer.intuit.com/v2/docs?redirectID=PayErrors"
}
]
}
Im trying to figure out where to put the "request-id" parameter on the request body. Here is my code:
function QBOcreatecharge(){
var token = "TOKEN"
var service = getQuickbooksService();
if (service.hasAccess()) {
var url = 'https://sandbox.api.intuit.com/quickbooks/v4/payments/charges'
var Details =
{
"amount": "80.00",
"currency": "USD",
"capture": "false",
"token": token
}
var params = {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
},
contentType: 'application/json',
method: 'POST',
payload: JSON.stringify(Details),
muteHttpExceptions:true
}
var response = UrlFetchApp.fetch(url, params);
var value = JSON.parse(response.getContentText())
Logger.log(value)
}
else{
var authorizationUrl = service.getAuthorizationUrl();
Logger.log('Open the following URL and re-run the script: %s', authorizationUrl);
}
}
How do I add the requestId parameter? I tried to insert it on the link, on the header and nothing work. Im using UrlFetch on Google Apps Script. Any help will be appreciated. Thanks!
The Request-Id is a header you need to send. e.g.:
headers: {
Authorization: 'Bearer ' + service.getAccessToken(),
'Request-Id': your unique value here
},
Intuit documents it here:
https://developer.intuit.com/app/developer/qbpayments/docs/develop/explore-the-quickbooks-payments-api/rest-api-features#identifiers

Can't send Webhook request from Actions

Im having problems contacting my web hook, I tried changing from Inline Script (is down below) to WebHook to my server api and with a direct json file on a web server that doesn't require authentication, but Im not having success, this is the script that I use to call my server:
https.get({
host: 'myurl.eu.ngrok.io',
path: 'apipath/function-called',
headers: {
'Authorization': 'mytoken',
},
}, function(response) {
let json = '';
response.on('data', function(chunk) {
console.log('received JSON response: ' + chunk);
json += chunk;
});
response.on('end', function() {
let jsonData = JSON.parse(json);
let stockPrice = jsonData.data[0].value;
console.log('the stock price received is:' + stockPrice);
let chat = 'The' + priceType + ' price for ' + companyName +
' on ' + date + ' was ' + stockPrice;
CloudFnResponse.send(buildChatResponse(chat));
});
});
when I test the Intent on Dialogflow they return me a 403, because the API requires authentication, when I try to do the same thing from Actions and with a logged account with Oauth / Google Sign In the error is this:
"responseMetadata": {
"status": {
"code": 14,
"message": "Webhook error (206)"
}
but watching the logs, I don't receive the request, giving a look to the exception from Cloud Platform, the server that answers doesn't have the headers my server use, I don't use NGNIX
Received response from agent with body: HTTP/1.1 200 OK Server: nginx/1.13.6 Date: Wed, 10 Oct 2018 08:15:48 GMT Content-Type: application/json;charset=UTF-8 Content-Length: 534 X-Cloud-Trace-Context: 6441a38beda637638dfd2e6b1f3e9c8a/7766163845645599757;o=0 Google-Actions-API-Version: 2 Via: 1.1 google Alt-Svc: clear
{
"conversationToken": "[]",
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "text request"
}
}
]
}
},
"possibleIntents": [
{
"intent": "assistant.intent.action.TEXT"
}
],
"speechBiasingHints": [
"$measureUnit",
"$product"
]
}
],
"responseMetadata": {
"status": {
"code": 14,
"message": "Webhook error (206)"
},
"queryMatchInfo": {
"queryMatched": true,
"intent": "d060e25c-2e4e-4c7e-903b-5cb55c13a6f0",
"parameterNames": [
"product",
"quantity",
"measureUnit"
]
}
}
}
anyone knows what could be the problem?
the problem seemed to be the 2nd version of the agent, the Web hook error is supossed to return the Error Code of the page, but it didnt.

Getting POST Request Message using React.JS

I am writing a program which has a "sign up" functionality. The front-end is created using React.JS. So far, I am able to using this code to send a post request in React.JS:
fetch('http://localhost:2000/users/signup/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"email": "testing#gmail.com",
"password": "secret",
"name": "matthew",
"organization": "Apple"
})
}).then(function(response) {
return response.json();
});
This works perfectly - for the user information is now in the database. However I am not sure how to get the response JSON using response.json(). I want to be able to take the response, get the message string, and display it to my user on the front-end. This is the response when I run the same post request on Postman.
{
"message": "New user created"
}
Thanks for the help!
response.json() returns a promise, so you need one more then to get the actual data:
.then(function(response) {
return response.json();
})
.then(function(data) {
console.log(data);
})
see https://developer.mozilla.org/en-US/docs/Web/API/Body/json

Azure Machine Learning REST API: no body

I am simply strying to call the REST API end point of a machine learning experiment created with Azure. I keep getting this error message:
{
"error": {
"code": "BadArgument",
"message": "Invalid argument provided.",
"details": [
{
"code": "RequestBodyInvalid",
"message": "No request body provided or error in deserializing the request body."
}
]
}
}
I have looked it up on their documentation: https://learn.microsoft.com/en-us/azure/machine-learning/machine-learning-web-service-error-codes
All it says is that my bod is empty, I am not sure how can it be empty, here is my code:
router.post('/rating/new', function(req, res) {
var postData = {
"Inputs": {
"input2":
[
{
'Col1': "A11",
'Col2': "6",
'Col3': "A34",
'Col4': "A43",
'Col5': "1169",
'Col6': "A65",
'Col7': "A75",
'Col8': "4",
'Col9': "A93",
'Col10': "A101",
'Col11': "4",
'Col12': "A121",
'Col13': "67",
'Col14': "A143",
'Col15': "A152",
'Col16': "2",
'Col17': "A173",
'Col18': "1",
'Col19': "A192",
'Col20': "A201",
'Col21': "1",
}
],
},
"GlobalParameters": {
}
};
// Configure the request
var options = {
url: config.ML_PREDICTIVE.url,
method: 'POST',
headers: {
'Content-Type':'application/json',
'Authorization':('Bearer ' + config.ML_PREDICTIVE.apiKey)},
form: postData
}
console.log(JSON.stringify(options));
// Start the request
request.post(options, function (error, response, body) {
if(error){
res.status(403).send(error);
}
if(response.statusCode != 200){
res.status(403).send(response.body);
}
if (!error && response.statusCode == 200) {
console.log(body)
}
})
});
The only thing I see that could go wrong is that "form" in the request is not considered body by azure, I have tried with "body" as well no success.
Please help !
According to the code you provided, the variable postData is not valid JSON string. You'd need to use JSON.stringify() method to convert postData value to a JSON string before you send a POST request.

Sending push notification using ionicframework cloud api

Hello am trying to send push notification from my nodejs server to ionicframework API and am getting an error here is my code
var token = '66a5c472b52d3210b591f717b5b996312f8xxxxxxxxxxxx';
var title = 'test';
var message = 'message';
var options = {
method: 'POST',
url: 'https://api.ionic.io/push/notifications',
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
},
json : {
"send_to_all": true,
"profile" : "my-profile",
"notification": {
"title": title,
"message": message,
"android": {
"title": title,
"message": message
},
"ios": {
"title": title,
"message": message
}
}
}
};
request(options, function(err, response, body) {
if (err) throw new Error(err);
console.log(body);
});
am getting this error
{ error:
{ message: 'JWT decode error occurred.',
link: null,
type: 'Unauthorized' },
meta:
{ status: 401,
version: '2.0.0-beta.0',
request_id: '75726406-3060-4329-a59e-3bd7f9ca90c8' } }
What could I be doing wrong
I think there is issue with your authorization header.
In header you're putting token, but please make sure it is API token.
Also make a postman request first and check whether it is working fine.
add content-type and authroization parts in header only..
then check the difference..
Thanks
Basu