MigaPushApi

On Agosto 1, 2022, Posted by , In Italiano, With Commenti disabilitati su MigaPushApi

Il funzionamento di questo modulo è semplice ed estremamente utile.

Grazie all’utilizzo di due specifiche API consente ad applicazioni esterne di inviare:

  • notifiche push a singoli utenti di una app tramite l’indirizzo email di registrazione
  • l’elenco degli utenti registrati di una specifica app della tua piattaforma siberian

Impostazioni

Una volta installato il modulo, Il pannello delle impostazioni è raggiungibile dal frontend dell’app builder. Dal menu verticale a sinistra, sezione Moduli, fai clic su Miga Push Api.

Da questa schermata l’unica scelta da effettuare è il numero massimo di push per minuto.

Note:

  • API URL For Send Individual Push da utilizzare con post request, i cinque campi {`app_id`, `token`, `message`, `subject`, ‘email’} sono obbligatori ma “email” è il più importante.
  • API URL Get Users List da utilizzare con post request, i due campi {`app_id`, `token`} sono obbligatori.

User List

Description

Fetch all the users available for sending Push notifications.

$endpoint = "https://www.domain.com/migapushapi/public_apiusers/init"

Request

ParamType
app_idint
tokenstring

Response

{
    “error”: null,
    “data”: [
        {
            “email”: “user.com”,
            “firstname”: “user”,
            “lastname”: “x”
        },
        {
            “email”: “user2.com”,
            “firstname”: “user2”,
            “lastname”: “x”
        }
    ]
}

 

Example

 

Send Individual Push

Description

Sends an individual push notification via user email.

$endpoint = "http://www.domain.com/migapushapi/public_api/init"

Request

ParamTypeDetails
subject *stringPush title
message *stringPush message
app_id *int
token *string
email *string
devicesstringallandroidios
open_urlintIf set to 1 url will be opened in app
urlstringAlong with open_url set to 1, the url to open
coverstringbase64 encoded image to display as a cover, must be png or jpg

 

Cover Image BASE64 Conversion Steps.

  • Go to BASE64 Conversion link
  • Choose a cover image (jpg, png)
  • Select output type format (Data URI — data:content/type;base64)
  • Click on encode image button.

ESEMPIO IMPLEMENTAZIONE PHP

For Get User List

<?php

$url = ‘https://domain.com/migapushapi/public_apiusers/init’;
    $data = array(
        “app_id” => “11”,
        “token” => “c89222798a03a0c7efdb851ec38…….”,
    );
    $curlHandler = curl_init();
    curl_setopt_array($curlHandler, [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        /**
        * Specify POST method
        */
        CURLOPT_POST => true,
        /**
        * Specify request content
        */
        CURLOPT_POSTFIELDS => $data,
    ]);
    $response = curl_exec($curlHandler);
    curl_close($curlHandler);
    echo($response);

?>

 

For Send Push Notification

<?php

    $url = “https://domain.com/migapushapi/public_api/init”;
    $data = array(
        “app_id” => “11”,
        “token” => “c892227…….”,
        “message” => “Message……”,
        “subject” => “Subject……..”,
        “email” => “email@gmail.com”,
        “devices” => “android”,
        “open_url”=>1,
        “url” => “https://domain.com/api/push/”,
        “cover”=>”data:image/png;base64,iVBORw0KGgoAAAANSUhE……………..”
    );
    $curlHandler = curl_init();
    curl_setopt_array($curlHandler, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    /**
    * Specify POST method
    */
    CURLOPT_POST => true,
    /**
    * Specify request content
    */
    CURLOPT_POSTFIELDS => $data,
    ]);
    $response = curl_exec($curlHandler);
    curl_close($curlHandler);
    echo($response);

?>

ESEMPIO IMPLEMENTAZIONE Javascript

For Get User List

    <script>
        $.ajax({
            url: “https://domain.com/migapushapi/public_apiusers/init”,
            type: “post”,
            data: {
                “app_id”: “11”,
                “token”: “c89222798a03a……”
            } ,
            success: function (response) {
                console.log(response);
            },
            error: function(jqXHR, textStatus, errorThrown) {
            console.log(textStatus, errorThrown);
            }
        });
    </script>
For Send Push Notification
<script>
    $.ajax({
        url: “https://domain.com/migapushapi/public_apiusers/init”,
        type: “post”,
        data: {
            “app_id” : “11”,
            “token” : “c892227…….”,
            “message” : “Message……”,
            “subject” : “Subject……..”,
            “email” : “email@gmail.com”,
            “devices” : “android”,
            “open_url” :1,
            “url” : “https://domain.com/api/push/”,
            “cover”:”data:image/png;base64,iVBORw0KGgoAAAANSUhE……………..”
        },
        success: function (response) {
            console.log(response);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.log(textStatus, errorThrown);
        }
    });
</script>

Success Response

{
    “success”: true,
    “response”: 1
}

 

All Response

ResponseDetails
1Successful
0Wrong/Missing Token
2App ID is missing
3Email is missing”
4Email User hasn’t a push token
5Message field is empty
6Subject is missing
7Url is missing (if field OpenUrl is 1 value and Url is empty)
8Wrong Cover Image base64 encoded image to display as a cover, must be png or jpg
9Invalid Request
10Invalid Parameter(s) Found.
11Already user send max push plz wait one minute
12Email does not exists

 

Example

LINK: https://support.migastone.com/it/hrf_faq/migapushapi-2/