Skip to content

Commit

Permalink
update query dynamic system
Browse files Browse the repository at this point in the history
  • Loading branch information
NahumDEV committed Mar 1, 2024
1 parent f38933b commit 82fbc40
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
26 changes: 22 additions & 4 deletions lambda_handlers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,36 @@

def handle_history(event, context):
# Logic for /servicenow/history
url = f"{ENVIRONMENT_VARIABLES['API_URL']}/sysapproval_approver?sysparm_limit=10"

query_params = event.get('queryStringParameters', {})
url = f"{ENVIRONMENT_VARIABLES['API_URL']}/table/sysapproval_approver"
query_params = event.get('queryStringParameters', {})
params = {
'sysparm_limit': 10,
'sysparm_display_value': True,
'sysparm_query': ""
}

if query_params:
sysparm_limit = query_params.get('sysparm_limit')
sysparm_display_value = query_params.get('sysparm_display_value')
sysparm_query = query_params.get('sysparm_query')

if sysparm_limit:
params['sysparm_limit'] = sysparm_limit
if sysparm_display_value:
params['sysparm_display_value'] = sysparm_display_value
if sysparm_query:
params['sysparm_query'] = sysparm_query

try:
response = requests.get(
url,
params=params,
auth=HTTPBasicAuth(ENVIRONMENT_VARIABLES['USERNAME'], ENVIRONMENT_VARIABLES['PASSWORD'])
)
response.raise_for_status() # Raise an exception for bad responses (4xx, 5xx)
response.raise_for_status()

data = response.json()
# Process the data as needed
print(data)

return {
Expand Down
13 changes: 11 additions & 2 deletions lambda_handlers/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ def handle_item(event, context):
'statusCode': 400,
'body': json.dumps({'error': 'Invalid request'})
}
item_id = event['path'].split('/')[-1]

url = ""
query_params = event.get('queryStringParameters', {})
# Logic for /servicenow/item/<item_id>
url = f"{ENVIRONMENT_VARIABLES['API_URL']}/x_rnod_csod_serv_0_service_ops_request/{item_id}"
if query_params:
item_id = query_params.get('item_id')
if item_id:
url = f"{ENVIRONMENT_VARIABLES['API_URL']}/task/{item_id}"
else:
return {
'statusCode': 400,
'body': json.dumps({'error': 'Invalid request'})
}


try:
Expand Down
23 changes: 20 additions & 3 deletions lambda_handlers/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@
from common.constants.environment_variables import ENVIRONMENT_VARIABLES


def handle_items():
def handle_items(event, context):
# Logic for /servicenow/items
url = f"{ENVIRONMENT_VARIABLES['API_URL']}/sysapproval_approver?sysparm_limit=10&sysparm_display_value=true"

url = f"{ENVIRONMENT_VARIABLES['API_URL']}/sysapproval_approver"
query_params = event.get('queryStringParameters', {})
params = {
'sysparm_limit': 10,
'sysparm_display_value': True,
'sysparm_query': ""
}
if query_params:
sysparm_limit = query_params.get('sysparm_limit')
sysparm_display_value = query_params.get('sysparm_display_value')
sysparm_query = query_params.get('sysparm_query')

if sysparm_limit:
params['sysparm_limit'] = sysparm_limit
if sysparm_display_value:
params['sysparm_display_value'] = sysparm_display_value
if sysparm_query:
params['sysparm_query'] = sysparm_query

try:
response = requests.get(
url,
params=params,
auth=HTTPBasicAuth(ENVIRONMENT_VARIABLES['USERNAME'], ENVIRONMENT_VARIABLES['PASSWORD'])
)
response.raise_for_status() # Raise an exception for bad responses (4xx, 5xx)
Expand Down
14 changes: 12 additions & 2 deletions lambda_handlers/patch_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ def handle_patch_item(event, context):
'statusCode': 400,
'body': json.dumps({'error': 'Invalid request'})
}
item_id = event['path'].split('/')[-1]
url = ""
query_params = event.get('queryStringParameters', {})
# Logic for /servicenow/item/<item_id>
if query_params:
item_id = query_params.get('item_id')
if item_id:
url = f"{ENVIRONMENT_VARIABLES['API_URL']}/task/{item_id}"
else:
return {
'statusCode': 400,
'body': json.dumps({'error': 'Invalid request'})
}
patch_data = event['body']
url = f"{ENVIRONMENT_VARIABLES['API_URL']}/sysapproval_approver/{item_id}"

try:
response = requests.patch(
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.31.0

0 comments on commit 82fbc40

Please sign in to comment.