Quickblox, send push notification via REST API - quickblox

When trying to send a push notification:
{'event[environment]': 'development', 'event[notification_type]': 'push', 'event[message]': u'payload=VGhpcyBpcyBhIHB1c2ggbm90aWZpY2F0aW9uIEFQSSBUZXN0', 'event[user][ids]': 'xxx', 'token': xxx'}
I get following result from the API.
{"code":null,"message":"invalid byte sequence in UTF-8"}
The Payload is a base64 encoded string, so it should work properly. Anyone an idea what's wrong here?
thanks,
phil

It looks like your message is not in the correct format:
Did you encode a JSON Object like the following one as Base64 ?
"aps": { "alert": "Some text", "badge": 1, "sound": "default" }

Related

How to send image to Telegram Bot?

Trying to send image (or any type of file) to telegram bot.
It possible to take blob, convert it to Base64 and POST it?
I've tried to test it via SOAPUI but:
https://api.telegram.org/botXXX/sendDocument
{
"chat_id":XXX,
"document":"R0lGODlhKAAoAMIAAAAAAL6+vgCYAOfn5wAA/wAAAAAAAAAAACH5BAEAAAEALAAAAAAoACgAAAPYGLrc/jDKSau9OOvNu19AKIafIxJoioplqL4vyQEwIdw1AWw0fAu52w5D+xlxNeOw0rMdjb6fztJ0PpEp6FJSDQKjqS2kNxigygQ0Do1Om6fc89tNX5vbdPhYnmKb7Xl5Yg00eHSGfipogwyFb3eQh5GPZowgkpiJmgMClgqOmZOibp1xbmWop6h+q5ylEWStkJSzq0ITsX1pWTd3fa6elzkqR1HBwsNWWFnHIMtRUi+vTNFJzysZANe8Nc0PXdLdHQDgOeQt5ObnJY3k7uvs8fLz9PX29/EJADs="
}
In that case response:
{
"ok": false,
"error_code": 400,
"description": "Bad Request: wrong remote file identifier specified: Wrong character in the string"
}
You just had to send request with form-data)

How to send a message via url with inline buttons

I can send message, sample:
https://api.telegram.org/bot[TOKEN]/sendMessage?chat_id=#[USERNAME]&text=hello
but I want to send message with inline buttons, please help.
This would be the url you are looking for:
https://api.telegram.org/bot[TOKEN]/sendMessage?chat_id=[CHAT_ID]&text=[TEXT]&reply_markup={"inline_keyboard": [[{"text": "hi", "callback_data": "hi"}]]}
You can pass a JSON toreply_markup field. Here this our JSON:
{
"inline_keyboard": [
[
{
"text": "hi",
"callback_data": "hi"
}
]
]
}
I suggest you use an API library to communicate with Telegram. Using bare urls has its own challenges, like sometimes you should url encode your JSON to avoid errors in URL.
For example this is the url-encoded version of above JSON:
%7B%22inline_keyboard%22%3A%20%5B%5B%7B%22text%22%3A%20%22hi%22%2C%20%22callback_data%22%3A%20%22hi%22%7D%5D%5D%7D

how to fix 'InvalidRegistration' FCM

I'm getting the InvalidRegistration error in response of my post request for sending push notification.
When I use the Firebase console to send push notification it works all fine.
so I copy the exact registration token I've used in console. I also get my api-key from my project-settings/cloud-messaging.
for sending the post request I've used postman.
I've sent my post request to https://fcm.googleapis.com/fcm/send
my postman header has this attributes:
key: Authorization value: key=<api-key-i-got-from-console>
key: Content-Type value: application/json
my body is:
{
"to" : "fDj8iG5ajZI:APA91bHfs_AjdxOc5Qn-1Plr_OfitrdCTchb4syhPGC0DhPMGiWggJ9mQ5W00ombqowlUSCUOfH_0N3KA-KF0VjQvj5mcMNUMUBgTblpsNzra60kwrbtH2ikfdBa8lenh__olBpGZD4O'",
"collapse_key" : "type_a",
"notification" : {
"body" : "plz work",
"title": "title"
},
}
I get this response from the Firebase
{
"multicast_id": 5801302802423881516,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidRegistration"
}
]
}
I did the same with fcm and django-push-notification and got the same result I have no clue what am I doing wrong since my token works with the console and I can send push notifications from the console.
it was my bad that I had an extra ' in the end of my token...

cannot subscribe to onedrive API

I tried to subscribe to onedrive webhooks by hitting
https://graph.microsoft.com/v1.0/subscriptions
https://graph.microsoft.com/beta/subscriptions
parameters are:
"changeType": "created,updated,deleted",
"notificationUrl": url.
"resource": "me/drive/root",
"clientState": "client-specific string",
"expirationDateTime": "2018-01-01T11:23:00.000Z",
I am getting an error like below:
{ error:
{ code: 'InvalidRequest',
message: 'Server could not process subscription creation payload.',
innerError:
{ 'request-id': 'id',
date: '2018-10-16T09:16:46' } } }
I am trying it in my local.
Is there any solution ?
Make sure you post a json request, that means:
Request body is a json string;
'Content-Type' field in headers, and value is 'application/json'
If you use Python, there is a shortcut:
import requests
url = "https://graph.microsoft.com/beta/subscriptions"
headers = {'Authorization': 'Bearer ' + "YOUR_TOKEN"}
data = {
"changeType": "created,updated,deleted",
"notificationUrl": url.
"resource": "me/drive/root",
"clientState": "client-specific string",
"expirationDateTime": "2018-01-01T11:23:00.000Z"
}
resp = requests.post(headers=headers, json=data)
I had the same problem trying the request with Postman. The body was in x-www-form-urlencoded format. It worked when I changed the body format to raw and specified JSON.
Not working "x-www-form-urlencoded" format
Working "raw" format
It looks like MS Graph API only accepts certain input formats. Hope this will help!

Firebase Cloud Messaging topic send, message does not show in Notifications and is never sent

I am using the REST api and I am trying to send to a topic. I know the topic exists because I can see in the Notification console that the topic is there. And I can send a test message through the console and that works.
However, when I use the REST api, I get an http status 200 response with json {"message_id":8769790390495267408} which looks like a successful send. However, the message does not show up in Notifications and the message is not sent to subscribed clients.
My message looks like, which is from the docs
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
And I am using the "Server key" and not the Web api key.
Thanks for any help.
For iOS, try using notification instead of data. Then add in the priority and set it to high. The payload should look something like this:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"priority": "high",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
}
}