An error occurred when calling Get All Unsupported content type: text/plain

I am calling an AWS Lambda function using API Gateway, which returns a simple response:

return {
    'statusCode': 200,
    'body': json.dumps({"hi":"hi"})
}

Adalo is able to call the endpoint and read the payload body, but says it is unsupported content.

image

I have tried various results key (i.e. “body”) and various Headers (i.e. “Content-Type”:“application/json” and “text/plain”. Nothing works. Would you have an idea?

I am not at my computer at the moment, but I am pretty sure Adalo needs the response payload to be wrapped in results

So your lambda needs to return

{ "results": { "hi": "hi" } }

Give that a shot, if it doesn’t work let me know and when I get back to my computer I’ll double check and let you know.

2 Likes

Thanks for the reply! Unfortunately, I tried that and it gave me the same error:

Lambda Function:

return {
    'statusCode': 200,
    'body': json.dumps({"results":{"hi":"hi"}})
}

Adalo:

image

My mistake, the external collection will run a Get All (it is a collection after all). It must return an array, not an object! Normally structured with “response”, so return

{
   "response": {
      "data": [{
         "hi": "hi"
      }]
   }
}

try this

return {
    'statusCode': 200,
    'body': json.dumps({ "response": { "data": [{"hi":"hi"}] } })
}

Notice that “data” is an array. If you want to not return an array then you do not use external collection, but a custom action that calls an endpoint.

1 Like

Thanks for the reply again @TKOTC. We’ll be doing both a collection (with an array) and a custom action. I did as you instructed and tried the code you suggested:

return {
‘statusCode’: 200,
‘body’: json.dumps({ “response”: { “data”: [{“hi”:“hi”}] } })
}

Adalo:

However, it seems the issue persists even if “data” is an array. Any insights as to why? Thanks!

Also, I did input the “results key” and “second results key”, using combinations of “response” and “data” for each field.

Did you test it without putting any keys?

image


image

Still not working. I re-did the Endpoint (with no results key or headers), and the same issue persisted.

return {
    'statusCode': 200,
    'body': json.dumps({ "response": { "data": [{"hi":"hi"},{"there":"there"}] } })
}

return {
"statusCode": 200,
"body": json.dumps({ "response": { "data": [{"hi":"hi"}] } }),
"content-type": "application/json; charset=UTF-8"
}
return {
    'statusCode': 200,
    'body': json.dumps({ "response": { "data": [{"hi":"hi"},{"there":"there"},{"again":"again"}] } }),
    "content-type": "application/json; charset=UTF-8"
}

Can you share the yaml for the lambda? Something seems off with your lambda.

So, I’m not sure what the .yaml file is for the lambda, I just created the lambda function from the dashboard. Here’s the code:

import json
import logging
import io

def lambda_handler(event, context): 
    
    return {
        'statusCode': 200,
        'body': json.dumps({ "response": { "data": [{"hi":"hi"},{"there":"there"},{"again":"again"}] } }),
        "content-type": "application/json; charset=UTF-8"
    }

And the Resource-Based Policy Document (with API Gateway invoking the function):

{
  "Version": "2012-10-17",
  "Id": "default",
  "Statement": [
    {
      "Sid": "6f25300c-f555-50dc-9f8e-d95aee0e29ba",
      "Effect": "Allow",
      "Principal": {
        "Service": "apigateway.amazonaws.com"
      },
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:us-east-2:406273866153:function:recommender",
      "Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:execute-api:us-east-2:406273866153:6qmsb4au8l/*/*/recommender"
        }
      }
    }
  ]
}

Ahhhh… I understand now!

Okay, here is the results

Here are the steps to make it work.

I used the following code in the lambda

import json
import logging
import io

def lambda_handler(event, context): 
    
    return {
        'statusCode': 200,
        'body': [{"hi":"hi"},{"there":"there"},{"again":"again"}],
        "content-type": "application/json; charset=UTF-8"
    }

Notice, there is no json.dumps

Second, there issue if probably in your API Gateway! Not the lambda or Adalo.

  1. Create a new API Gate and choose REST API (Not HTTP API, which is what I think you have done)

  2. Leave the defaults and give it a name

  3. Choose Create Method

  4. Choose GET from the dropdown, click the check mark

  5. Choose Lambda Function and enter the name of your lambda

  6. Click OK to give permissions

  7. Leave all the defaults, verify that the METHOD RESPONSE is “application/json”

  8. Choose DEPLOY API from the ACTIONS dropdown

  9. Choose NEW STAGE and give it information
    image

  10. Copy the INVOKE URL, this is what you use for Adalo

  11. Edit the external collection

  12. Enter the Result key as body (from the lambda)

  13. Test collection and click create

Let me know if this works out for you!

1 Like

Also, now that I am less confused, your Lambda should look like this

import json
import logging
import io

def lambda_handler(event, context): 
    
    return [{"hi":"hi"},{"there":"there"},{"again":"again"}]
    

No need for anything else. The return of a lambda_handler will get wrapped by the API Gateat so it will already include the status 200 (unless you throw an error) and the { “response”: { “data”: … } }

The above code will return

Which means you do not need to use the Results Key

for it to work

1 Like

Perfect, that worked just perfectly! I was able to return a list like you suggested.
image

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.