#!/bin/bash

# EveryonePrint Customer Support
#
# This is a sample bash script using HCP API with CURL to add user(s)


echo -e " \e[1;32;22m     ***********************************************************************************
      *                                                                                 *
      *           Hybrid Cloud Platform - API Automation Tool                           *    
      *                                                                                 *
      ***********************************************************************************\e[m"

# note: API Key is hardcoded for HCP 2.5.x version
XAPIKey="46405b18-8e1b-4db9-b930-bedd9ae839af"


#************************************************************************
#                                                                       *
#             CHANGE HCP ACCOUNT DOMAIN NAME - MUST DO                  *
#                                                                       *
#************************************************************************

hcpserver="swaptest.eu.eophcp.com"


#************************************************************************
#                                                                       *
#            CHANGE .CSV FILE NAME - COUNT THE COLUMNS                  *
#                                                                       *
#************************************************************************


# CSV file name
#INPUT=./users.csv
INPUT=./usr.csv




OLDIFS=$IFS
IFS=";"

    # Type of the user detail to add: 0=full name, 1=email, 3=password, 4=cardid, 5=shortid, 6=pin, 7=alias
    #************************************************************************
    #                                                                       *
    #            UPDATE COLUMN DETAILS - SCRIPT WILL READ LIKEWISE          *
    #                                                                       *
    #************************************************************************

    [ ! -f $INPUT2 ] &while read UserName CardNo
    do
    
        ######### UPDATE CARD NUMBER TO EXISTING USERS ###########  
        echo -e " \e[1;32;22m Adding Card No: $CardNo \e[m"
        echo -e " \e[1;32;22m User Name: $UserName \e[m"
        CardNo=$(echo $CardNo | sed -e 's/\r//g')
        curl -X POST -i -H "X-Api-Key: $XAPIKey" -H "X-Account-Domain: $hcpserver" -d detailtype=4 -d "detaildata=$CardNo" -k "https://$hcpserver:7300/api/v1/users/$UserName"

    done < $INPUT
    IFS=$OLDIFS
    

echo -e " \e[1;32;22m $counter Card details from the CSV file has been updated. Please check USER details in HCP console --> https://"$hcpserver":8443 \e[m"



