Hi everyone,
I wanted to share a method for updating asset fields in Limble CMMS directly from Ignition using their REST API. This approach can be really useful if you’re tracking runtime hours, maintenance counters, or any other custom fields and want to automate updates from your Ignition system.
If you have a better way of doing this, let me know. I’m still pretty new to all this, and I’m always looking for good feedback.
Key points:
-
Authentication
Limble uses HTTP Basic Authentication for API requests. You’ll need aclient_id
andclient_secret
, which you get when registering your application with Limble. These credentials should ideally be stored outside your script (like in environment variables) for security, and then Base64-encoded to form the Authorization header. -
Identifying the field to update
Every field in Limble has a uniquevalueID
. You’ll need this ID to target the correct field when sending an update request. You can usually find it via the Limble UI or API. -
Preparing your data
The API expects a JSON payload. For example, if you want to update a runtime counter, your payload will include the new value for that field. -
Constructing the API request
The endpoint to update a field typically looks like this:https://api.limblecmms.com/v2/assets/fields/{value_id}/
You’ll use a PATCH request with the JSON payload and Authorization header.
-
Error handling
Always wrap your request in a try/except block to catch any connection issues, authentication errors, or invalid requests. Logging the response or error message helps debug when something doesn’t update as expected.
Here is the script we are now using on a handful of machines for various tags. I have this setup on any tag where the value changes. This way it updates when the tag does.
import system.util
import system.net
import base64
import json
AutoUpdate = system.tag.readBlocking("PlaceTagPathHere")[0].value
# ================================
# Limble API credentials
# ================================
# These credentials are used to authenticate with the Limble CMMS API.
# client_id and client_secret are provided when you register an application
# or integration with Limble.
client_id = "add your client id here"
client_secret = "add your secret token here"
# ================================
# Encode credentials for Basic Auth
# ================================
# Limble API uses HTTP Basic Authentication. The client_id and client_secret
# are combined with a colon, then Base64-encoded to form the Authorization header.
credentials = client_id + ":" + client_secret
auth_header = "Basic " + base64.b64encode(credentials.encode()).decode()
# ================================
# Define the value ID to update
# ================================
# Each field in Limble has a unique valueID. Here, we specify the ID for
# "Runtime Hours" (or any other field you want to update). This will be
# used in the API endpoint URL to target the correct field.
value_id = 9999 #you will want to change this value for your field
# ================================
# Construct the API endpoint URL
# ================================
# The update_url points to the specific field on a specific asset that we want
# to modify. We append the value_id to the base URL for assets/fields.
update_url = "https://api.limblecmms.com:443/v2/assets/fields/" + str(value_id) + "/"
# ================================
# Prepare the new data to update
# ================================
# The API expects a JSON payload. Here, we set the new value for the field.
update_data = {
"value": AutoUpdate # Replace with whatever value you want to update
}
# ================================
# Set request headers
# ================================
# Content-Type specifies that we are sending JSON data.
# Authorization contains our Base64-encoded credentials.
headers = {
"Content-Type": "application/json",
"Authorization": auth_header
}
# ================================
# Send PATCH request to Limble API
# ================================
# Wrap in try/except to catch any errors during the HTTP request.
try:
# Create an HTTP client using Ignition's system.net module
client = system.net.httpClient()
# Send a PATCH request to update the field value
update_response = client.patch(
url=update_url, # API endpoint for updating the field
headers=headers, # HTTP headers including auth
data=json.dumps(update_data) # JSON payload as a string
)
# Print success message and response text to Perspective console
system.perspective.print("Updated successfully:")
system.perspective.print(update_response.getText())
except Exception as e:
# Print failure message and exception details if request fails
system.perspective.print("Failed to update")
system.perspective.print(str(e))
Hope this helps someone!