Google Functions authentication issue

Hi Greg,
I had the same idea, but it is a little bit tricky to do this. I don`t have sufficient rights in Google Cloud to set unauthenticated access. I have to create a ticket about the topic and explain a lot the responsible colleagues. And even afterwards I am not sure I will get this temporary unauthenticated access. Of course, I could try, but it will take time also. Do you have any other idea how we could test and troubleshoot? Could we change the format of the response in any way?

Best regards,
Borislav

You might be able to use ngrok to capture the request response. Ngrok lets you setup a proxy that you would configure to point to the Google endpoint, and would change your Action to call the ngrok assigned proxy. You run the proxy locally. We often use this when doing internal testing of new endpoints to see the request/response flow.

Hi Greg,
I will try it tomorrow and write you about the result. At the moment here it is almost 23:00 and cannot go on working.

Best regards,
Borislav

Hi again Greg,
The colleagues granted only for very short time Public Access to the Function and I was able to test from Postman.
My cURL was:

curl --location --request POST 'https://europe-west3-cf-genesys-dev-t7.cloudfunctions.net/gc_query_dedicated_skill'
--header 'Content-Type: application/json'
--data-raw ' {
"integrationId": "be7e7424-e9dc-41b9-9471-abf71ddb184b",
"rawRequest": "{"contact":"359899884321","area_code":"DE_DUS_CCC"}",
"orgId": "720bb830-ca9b-47d1-bc1d-879e04bddc27",
"contact": "359899884321",
"area_code": "DE_DUS_CCC"
}'

and as a Response I recieved:

{"skill": "FSD"}

Best regards,
Borislav

Hi Borislav,

Can you look at the headers of the response, specifically the "Content-Type" header. We expect that header to include "application/json". If it is returning something like text/plain then that function needs to be updated to set the content-type to application/json.

--Jason

What was the content type header returned?

Hi Jason,
Great! We will try to meet your expectations.
Just a small question. Where in the documentation are they described? This about the response header, I mean. Obviously we have missed it.

Best regards,
Borislav

It would have been details from the curl. -v for verbose.

Just a small question. Where in the documentation are they described? This about the response header, I mean. Obviously we have missed it.

I don't see the content-type header requirement spelled out. On this page:

on the "Web services" tab it shows a requirement of "JSON-based web service calls." which I would expect to have a content-type that includes application/json for any response that includes a body. We can see about adding that as a documented requirement.

--Jason

Yes, if this requrement is valid for Google also, it will be nice, when it is written, I think. In Web Service I havent check at all, since I dont use this Integration. And one hint more. In your Example Function you have:

function createResponse(req) {

var response = {};
response.sumOfNumber1AndNumber2 = req.body.inputNumber1 + req.body.inputNumber2;
return response;

}

There is nothing about formating the response (its header).

Maybe, if you provide this in example, it will be easier for everyone.

Best regards,
Borislav

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.