ENDPOINT = "https://cp.pushwoosh.com/json/1.3"
API_KEY = "" # Put your API Key here
APP_CODE = "" # Put the application code here
def bulkSetTags(hwids=None, name=None, value=None):
Function to set tags in bulk via polling /bulkSetTags API:
https://docs.pushwoosh.com/platform-docs/api-reference/tags#bulksettags
:param hwids – array of hardware IDs
:param name – name of the tag
:param value - value of the tag
returns JSON with the response
if hwids is not None and name is not None and value is not None:
request = {"request": {"auth": API_KEY, "application": APP_CODE, "devices": []}}
request["request"]["devices"].append({"hwid": hwid, "tags": {name: value}})
url = "{}/bulkSetTags".format(ENDPOINT)
print("Url: {}\nDATA:{}".format(url, json.dumps(request)))
response = requests.post(url, data=json.dumps(request))
if response.status_code == 200:
parser = argparse.ArgumentParser(
description="Bulk set tags via CSV. Usage: bulksettags.py file.csv tag_name tag_value"
help="CSV file name in current directory with the list of HWIDs, assuming hwid in first column",
parser.add_argument("tag_name", help="name of the tag to update")
parser.add_argument("tag_value", help="value of the tag to set")
args = parser.parse_args()
args.csv_location is not None
and args.tag_name is not None
and args.tag_value is not None
with open(args.csv_location) as f:
# read list of HWIDs from input CSV and split it into batches of 1000 devices
rows = csv.reader(f, delimiter=",", quotechar='"')
# if we have already 1000 hwids, let's send the request
r = bulkSetTags(hwids=hwids, name=args.tag_name, value=args.tag_value)