Apple wallet update card from nodejs restify from api to api request

907 views Asked by At

I have implemented apple wallet its generating card first time working fine, now im trying to push new changes to existing card.

When I send push notification for new changes request. I get request for serial number then again I get GET request for updated card. ‘/v1/passes/:passTypeIdentifie/:serialNumber’

I’m using card generation API that generated card first time to serve new changes. Im not sure this good idea but some how it is not working maybe im not doing right in nodejs.

When im sending request from my browser it gives me download myfile.pkpass after download I changed .pkpass extension to zip it doesn’t work shows error “can not open file c:\myfile.zip as archive’ Look like

im not packaging pkpass file right

please help me to find issue Please see below my attached code endpoint

Im using nodejs restify

    routerInstance.get('/v1/passes/:passTypeIdentifie/:serialNumber', async (req, res) => {
    try {
        console.log('Starting pkpass API call');
        const options = {
            hostname: 'localhost',
            //port: 443,
            path: '/api/localapi/passgen/c1',
            method: 'GET'
        }


        const getfile = https.request(options, fileres => {
            console.log(`statusCode: ${fileres.statusCode}`);
            var result = '';

            fileres.on('data', pkpass => {
                result += pkpass.toString();
            });

            fileres.on('end', () => {
                console.log('Response ended');
                res.header('x-timestamp', Date.now());
                res.header('x-sent', true);
                res.header('Content-Type', 'application/vnd.apple.pkpass');
                res.header('Content-disposition', 'attachment; filename=myfile.pkpass');

                res.send(result);
            });

            fileres.on('error', (err) => {
                console.error('Error receiving pkpass', err.toString());
                throw new Error("Error receiving pkpass");
            })

        });
        getfile.on('error', error => {
            console.error('Error making GET call', error);
            throw new Error('Error making GET call');
        })

        getfile.end();
    } catch (ex) {
        console.error('Uncaught PKPASS error', ex.toString());
        res.send('Error');
    }
});

console output :

statusCode: 200


Response ended
 Starting pkpass API call
 statusCode: 200



{"logs":["[2021-02-24 13:41:54 -0800] Get pass task (pass type pass.com.localhost, serial number MB982H, if-modified-since (null); with web service url https:\/\/localhost\/) encountered error: Received invalid pass data (The pass cannot be read because it isn’t valid.)"]}
0

There are 0 answers