1

I am attempting to deploy a basic python function which calls an api using an HTTP trigger through Google Functions (browser-editor).

Here's the function I'm trying to deploy:

import requests
import json

def call_api():

    API_URL = 'https://some-api.com/v1'
    API_TOKEN = 'some-api-token'

    result = requests.get(API_URL+"/contacts?access_token="+API_TOKEN).json()
    print(result)

call_api()

My requirements.txt contains:

requests==2.21.0

However, every time I try to deploy the function, the following error occurs:

Unknown resource type

What am I doing wrong? The function works just fine on my local machine.

1 Answer 1

1

Please refer to Writing HTTP Functions for more information. This is what comes to my mind when looking at your code:

  • Missing the request parameter (def call_api(request):)
  • Missing return at the end (you don't need to print it, just return it to the caller)
  • Calling call_api() at the end of the file will call the function only locally, CFs don't need this

Make sure you are deploying using gcloud functions deploy call_api --runtime python37 --trigger-http

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.