Write a Python script to pass data to Appian WebAPI using username password certificate path and jq

import requests
import json
import jq
import certifi

# Set your Appian environment URL
APPIAN_ENV_URL = "https://my-appian.com"

# Set your Appian login credentials
APPIAN_USERNAME = "my-username"
APPIAN_PASSWORD = "my-password"

# Set the path to your custom certificate
CUSTOM_CERTIFICATE_PATH = "/path/to/your/certificate.pem"

# Create a requests session
session = requests.Session()

# Authenticate to Appian
auth_url = APPIAN_ENV_URL + "/suite/api/authentication/login"
auth_headers = {
    "Content-Type": "application/json"
}
auth_payload = {
    "username": APPIAN_USERNAME,
    "password": APPIAN_PASSWORD
}
auth_response = session.post(auth_url, headers=auth_headers, data=json.dumps(auth_payload), verify=CUSTOM_CERTIFICATE_PATH)

# Get the authentication token
auth_token = auth_response.json()["token"]

# Set the authentication token in the session headers
session.headers.update({"Authorization": "Bearer " + auth_token})

# Set the URL of the Appian web API you want to call
webapi_url = APPIAN_ENV_URL + "/suite/api/webapi/my-webapi"

# Set the data you want to pass to the Appian web API
webapi_payload = {
    "data": "my-data"
}

# Call the Appian web API
webapi_response = session.post(webapi_url, data=json.dumps(webapi_payload), verify=CUSTOM_CERTIFICATE_PATH)

# Check the response status code
if webapi_response.status_code == 200:
    # Decode the JSON response using jq
    webapi_response_data = json.loads(jq.compile(".data").input(webapi_response.content.decode("utf-8")))
    print("Web API call successful! Response data:", webapi_response_data)
else:
    print("Web API call failed: {}".format(webapi_response.status_code))

# Close the requests session
session.close()

This script will use the custom certificate at the specified path to verify the SSL connection to the Appian environment and use the jq library to decode the JSON response from the Appian Web API.

how to write a python script to pass data to appian webapi using username password certificate path and jq How to write a Python script to pass data to Appian WebAPI using username password certificate path and jq Screenshot 2023 10 06 at 9

How to write a Python script to pass data to Appian WebAPI using username password certificate path and jq

By DSD