Google Functions authentication issue

Content-type is a standard response header. I am just trying to find out what was returned when Borislav ran his test with curl to see if it was text/html like we were getting from the Action in production.

Hi Greg,
Hi Jason,
You are right. Our Function sends in the Response Content-Type text/html. I checked it again. And this is the reason we get this error. I made another function

https://europe-west3-cf-genesys-dev-t7.cloudfunctions.net/gc_query_dedicated_skill-test

It is identical with

https://europe-west3-cf-genesys-dev-t7.cloudfunctions.net/gc_query_dedicated_skill

I only added {'Content-Type': 'application/json'} in RETURN command in the code. And I think this new Function works fine.
We will test a little bit more and I will write here about the results.
Thank you very much for your support!

Best regards,
Borislav

Glad we could help. We will update the our documentation to warn about needing to set the Content-Type. We have not run into that in our tests.

Hi Jason,
I believe we solved our issue. Thank you very much again! Just finally I would like to get confirmation I have correctly understood something. You mentioned every Cloud Function requires separate Integration. But this doesn`t mean separate Service Account in the Google, as far as I understand. Am I right?

Best regards,
Borislav

You are correct, the same service account may be used. The separate integrations are needed because that is the level that authentication caching happens, and each google function ends up having a token unique to it when we authenticate. It is very specific to google function API and how the authentication for it has to be done.

Thank you for this explanation, Greg!
I wish you and Jason all the best!

Best regards,
Borislav

Borislov,

Would you send us the code from your function so we can see how your response was coded. We want to be sure we get out documents covering your use case.

Hi Greg,
Gladly! The significant part is:

try:
with db.connect() as conn:
results = conn.execute(stmt).fetchall()
if results:
print(results[0])
print (f"Skill {results[0]}")
a = str(results[0])
print(a)
b=str(a[2:-3])
print(b)
agent = json.dumps({'skill': b})
return agent, {'Content-Type': 'application/json'}

except Exception as e:
    return 'Error: {}'.format(str(e))

#return results
agent = json.dumps({'skill': 'none'})
return agent, {'Content-Type': 'application/json'}

It was "return agent" and added explicitly {'Content-Type': 'application/json'}. So it became " return agent, {'Content-Type': 'application/json'}". We use Python 3.9 and JSON library. "agent = json.dumps({'skill': 'none'})" command actualy produces JSON format, but it was not enough. So, following your advice, I made this small addition regarding the header.

Best regards,
Borislav

Hi Greg,
Did you see my information? Is it useful for you?

Best regards,
Borislav

Borislov,

Yes I did. Sorry for not replying. We are looking at our doc and will see what we can do to include a note about this.

I wish you much success!

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