I am not a professional programmer. I manage with PHP and Javascript, but I am having a hard time converting Pushwoosh methods to functional PHP or Javascript. This is the method that I need help converting:
Method /setTags
Set tags values for device
Request:
{
"request":{
"application":"DEAD0-BEEF0",
"hwid": 'device hardware id',
"tags": {
"tag1": "string value",
"tag2": 42,
"tag3": "string",
"tag4": 3.14
}
}
}
This is how they post their methods. Any help with this?
I wrote a PHP to setTags but I could not verify it yet as I am still working on retrieving the Token. I have a question on that on this link:
Phonegap/Pushwoosh Android retrieving Device id / Token
this is my PHP for setTags. Does this look right using JSON? (I am running late on my project!)
<?php
define('PW_AUTH', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('PW_APPLICATION', 'xxxxxxxxxx');
define('HW_ID', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
function doPostRequest($url, $data, $optional_headers = null) {
$params = array(
'http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null)
$params['http']['header'] = $optional_headers;
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp)
throw new Exception("Problem with $url, $php_errmsg");
$response = @stream_get_contents($fp);
if ($response === false)
return false;
return $response;
}
function pwCall( $action, $data = array() ) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $action;
$json = json_encode( array( 'request' => $data ) );
$res = doPostRequest( $url, $json, 'Content-Type: application/json' );
print_r( @json_decode( $res, true ) );
}
pwCall( 'setTags', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'hwid' => HW_ID,
'tags' => array(
array(
'tag1' => 'string value',
'tag2' => 42,
'tag3' => 'string',
'tag4' => 3.14
)
)
)
);
?>
you do not need to convert this JSON to send tags to Pushwoosh. It’s being sent directly from the device to the Pushwoosh server.