
// JavaScript Document
exports.onesignal_view_user_identity_by_sub = async function (options) {
    // get appid
    const appid = this.parseOptional(options.appid, '*', process.env.ONESIGNAL_APP_ID)
    console.log(options.appid + " => " + appid)

    const subscription_id = this.parseRequired(options.subscription_id, '*', 'No Subscription ID specified')
    console.log(options.subscription_id + " => " + subscription_id)

    const fetch = require('node-fetch');

    const url = `https://api.onesignal.com/apps/${appid}/subscriptions/${subscription_id}/user/identity`;
    const os_options = { method: 'GET', headers: { accept: 'application/json' } };

    return fetch(url, os_options)
        .then(res => {

            return res.json().then(json => {
                json.status = res.status; // Add status to json response
                return json;
            });
        })
        .catch(err => console.error('Error:', err));

}





