I am trying to call a patch API to our maintenance software, Limble. I keep getting back a invalid credentials error. There API requires basic base 64 encoding. If anyone has any ideas it wold be very helpful! Thanks
from java.util import Base64
# Create an HTTP client
client = system.net.httpClient()
# Define the URL and the payload
url = "https://api.limblecmms.com/v2/assets/fields/1416/"
payload = {"value": 5000}
# Encode your username and password for Basic Authentication
username = "ClientID"
password = "ClientSecret"
credentials = "{username}:{password}"
encoded_credentials = base64.b64encode(credentials.encode()).decode()
# Define headers for Basic Authentication
headers = {
"Content-Type": "application/json",
"Authorization": "Basic" + encoded_credentials
}
# Make the PATCH request
response = client.patch(url, data=payload, headers=headers)
# Check the response
if response.statusCode == 200:
print("Field updated successfully!")
else:
print("Failed to update field. Status code: {response.status_code}")
print(response.text)
print encoded_credentials
EDIT: For any one later with a similar issue. Passing the user and password in the header is the wrong. Like Kevin said, its better to pass them through the client.Patch