Question

How to Call Function Deployed to App Platform

I was reading through this tutorial on managing functions with App Platform: https://docs.digitalocean.com/products/app-platform/how-to/manage-functions/.

It says this:

Opening the live URL of a function directly in your browser can result in errors if your function is expecting input parameters. Use API testing tools like Postman, curl, or your programming language’s HTTP client library to test the URL with properly formatted HTTP requests.

How do I make a properly formatted HTTP request? I don’t see anything that says how.

In Insomnia (similar to Postman), I tried the following for the url https://site.ondigitalocean.app/COMPONENT/PACKAGE/FUNCTION

  1. A GET request to the function URL with a JSON body containing my serverless function arguments
  2. A GET request to the function URL with query/search params containing my serverless function arguments
  3. A POST request to the function URL with a JSON body containing my serverless function arguments

For all of these, I tried passing Basic MY_AUTH_TOKEN that I use for normal functions. Nothing I do works. I always get a 400 Bad Request with the following error:

{
  "code": "0570a2968654cb1831572b65bab68416",
  "error": "There was an error processing your request."
}

Just wondering what I’m doing wrong so I can get this working.

Thanks,

Joshua.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
July 2, 2023
Accepted Answer

Hi there,

The exact format of your HTTP request depends on the specific implementation of the serverless function you’re calling. If the function is expecting parameters, you’ll need to ensure that you’re providing these parameters in the correct format and location (such as in the query string, the HTTP headers, or the request body), and with the correct HTTP verb (like GET or POST).

The error message you’re seeing, “There was an error processing your request,” is a very general one and could be caused by a variety of issues. However, since you’re receiving a 400 status code, that typically means the server thinks you’ve made a bad request. This could be due to missing or incorrect parameters.

If you were to go to the App Platform logs, do you see any errors recorded there?

Also is your function open-source? If so can you share it here so I could check out what parameters it’s expecting and what might be going wrong?


UPDATE: Joshua got this working after upgrading the function to Python 3.11 and all of its dependencies and he’s now able to call it through App Platform and he is getting a 204 instead of a 400.

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel