I'm trying to use the backpack-connect API to push badges to a user's backpack. The example in the open badges documentation uses node.js.
My question is: Do I have to use node.js or is it possible to write something equivalent to this in php? I'm not asking for someone to write it, just to say:
- If it is possible.
- If i'm missing the point, or have a fundamental misunderstanding.
I have some experience coding in php and js, and have dipped into other apis with success (eg. linkedin), I'm finding this one difficult because of a lack of practical examples or helpful info (there's plenty of conceptual fluff talk, but little in the way of implementation examples).
The node.js example from the moz docs is as follows:
var assertionData = querystring.stringify({
badge: 'http://yoursite.com/badge-assertion.json'
});
var requestOptions = {
host : 'backpack.openbadges.org',//adjust for your api root
path : '/api/issue',
method : 'POST',
headers: { 'Authorization': 'Bearer ' + b64enc('your-access-token'),
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(assertionData)
}
};
var postRequest = http.request(requestOptions, function(pushResponse) {
var response = [];
pushResponse.setEncoding('utf8');
//store data
pushResponse.on('data', function (responseData) {
response.push(responseData);
});
pushResponse.on('end', function(){
var pushData=JSON.parse(response.join(''));
//...
});
});
postRequest.on('error', function(e) {
console.error(e);
});
// post the data
postRequest.write(assertionData);
postRequest.end();
Can I forget about node.js and just do this via PHP?
Thanks for any help!