Custom Action Not Working

I can’t get the custom action to work for simple RESTful Api service call. Have sent an email with recording but no response so far.

Hi @tgparmar75,

You can now check the logs if there’s an error with your code by checking your Action Runs in the custom action builder:

Thanks for pointing out the “Action Runs”. However, I dont see the latest error runs for this morning. Are they being shown live?

Seems the requests package is not working for a basic test to fetch a single JSON response. Please see the recording.

Custom Action Issue Demo Recording

Below is a simple JSON response from JSONBLOB that I want to parse and dispaly (to start with)
import requests

def getorderbyid(orderid: str):
“”"
The customer will provide an OrderID. Call an API and Parse a JSON Response

Args:
    orderid (string): Order Id of a customer that needs to be searched
"""

# Insert your PYTHON code below. You can access environment variables using os.environ[].
# Currently, only the requests library is supported, but more libraries will be available soon.
# Use print statements or return values to display results to the user.
# If you save a png, pdf, csv, jpg, webp, gif, or html file in the root directory, it will be automatically displayed to the user.
# You do not have to call this function as the bot will automatically call and fill in the parameters.


url = "https://api.jsonblob.com/019af7a1-8601-7725-beb8-e546eea62a79"
headers = {"Content-Type": "application/json"}

resp = requests.get(url, headers=headers, timeout=10)
data = resp.json()               # parse JSON

status = data.get("Status")
total_amount = data.get("TotalAmount")

orderid = "1"
print(f"OrderId of customer is {orderid}")
print(status)
print(total_amount)

return (f"The Shipment status is {status} and your total amount is {total_amount}")

Please try again. The issue was with the built-in json package that was included in your action’s packages list. Since it’s included in Python by default, attempting to install it through our sandbox system causes an error.

We’ll add more validations so this doesn’t happen in the future.

1 Like

It worked. However, when I try with my live API, I am getting this error. Please note the my API works fine in Postman without any issues.

Postman Call Demo: Check Postman Call

I suggest copying your code + the error stack and ask the AI what’s wrong with it.
From what I can see, the url variable in your latest code needs to be an f-string.

Thanks I was able to get the API to work after I added the User-Agent to “PostmanRuntime/7.49.1”. Not sure why this is required but it works fine now.