I have a several notebooks running that will fail when the user has 29 credits remaining. I believe this is the Esri default, because I cannot find a way around this even if the notebook uses a fraction of a credit.
My solution would be to generate an email to myself or another admin when a user has a low credit balance. Is this a possible trigger to set in Power Automate?
My only other approach would be to use a notebook to scrape user credit information on a regular basis and add that to a table that would in turn trigger a 'When a Feature Class is Added' response from Power Automate. This seems a bit clunky and obviously uses more credits in the process.
You're correct that's a built-in failsafe in ArcGIS Online that you can't change. You might try something like the following:
I have some code that checks the credit balance for an account I use for Notebook automation that I want to keep topped up with credits.
I run it on a VM, but you could also set it up to run periodically on your personal machine, or some other machine that's available.
from arcgis.gis import GIS
import smtplib
from email.message import EmailMessage
reportPage = ''
# Connect to the GIS
myGIS = GIS(url="https://myAGOorg.maps.arcgis.com/", username='MYADMINUSERNAME', password="MYPASSWORD")
theUserAccount = myGIS.users.get(username='THEUSERNAME_HERE')
cm = myGIS.admin.credits
credit_status = "User has " + str(theUserAccount.availableCredits) + " credits."
if theUserAccount.availableCredits < 50:
cm.allocate(theUserAccount, 1000)
reportPage = reportPage + '\n' + "Allocated 1000 Credits"
# SMTP method:
SENDER = 'userName@myCompany.com'
RECIPIENTS = ['userName@myCompany.com']
MESSAGE_SUBJECT = 'Automated Report User Credits'
MESSAGE_BODY = """
User Credits Status:
{}
""".format(reportPage)
smtpserver = smtplib.SMTP("smtp.myCompany.com")
#smtpserver.login(SMTP_USER, SMTP_PASSWORD)
msg = EmailMessage()
msg.set_content(MESSAGE_BODY)
msg['Subject'] = MESSAGE_SUBJECT
msg['from'] = SENDER
msg['to'] = RECIPIENTS
try:
smtpserver.send_message(msg)
except smtplib.SMTPException as err:
print("Unable to send mail:", err)
finally:
smtpserver.quit()This one sends out a notice via email using SMTP, but you can also send messages from the ArcGIS Org if you're an admin. If you wanted you could skip the automatic topping off and just send a message that the account is low.
This is an example showing how to send from the org:
um = myGIS.users
uMiniList = []
uMiniList.append(myGISusername)
user = um.get(theUserName)
subject = 'Credits Low'
message = f'''Hi, {myGISusername},
Your credits are low.
'''
um.send_notification(uMiniList,subject,message,type='email')
I don't think Notebooks will let you send emails via SMTP, but they should allow you to send notifications from the org.
This tutorial shows the steps for setting up a batch file and Windows Scheduled Task to run a Python script.
https://learn.arcgis.com/en/projects/schedule-automated-near-real-time-data-updates/
Thank you both for the replies - I will try to implement one or both of these suggestions and report back with any successes!
Thanks @BobBooth1 and good luck with the project @bbywaterbw!