def main(servicenow_instance: str, username: str, password: str, short_description: str, description: str, contact: str = None, account: str = None):
"""
Creates a new case in ServiceNow.
:param servicenow_instance: The URL of the ServiceNow instance (e.g., your-instance.service-now.com).
:param username: The username for authentication.
:param password: The password for authentication.
:param short_description: A short description of the case.
:param description: A detailed description of the case.
:param contact: The contact for the case.
:param account: The account for the case.
"""
url = f"https://{servicenow_instance}/api/sn_customerservice/case"
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
data = {
"short_description": short_description,
"description": description,
}
if contact:
data["contact"] = contact
if account:
data["account"] = account
response = requests.post(url, auth=(username, password), headers=headers, data=json.dumps(data))
if response.status_code == 201:
return response.json()
else:
return {"error": response.text, "status_code": response.status_code}
if __name__ == "__main__":
# Example usage (replace with your actual data)
# You would typically run this within the Windmill environment
# For local testing, you can set up environment variables or a config file
instance = "your-instance.service-now.com"
user = "your-username"
pwd = "your-password"
short_desc = "Case created via API"
desc = "This is a test case created using the Windmill script."
result = main(instance, user, pwd, short_desc, desc)
print(result)
Submitted by vinayak saokar174 294 days ago