How do you send a notification from server using UrbanAirship? - push-notification

I am trying to send a notification from the server and the docs says to POST to /api/push/broadcast/ which I have done from the following code
$.ajax({
type: 'POST',
dataType: 'json',
url: 'https://go.urbanairship.com/api/push/?callback=?',
data: '{"android": {"alert": "hi"}}',
contentType: "application/json",
username:"P4...UBg",
password:"fg...gDA",
error: function(jqXHR, textStatus, errorThrown){
// log the error to the console
alert(
"The following error occured: "+
textStatus, errorThrown
);
},
});
And I am getting a 500 (Internal Server Error). I added the callback to prevent "same origin policy" error as suggested here. Does anybody know how to do it correctly?
Thanks

I initially tried to set things up this way (making a raw $POST) to their servers. In the end, I was happy to find that they have modules for most common languages. Our server is all written in Python so we used the Python module. Here is a list of the packages they have:
https://support.urbanairship.com/customer/portal/articles/60713-push-server-libraries
All we had to do was upload the .py file into our bin and we're able to send pushes like this:
airship_android = urbanairship.Airship(SECRET_KEY, MASTER_KEY)
push_data = {"android": {"alert": notification_message, "extra": str(extra_data_str)}, "apids": [apid]}
airship_android.push(push_data)
Hopefully that helps!

Related

The AWS Lambda returns "Error: connect ETIMEDOUT **.****.***.***:443"

I have to services, Admin Panel(Laravel) и Online Shop(Woocommerce). The relation between these to services was realized with AWS Lambda.
When I try to send an updating product request from my Admin panel to online shop, time to time the lambda couldn't connect to the Woocomerce API.
On time when the system is not updating the product, lambda returns the error "Error: connect ETIMEDOUT"
I originally thought that the Wordpress didn't have enought time for updating process. And decided to increase the lambda's timeout (60000 ms). But it didn't help. I still found the ETIMEDOUT errors in logs.
By the way, the time period between sending the updating request to woocommerce and showing an error is 2 min. If I right understand, the lambda had enough time for getting the answer from woocommerce.
Another strange thing. According the lambda's logs, on time when lambda got an error, the woocommerce API was available. It seems like something disconnects the internet on time when lambda is sending the request.
My question is, why lambda cannot send to Woocommerce API the request. Why it happens time to time?
P.S. Below I added the example of lambda's logs.
The log on starting sending the updating request.
2021-08-14T18:23:48.692Z b228455b-45a8-5cbf-8160-1cc INFO Inside edit Online List {
status: '1',
*********
is_delete: 0,
name: 'Omega Speedmaster Moonwatch Chronograph 42mm ',
price_on_request: 0,
on_sale: 0
}
The log with error.
2021-08-14T18:25:58.299Z b228455b-45a8-5cbf-8aae6 INFO WooCommerce editOnlineStock err::: { Error: connect ETIMEDOUT ***.****.***.***:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
address: '***.****.***.***',
port: 443,
config:
{ url:
'https://domain/wp-json/wc/v3/products/*****',
method: 'put',
params: {},
data:
'{"name":"Omega Speedmaster Moonwatch Chronograph 42mm ","type":"simple"***********',
headers:
{ Accept: 'application/json',
'Content-Type': 'application/json;charset=utf-8',
'User-Agent': 'WooCommerce REST API - JS Client/1.0.1',
'Content-Length': 681 },
auth:
{ username: 'ck_************',
password: 'cs_************' },
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 60000,
adapter: [Function: httpAdapter],
responseType: 'json',
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
****************************
Is your lambda associated with a VPC? If so, i) explore to see if the VPC has a route out to the internet with a NAT gateway/instance, ii) examine the VPC flow logs for errors.

Upload file size limit with custom webscript on Alfresco Community 5.2

I need help to upload document content back in Alfresco Community 5.2 though a share javascript.
The destination noderef is already existing, I upload a new version of a document.
I can't use the api/upload web service because I also need to do some operation on the noderef and I have a base64 content of the file which need to be converted.
So I wrote a new webscript and it is all working fine, at least while I upload documents which are smaller than 3MB,
Here it is the code
Alfresco.util.Ajax.request({
method: Alfresco.util.Ajax.POST,
dataObj: {
bytes: response.bytes,
digestAlgorithm: response.digestAlgorithm,
mimeType: response.mimeType.mimeTypeString,
name: response.name,
nodeRef: this.nodeRef,
signatureLevel: this.signatureLevel
},
url: thisClass.urlAlfrescoService + "myOrg/myPackage/uploadDocument",
successCallback: {
fn: thisClass._successOnUploadContent,
scope: this
},
failureCallback: {
fn: thisClass._errorOnUploadContent,
scope: this
},
scope: this,
noReloadOnAuthFailure: true
});
Do I miss some option to increase max upload file size?
I tryed uploading the file normally (with drag and drop) and it works.
The problem is when the file is >= 3MB the java class behind the webscript does not receive any byte
UPDATE
After some researches I found it could be a problem of how data are passed through POST, as application/x-www-form-urlencoded instead of multipart/form-data, but I can't find a way to specify the request content type in the ajax request
SOLUTION
The problem was the application/x-www-form-urlencoded instead of the multipart/form-data, I used a fetch POST request as stated here, but also the ajax request solution is good.
Last week,I had a same very similar problem with Alfresco AJAX request on Alfresco 5.0.2.5 and I used jquery's AJAX calls and it worked for me.
$.ajax({
url: Alfresco.constants.PROXY_URI + "your_web_script",
type: "POST",
data: dataFromFiles,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
dataType: "text",
success: function(data, textStatus, jqXHR) {
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
Reference link : https://blog.arvixe.com/sending-multipart-form-using-ajax/
Hope this helps you.

google flex endpoint 403 forbidden

I've developed some google flex endpoints. They work locally but when I deploy the app (gcloud app deploy) I get a http status 403 forbidden. I'm using ajax to call the endpoint like this:
var echoEndpoint = function() {
$.ajax(userBaseUrl+'/echo', {
headers: {'Authorization': 'Bearer ' + userIdToken},
type: 'GET',
data: "key=my special key"
})
}
I'm protecting the endpoint with an apikey and passing the userIdToken in the header. The above code produces the 403 forbidden. But if I remove the header it works. albeit no user token. Here is the code that will NOT produce the 403
var echoEndpoint = function() {
$.ajax(userBaseUrl+'/echo', {
type: 'GET',
data: "key=my special key"
})
}
here is my paths section of my openapi.yaml
.....
paths:
"/echo":
get:
description: "Echo a test message."
operationId: "echo"
produces:
- "application/json"
responses:
200:
description: "Echo"
schema:
$ref: "#/definitions/echoMessage"
x-security:
- firebase:
audiences:
- "my project-id"
....
definitions:
echoMessage:
properties:
message:
type: "string"
Do I need to specify in my openapi.yaml that I'm sending a header in the request? If so how and where? I tried to put it in the definitions section but that yields a INVALID_ARGUMENT error when trying to deploy.
Did you define "firebase" in "securityDefinitions" as shown in this example (https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/flexible/endpoints/openapi.yaml#L108"?

HTTP POST fails because of double dash (hyphen) in parameter value

I've found this problem when I was doing some stuff for a customer.
Whenever some form was posted (using ajax) the server was responding with a 404 but this was only happening whenever the data contained a parameter with double dashes in the value of it.
I dont have full access to the server but all I found in the error log was "/var/www/digital/sites/ftp/htdocs/favicon.ico" File does not exist. I can only imagine that something is going wrong in the HTACCESS or something. Anyone has an idea?
Some example:
var d = "Friday|~|<#if contact.edm_mailpack?starts_with(\"Val\")> ${\"${contact.soort_aanvraag!}\"?uncap_first}<#if contact.merk?has_content && contact.model_1?has_content> van de ${contact.merk_1!} ${contact.model_1!}<#elseif contact.edm_mailpack?starts_with(\"UC\")>Kucsdcailpack?starts_with(\"CC\")>Bescdds geïnteressseerd<#if contact.merk?has_content && contact.model_1?has_content> in de ${contact.merk_1!} ${contact.model_1!}<!--#if-->?<!--#if-->|~|some other data";
var d2 = d.replace(/--/g, '');
$.ajax({
type: "POST",
url: 'http://xxxxx/dt_csv_export.php',
//contentType: 'application/octet-stream; charset=utf-8',
data: {
action: "generate",
csv_type: oTable.attr('id'),
csv_data: d2
},
success: function(download_link) {
location.href = download_link;
}
}).fail(function(xhr, textStatus, errorThrown) {
alert(textStatus);
});

how do you pass a parameter to an asp.net page method using jquery/ajax?

I'm trying to pass parameters to my static web method (which is in an asp.net page). I'm trying to pass the "test1" param with a value of "myvalue". Any ideas on what I am doing wrong?
$.ajax({
type: "POST",
url: "WebForm1.aspx/WebMethod1",
data: {"test1": "myvalue"},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});
my "data" section was wrong. it needs to be "{'test1':'myvalue'}"
What error are you getting?
I've used prototype before (similar to jQuery for ajax) and with that you don't quote the parameter names. So your data parameter should probably be:
data: {test1: "myvalue"}
Give that a shot.
You could also try setting up Fiddler and see the actual request being made.
The way you have it set up, any error that may occur in the ajax call will get silently swallowed. I'd suggest adding an error callback like this:
$.ajax({
type: "POST",
url: "WebForm1.aspx/WebMethod1",
data: {"test1": "myvalue"},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
},
error: function(response) {
$('body',document).html(response.responseText);
}
});
Also, if you are using Visual Studio, you could run your ASP.NET app in debug mode to catch any server-side error. You can also put a breakpoint somewhere in the server-side code to make sure it's getting hit at all, and to inspect the Request.Form collection.
Hope this helps.

Resources