Developer – QuarkifiMagIQ
Please refer Sample Code
Code Samples

This section provides sample codes to help understand how to work with MagIQ APIs. Select your choice of technology, prepare the request using the API credentials and get started

Get MagIQ Socket

Fetch MagIQ Socket details. Please follow carefully the instructions provided in sample code before executing

JavaScript
Python
cURL

            const axios = require('axios')
            const crypto = require('crypto')
            
            const apiKey = 'Add your API key here'
            const secretKey = 'Add your Secret Key here'
            
            async function getDevice(deviceId) {
                const timestamp = new Date().toISOString()
                const content = apiKey + timestamp
                const signature = crypto.createHmac('sha256', secretKey).update(content).digest('hex')
            
                const url = `https://api.magiqworks.com/api-ext-magiq/device`
                const headers = {
                    'MQ-TIMESTAMP': timestamp,
                    'MQ-API-KEY': apiKey,
                    'MQ-SIGNATURE': signature,
                }
                const body = {
                    deviceId: deviceId,
                    action: 'GET'
                }
                try {
                    const response = await axios.post(url, body, { headers })
                    return response.data
                } catch(error) {
                    console.error('Error getting device:', error)
                    return null
                }
            }

            // Usage Example
            getDevice('1234567').then(response => {
                console.log('Device found:', response)
            }).catch(error => {
                console.error('Error:', error)
            }) 
          

            import requests
            import hmac
            import hashlib
            import json
            from datetime import datetime, timezone
            
            api_key = 'Add your API key here'
            secret_key = 'Add your secret key here'
            
            # Function to get device
            def get_device(device_id):
                timestamp = datetime.now(timezone.utc).isoformat()
                content = api_key + timestamp
                signature = hmac.new(secret_key.encode(), content.encode(), hashlib.sha256).hexdigest()
            
                url = 'https://api.magiqworks.com/api-ext-magiq/device'
                headers = {
                    'MQ-TIMESTAMP': timestamp,
                    'MQ-API-KEY': api_key,
                    'MQ-SIGNATURE': signature,
                    'Content-Type': 'application/json'
                }
                body = {
                    'deviceId': device_id,
                    'action': 'GET'
                }
            
                try:
                    response = requests.post(url, headers=headers, data=json.dumps(body))
                    response.raise_for_status()
                    return response.json()
                except requests.RequestException as error:
                    print('Error getting device:', error)
                    return None
            
            if __name__ == '__main__':
                device_id = '1234567'
                response = get_device(device_id)
                if response:
                    print('Device found:', response)
                else:
                    print('Error:', response)
          

            apiKey="Add your API key here"
            secretKey="Add your API key here"
            deviceId="12341567"
            
            # Generate timestamp
            timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
            
            # Generate signature
            content="$apiKey$timestamp"
            signature=$(echo -n $content | openssl dgst -sha256 -hmac $secretKey | cut -d " " -f2)
            
            # Get device information
            curl  -X POST "https://api.magiqworks.com/api-ext-magiq/device" \
                  -H "MQ-TIMESTAMP: $timestamp" \
                  -H "MQ-API-KEY: $apiKey" \
                  -H "MQ-SIGNATURE: $signature" \
                  -H "Content-Type: application/json" \
                  -d '{
                        "deviceId": "'"$deviceId"'",
                        "action": "GET"
                      }'
        
Operate MagIQ Socket

Operate MagIQ Socket (turn ON / OFF). Please follow carefully the instructions provided in sample code before executing

JavaScript
Python
cURL

            const axios = require('axios')
            const crypto = require('crypto')
            
            const apiKey = 'Add your API key here'
            const secretKey = 'Add your Secret Key here'
            // Function to turn device on or off
            async function deviceOnOff(deviceId, operation) {
                try {
                   const requestData = {
                        deviceId: deviceId,
                        action: 'SET',
                        device: {
                            deviceId: deviceId,
                            deviceChangeCounter: 10,
                            deviceState: {
                                "switch_1": operation ? '1' : '0'
                            }
                        },
                    }
            
                    const timestamp = new Date().toISOString()
                    const content = apiKey + timestamp
                    const signature = crypto.createHmac('sha256', secretKey).update(content).digest('hex')
            
                    const serviceUrl = `https://api.magiqworks.com/api-ext-magiq/device`
                    const headers = {
                        'MQ-TIMESTAMP': timestamp,
                        'MQ-API-KEY': apiKey,
                        'MQ-SIGNATURE': signature,
                        'Content-Type': 'application/json'
                    }
            
                    try {
                        const postResponse = await axios.post(serviceUrl, requestData, { headers })
                        return postResponse.data
                    } catch(error) {
                        console.error('Error in deviceOnOff:', error)
                        throw error
                    }
            
                } catch(parseError) {
                    console.error('Error parsing device response:', parseError)
                    throw parseError
                }
            }
            
            // Usage Example
            deviceOnOff('1234567', true).then(response => {
                console.log('Device turned on:', response)
            }).catch(error => {
                console.error('Error:', error)
            })
        
   
            import requests
            import hmac
            import hashlib
            import json
            from datetime import datetime, timezone
            
            api_key = 'Add your API key here'
            secret_key = 'Add your secret key here'
            
            # Function to turn device on or off
            def device_on_off(device_id, operation):
                try:
                    timestamp = datetime.now(timezone.utc).isoformat()
                    content = api_key + timestamp 
                    signature = hmac.new(secret_key.encode(), content.encode(), hashlib.sha256).hexdigest()
                    url = 'https://api.magiqworks.com/api-ext-magiq/device'
                    headers = {
                        'MQ-TIMESTAMP': timestamp,
                        'MQ-API-KEY': api_key,
                        'MQ-SIGNATURE': signature,
                        'Content-Type': 'application/json'
                    }
                    request_data = {
                        'deviceId': device_id,
                        'action': 'SET',
                        'device': {
                            'deviceId': device_id,
                            'deviceChangeCounter': 10,
                            'deviceState': {'switch_1': '1' if operation else '0'}
                        }
                    }
                    try:
                        post_response = requests.post(url, headers=headers, data=json.dumps(request_data))
                        post_response.raise_for_status()
                        return post_response.json()
                    except requests.RequestException as error:
                        print('Error in device_on_off:', error)
                        raise error
                except json.JSONDecodeError as parse_error:
                    print('Error parsing device response:', parse_error)
                    raise parse_error
            
            # Usage Example
            if __name__ == '__main__':
                response = device_on_off('1234567', True)
                if response:
                    print('Device turned on:', response)
                else:
                    print('Error:', response)
          

            apiKey="Add your API key here"
            secretKey="Add your Secret key here"
            deviceId="12341567"
            operation="1"
            
            # Generate new timestamp and signature for the update request
            timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
            content="$apiKey$timestamp"
            signature=$(echo -n $content | openssl dgst -sha256 -hmac $secretKey | cut -d " " -f2)
            
            # Update device state
            curl  -X POST "https://api.magiqworks.com/api-ext-magiq/device" \
                  -H "MQ-TIMESTAMP: $timestamp" \
                  -H "MQ-API-KEY: $apiKey" \
                  -H "MQ-SIGNATURE: $signature" \
                  -H "Content-Type: application/json" \
                  -d '{
                        "deviceId": "'"$deviceId"'",
                        "action": "SET",
                        "device": {
                          "deviceId": "'"$deviceId"'",
                          "deviceChangeCounter": 10,
                          "deviceState": "'"$operation"'"
                        }
                      }'    
        
Get All MagIQ Sockets

Fetch details of all MagIQ Sockets in your account. Please follow carefully the instructions provided in sample code before executing

JavaScript
Python
cURL

            const axios = require('axios')
            const crypto = require('crypto')
            
            const timestamp = new Date().toISOString()
            const apiKey = 'Add your API key here'
            const secretKey = 'Add your Secret Key here'
            
            const content = apiKey + timestamp
            
            const signature = crypto.createHmac('sha256', secretKey)
                .update(content)
                .digest('hex')
            
                console.log('signature is : ', signature, timestamp)
            
            const url = 'https://api.magiqworks.com/api-ext-magiq/device'
            const headers = {
                'MQ-TIMESTAMP': timestamp,
                'MQ-API-KEY': apiKey,
                'MQ-SIGNATURE': signature,
            }
            
            const body = {
                action: 'GET'
            }
            
            axios.post(url, body, { headers })
                .then(response => {
                    console.log(response.data)
                })
                .catch(error => {
                    console.error(error)
                })
            

            import requests
            import json
            import hashlib
            import hmac
            from datetime import datetime, timezone
            
            api_key = 'Add your API key here'
            secret_key = 'Add your Secret key here'
            
            # Get the current UTC time and format it properly
            timestamp = datetime.now(timezone.utc).isoformat()
            content = api_key + timestamp
            signature = hmac.new(secret_key.encode(), content.encode(), hashlib.sha256).hexdigest()`
            
            url = 'https://api.magiqworks.com/api-ext-magiq/device'
            headers = {
                'MQ-TIMESTAMP': timestamp,
                'MQ-API-KEY': api_key,
                'MQ-SIGNATURE': signature,
                'Content-Type': 'application/json'
            }
            
            body = {
                "action": "GET"
            }
            
            response = requests.post(url, data=json.dumps(body), headers=headers)
            
            # Handle response appropriately
            try:
                response_data = response.json()
                print(response_data)
            except json.JSONDecodeError:
                print(f"Failed to parse response: {response.text}")
          

            timestamp=$(date -u +"%T %d-%m-%Y GMT")
            echo "Timestamp: $timestamp"
            
            apiKey="Add your API key here"
            secretKey="Add your Secret key here"
            
            message="$apiKey$timestamp"
            echo "Message: $message"
            
            signature=$(echo -n "$message" | openssl dgst -sha256 -hmac $secretKey | cut -d' ' -f2)
            echo "Generated Signature: $signature"
            
            url="https://api.magiqworks.com/api-ext-magiq/device"
            curl -X POST "$url" \
              -H "MQ-TIMESTAMP: $timestamp" \
              -H "MQ-API-KEY: $apiKey" \
              -H "MQ-SIGNATURE: $signature" \
              -H "Content-Type: application/json" \
              -d '{
                "action": "GET"
            }'
        
Get Schedules

Fetch details of all Schedules created for MagIQ Sockets in your account. Please follow carefully the instructions provided in sample code before executing

JavaScript
Python
cURL

            const axios = require('axios')
            const crypto = require('crypto')
            
            const apiKey = 'Add your API key here'
            const secretKey = 'Add your Secret key here'
            const propertyId = 'Add your propertyId, You can find in "device object" (getDevice)'
            
            async function getRules() {
              try {
                const requestData = {
                  action: 'GET',
                  version: 'v2',
                  propertyId: propertyId,
                }
            
                const timestamp = new Date().toISOString()
                const content = apiKey + timestamp
                const signature = crypto.createHmac('sha256', secretKey).update(content).digest('hex')
                const serviceUrl = `https://api.magiqworks.com/api-ext-magiq/rules`
                const headers = {
                  'MQ-TIMESTAMP': timestamp,
                  'MQ-API-KEY': apiKey,
                  'MQ-SIGNATURE': signature,
                  'Content-Type': 'application/json'
                }
                try {
                  const postResponse = await axios.post(serviceUrl, requestData, { headers })
                  return postResponse.data
                } catch(error) {
                  console.error('Error in getRules:', error)
                  throw error
                }
              } catch(parseError) {
                console.error('Error parsing device response:', parseError)
                throw parseError
              }
            }
            
            // Usage Example
            getRules().then(response => {
              console.log('Rules are :', response)
            }).catch(error => {
              console.error('Error:', error)
            })
          
   
            import requests
            import hashlib
            import hmac
            import json
            from datetime import datetime, timezone
            
            api_key = 'Add your API key here'
            secret_key = 'Add your Secret key here'
            property_id = 'Add your propertyId, You can find in "device object" (getDevice)'
            
            def get_rules():
                requestData = {
                    'action': 'GET',
                    'version': 'v2',
                    'propertyId': property_id,
                }
            
                timestamp = datetime.now(timezone.utc).isoformat()
                content = api_key + timestamp
                signature = hmac.new(secret_key.encode(), content.encode(), hashlib.sha256).hexdigest()
                serviceUrl = 'https://api.magiqworks.com/api-ext-magiq/rules'
                headers = {
                    'MQ-TIMESTAMP': timestamp,
                    'MQ-API-KEY': api_key,
                    'MQ-SIGNATURE': signature,
                    'Content-Type': 'application/json'
                }
            
                try:
                    response = requests.post(serviceUrl, headers=headers, data=json.dumps(requestData))
                    response.raise_for_status()
                    return response.json()
                except requests.RequestException as error:
                    print(f'Error in getRules: {error}')
                    raise
            
            # Usage Example
            try:
                response = get_rules()
                print(response)
            except Exception as error:
                print('Error:', error)
            

            apiKey="Add your API key here"
            secretKey="Add your Secret key here"
            propertyId="Add your propertyId, You can find in "device object" (getDevice)"
            
            timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
            content="${apiKey}${timestamp}"
            signature=$(echo -n "$content" | openssl dgst -sha256 -hmac "$secretKey" | cut -d' ' -f2)
            
            url="https://api.magiqworks.com/api-ext-magiq/rules"
            curl  -X POST $url \
                  -H "MQ-TIMESTAMP: $timestamp" \
                  -H "MQ-API-KEY: $apiKey" \
                  -H "MQ-SIGNATURE: $signature" \
                  -H "Content-Type: application/json" \
                  -d '{
                    "action": "GET",
                    "version": "v2",
                    "propertyId": "'$propertyId'"
                  }'
          
Add Schedule

Create Schedules for MagIQ Sockets. Please follow carefully the instructions provided in sample code before executing

JavaScript
Python
cURL

            const axios = require('axios')
            const crypto = require('crypto')
            
            const apiKey = 'Add your API key here'
            const secretKey = 'Add your Secret key here'
            const propertyId = 'Add your propertyId, You can find in "device object" (getDevice)'
            
            async function addRule({
              deviceId,
              time,
              days,
              repeat,
              active,
              name,
              deviceAction,
            }) {
              const requestData = {
                action: 'ADD',
                version: 'v2',
                type: 0,
                rules: [
                  {
                    propertyId: propertyId,
                    period: 0,
                    time: time,
                    days: days,
                    endpoint: `${deviceId}.switch_1`,
                    startAction: [
                      {
                        deviceId: deviceId,
                        deviceState: {
                          switch_1: deviceAction ? '1' : '0',
                        },
                      },
                    ],
                    ruleId: `timedRule_${Date.now()}_${time}`,
                    ruleName: name,
                    active: active,
                    repeat: repeat,
                  },
                ],
              }
            
              const timestamp = new Date().toISOString()
              const content = apiKey + timestamp
              const signature = crypto.createHmac('sha256', secretKey).update(content).digest('hex')
            
              const serviceUrl = 'https://api.magiqworks.com/api-ext-magiq/rules'
              const headers = {
                'MQ-TIMESTAMP': timestamp,
                'MQ-API-KEY': apiKey,
                'MQ-SIGNATURE': signature,
                'Content-Type': 'application/json',
              }
            
              try {
                const postResponse = await axios.post(serviceUrl, requestData, { headers })
                return postResponse.data
              } catch (error) {
                console.error('Error in adding rule:', error)
                throw error
              }
            }
            
            // Usage Example
            addRule({
              deviceId: '1234567',
              time: '07:15',
              days: '1111111',
              repeat: true,
              active: true,
              name: 'Off garden light',
              deviceAction: false,
            })
              .then(response => {
                console.info( response)
              })
              .catch(error => {
                console.error('Error:', error)
              })
          
   
            import hashlib
            import hmac
            import json
            from datetime import datetime, timezone
            
            api_key = 'Add your API key here'
            secret_key = 'Add your Secret key here'
            property_id = 'Add your propertyId, You can find in "device object" (getDevice)'
            
            def add_rule(device_id, time, days, repeat, active, name, device_action):
                request_data = {
                    "action": "ADD",
                    "version": "v2",
                    "type": 0,
                    "rules": [
                        {
                            "propertyId": property_id,
                            "period": 0,
                            "time": time,
                            "days": days,
                            "endpoint": f"{device_id}.switch_1",
                            "startAction": [
                                {
                                    "deviceId": device_id,
                                    "deviceState": {
                                        "switch_1": '1' if device_action else '0'
                                    }
                                }
                            ],
                            "ruleId": f"timedRule_{int(datetime.now(timezone.utc).timestamp() * 1000)}_{time}",
                            "ruleName": name,
                            "active": active,
                            "repeat": repeat
                        }
                    ]
                }
            
                timestamp = datetime.now(timezone.utc).isoformat()
                content = api_key + timestamp
                signature = hmac.new(secret_key.encode(), content.encode(), hashlib.sha256).hexdigest()
            
                service_url = 'https://api.magiqworks.com/api-ext-magiq/rules'
                headers = {
                    'MQ-TIMESTAMP': timestamp,
                    'MQ-API-KEY': api_key,
                    'MQ-SIGNATURE': signature,
                    'Content-Type': 'application/json'
                }
            
                try:
                    response = requests.post(service_url, headers = headers, data = json.dumps(request_data))
                    response.raise_for_status()
                    return response.json()
                except requests.exceptions.RequestException as e:
                    print(f'Error in adding rule: {e}')
                    raise
            
            # Usage Example
            try:
                response = add_rule(
                    device_id= '14898339',
                    time = '07:37',
                    days = '1111111',
                    repeat = True,
                    active = True,
                    name = 'garden lights off',
                    device_action = False
                )
                print( response )
            except Exception as e:
                print('Error:', e)
            

            apiKey="Add your API key here"
            secretKey="Add your Secret key here"
            propertyId="Add your propertyId, You can find in "device object" (getDevice)"
            
            DEVICE_ID = "1234567"
            TIME = "09:29"
            DAYS = "1111111"
            REPEAT = false
            ACTIVE = true
            NAME = "Rule name"
            DEVICE_STATE = "1" 
            
            REQUEST_DATA=$(printf '{
                "action": "ADD",
                "version": "v2",
                "type": 0,
                "rules": [
                    {
                        "propertyId": "%s",
                        "period": 0,
                        "time": "%s",
                        "days": "%s",
                        "endpoint": "%s.switch_1",
                        "startAction": [
                            {
                                "deviceId": "%s",
                                "deviceState": {
                                    "switch_1": "%s"
                                }
                            }
                        ],
                        "ruleId": "timedRule_%s_%s",
                        "ruleName": "%s",
                        "active": %s,
                        "repeat": %s
                    }
                ]
            }' "$propertyId" "$TIME" "$DAYS" "$DEVICE_ID" "$DEVICE_ID" "$DEVICE_STATE" "$(date +%s%3N)" "$TIME" "$NAME" "$ACTIVE" "$REPEAT")
            
            timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
            content="${apiKey}${timestamp}"
            signature=$(echo -n "$content" | openssl dgst -sha256 -hmac "$secretKey" |  cut -d " " -f2)
            
            curl -X POST "https://api.magiqworks.com/api-ext-magiq/rules" \
                 -H "MQ-TIMESTAMP: $timestamp" \
                 -H "MQ-API-KEY: $apiKey" \
                 -H "MQ-SIGNATURE: $signature" \
                 -H "Content-Type: application/json" \
                 -d "$REQUEST_DATA"
          
Modify Schedule

Modify Schedules for MagIQ Sockets. Please follow carefully the instructions provided in sample code before executing

JavaScript
Python
cURL

            const axios = require('axios')
            const crypto = require('crypto')
            
            const apiKey = 'Add your API key here'
            const secretKey = 'Add your Secret key here'
            const propertyId = 'Add your propertyId, You can find in "device object" (getDevice)'
            
            async function addRule({
              deviceId,
              time,
              days,
              repeat,
              active,
              name,
              deviceAction,
              ruleId
            }) {
              const requestData = {
                action: 'MOD',
                version: 'v2',
                type: 0,
                rules: [
                  {
                    propertyId: propertyId,
                    period: 0,
                    time: time,
                    days: days,
                    endpoint: `${deviceId}.switch_1`,
                    startAction: [
                      {
                        deviceId: deviceId,
                        deviceState: {
                          switch_1: deviceAction ? '1' : '0',
                        },
                      },
                    ],
                    ruleId: ruleId,
                    ruleName: name,
                    active: active,
                    repeat: repeat,
                  },
                ],
              }
            
              const timestamp = new Date().toISOString()
              const content = apiKey + timestamp
              const signature = crypto.createHmac('sha256', secretKey).update(content).digest('hex')
            
              const serviceUrl = 'https://api.magiqworks.com/api-ext-magiq/rules'
              const headers = {
                'MQ-TIMESTAMP': timestamp,
                'MQ-API-KEY': apiKey,
                'MQ-SIGNATURE': signature,
                'Content-Type': 'application/json',
              }
            
              try {
                const postResponse = await axios.post(serviceUrl, requestData, { headers })
                return postResponse.data
              } catch(error) {
                console.error('Error in adding rule:', error)
                throw error
              }
            }
            
            // Usage Example
            addRule({
              deviceId: '1234567',
              time: '09:41',
              days: '1111111',
              repeat: false,
              active: true,
              name: 'Rule Name',
              deviceAction: false,
              ruleId: 'timedRule_1718198786872_09:29'
            })
              .then(response => {
                console.info( response)
              })
              .catch(error => {
                console.error('Error:', error)
              })
          
   
            import requests
            import hashlib
            import hmac
            import json
            from datetime import datetime, timezone
            
            api_key = 'Add your API key here'
            secret_key = 'Add your Secret key here'
            property_id = 'Add your propertyId, You can find in "device object" (getDevice)'
            
            def add_rule(device_id, time, days, repeat, active, name, device_state, ruleId):
                request_data = {
                    "action": "MOD",
                    "version": "v2",
                    "type": 0,
                    "rules": [
                        {
                            "propertyId": property_id,
                            "period": 0,
                            "time": time,
                            "days": days,
                            "endpoint": f"{device_id}.switch_1",
                            "startAction": [
                                {
                                    "deviceId": device_id,
                                    "deviceState": {
                                        "switch_1": '1' if device_state else '0'
                                    }
                                }
                            ],
                            "ruleId": ruleId,
                            "ruleName": name,
                            "active": active,
                            "repeat": repeat
                        }
                    ]
                }
            
                timestamp = datetime.now(timezone.utc).isoformat()
                content = api_key + timestamp
                signature =  hmac.new(secret_key.encode(), content.encode(), hashlib.sha256).hexdigest()
            
                service_url = 'https://api.magiqworks.com/api-ext-magiq/rules'
                headers = {
                    'MQ-TIMESTAMP': timestamp,
                    'MQ-API-KEY': api_key,
                    'MQ-SIGNATURE': signature,
                    'Content-Type': 'application/json'
                }
            
                try:
                    response = requests.post(service_url, headers=headers, data=json.dumps(request_data))
                    response.raise_for_status()
                    return response.json()
                except requests.exceptions.RequestException as e:
                    print(f'Error in adding rule: {e}')
                    raise
            
            # Usage Example
            try:
                response = add_rule(
                    device_id='1234567',
                    time='12:45',
                    days='1111111',
                    repeat=True,
                    active=True,
                    name='Rule name',
                    device_state=False,
                    ruleId='timedRule_1718179875163_09:08'
                )
                print('Rules are:', response)
            except Exception as e:
                print('Error:', e)
            

            apiKey="Add your API key here"
            secretKey="Add your Secret key here"
            propertyId="Add your propertyId, You can find in "device object" (getDevice)"
            
            DEVICE_ID="1234567"
            TIME="09:29"
            DAYS="1111111"
            REPEAT=true
            ACTIVE=true
            NAME="Rule name"
            DEVICE_STATE="1"
            RULE_ID="timedRule_171816546163_09:08"
            
            REQUEST_DATA=$(printf '{
                "action": "MOD",
                "version": "v2",
                "type": 0,
                "rules": [
                    {
                        "propertyId": "%s",
                        "period": 0,
                        "time": "%s",
                        "days": "%s",
                        "endpoint": "%s.switch_1",
                        "startAction": [
                            {
                                "deviceId": "%s",
                                "deviceState": {
                                    "switch_1": "%s"
                                }
                            }
                        ],
                        "ruleId": "%s",
                        "ruleName": "%s",
                        "active": %s,
                        "repeat": %s
                    }
                ]
            }' "$propertyId" "$TIME" "$DAYS" "$DEVICE_ID" "$DEVICE_ID" "$DEVICE_STATE" "$RULE_ID" "$NAME" "$ACTIVE" "$REPEAT")
            
            timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
            content="${apiKey}${timestamp}"
            signature=$(echo -n "$content" | openssl dgst -sha256 -hmac "$secretKey" |  cut -d " " -f2)
            
            curl -X POST "https://api.magiqworks.com/api-ext-magiq/rules" \
                -H "MQ-TIMESTAMP: $timestamp" \
                -H "MQ-API-KEY: $apiKey" \
                -H "MQ-SIGNATURE: $signature" \
                -H "Content-Type: application/json" \
                -d "$REQUEST_DATA"
          
Remove Schedule(s)

Remove Schedules for MagIQ Sockets. Please follow carefully the instructions provided in sample code before executing

JavaScript
Python
cURL

              const axios = require('axios')
              const crypto = require('crypto')
              
              const apiKey = 'Add your API key here'
              const secretKey = 'Add your Secret key here'
              
              async function DeleteRule(removeRules) {
                try {
                  const requestData = {
                    action: 'DEL',
                    version: 'v2',
                    rules: removeRules,
                  }
              
                  const timestamp = new Date().toISOString()
                  const content = apiKey + timestamp
                  const signature = crypto.createHmac('sha256', secretKey).update(content).digest('hex')
              
                  const serviceUrl = `https://api.magiqworks.com/api-ext-magiq/rules`
                  const headers = {
                    'MQ-TIMESTAMP': timestamp,
                    'MQ-API-KEY': apiKey,
                    'MQ-SIGNATURE': signature,
                    'Content-Type': 'application/json',
                  }
                  try {
                    const postResponse = await axios.post(serviceUrl, requestData, {
                      headers,
                    })
                    return postResponse.data
                  } catch (error) {
                    console.error('Error in Delete Rule:', error)
                    throw error
                  }
                } catch (parseError) {
                  console.error('Error parsing device response:', parseError)
                  throw parseError
                }
              }
              
              // array of rule object to delete (use getRules for rule object)
              const removeRules = [{}]
              
              // Usage Example
              DeleteRule(removeRules)
                .then(response => {
                  console.info( response )
                })
                .catch(error => {
                  console.error('Error:', error)
                })
            
   
              import requests
              import hashlib
              import hmac
              import json
              from datetime import datetime, timezone
              
              api_key = 'Add your API key here'
              secret_key = 'Add your Secret key here'
              
              def delete_rule(remove_rules):
                  requestData = {
                      'action': 'DEL',
                      'version': 'v2',
                      'rules': remove_rules
                  }
              
                  timestamp = datetime.now(timezone.utc).isoformat()
                  content = api_key + timestamp
                  signature = hmac.new(secret_key.encode(), content.encode(), hashlib.sha256).hexdigest()
              
                  serviceUrl = 'https://api.magiqworks.com/api-ext-magiq/rules'
                  headers = {
                      'MQ-TIMESTAMP': timestamp,
                      'MQ-API-KEY': api_key,
                      'MQ-SIGNATURE': signature,
                      'Content-Type': 'application/json'
                  }
              
                  try:
                      response = requests.post(serviceUrl, headers=headers, data=json.dumps(requestData))
                      response.raise_for_status()
                      return response.json()
                  except requests.RequestException as error:
                      print(f'Error in Delete Rule: {error}')
                      raise
              
              # array of rule object to delete (use getRules for rule object)
              removeRules = [{}]
              
              # Usage Example
              try:
                  response = delete_rule(removeRules)
                  print('Rules are:', response)
              except Exception as error:
                  print('Error:', error)
              

              apiKey="Add your API key here"
              secretKey="Add your Secret key here"
              
              timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
              content="${apiKey}${timestamp}"
              signature=$(echo -n "$content" | openssl dgst -sha256 -hmac "$secretKey" | cut -d' ' -f2)
              
              # array of rule object to delete (use getRules for rule object)
              removeRules='[{}]'
              
              serviceUrl="https://api.magiqworks.com/api-ext-magiq/rules"
                curl  -X POST $serviceUrl \
                      -H "MQ-TIMESTAMP: $timestamp" \
                      -H "MQ-API-KEY: $apiKey" \
                      -H "MQ-SIGNATURE: $signature" \
                      -H "Content-Type: application/json" \
                      -d '{
                        "action": "DEL",
                        "version": "v2",
                        "rules": '$removeRules'
                      }'
            
Most 'smart' technologies in the past meant a substantial change in habits or systems in India to suit the technology since they were essentially imparted from the Western world. Quarkifi’s promoters want to change that for good 'making technology adapt to you' and not the other way around. Towards that goal, Quarkifi has led the way in bringing the following firsts to the Indian context
  • first 'true' hub-less smart space automation
  • first voice control with support for all major Indian languages
  • first cloud-less device-to-device communication
Taking a step forward, we wish to open up the platform to a community of enthusiastic developers, allowing them to build their own solutions around the platform and take advantage of its capabilities.

We welcome you to explore the possibilities
Code copied to clipboard!