Not able to get http response from a third party API when code deployed to azure function app, in debug mode its working fine

sachin 1 Reputation point
2022-07-07T13:44:21.597+00:00

I have created an azure http trigger (also tried with timer trigger) function and it is calling an third party API with necessary params as content header. Locally in VS Code (debug mode), it's working fine. I am getting desired response (getting token if we call token end point as well as proper response if we call another end point by passing token). Even with postman I am getting correct response.

But when I deployed this function to azure function app, it's not getting response from both endpoint. (either from token one or if I pass hardcoded token copied from postman to second endpoint).

In logs, I can see function being called and when I am logging response I am getting a large html text(don't know what is that) Is it possible that third party API is blocking or restricting calls from azure function(though it's working locally or with postman if we pass proper values) Tried everything but can' find out the exact issue. I have verified I am passing correct values as grant_type, client_Id, client_secret, username, password, scope)

Have pasted below sample piece of code:

private async Task\

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,263 questions
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,021 Reputation points
    2022-07-07T15:15:12.147+00:00

    You are getting either an error login page. Your parameters are probably not correct or login configuration is not correct.

    View with an html viewer to better read.


  2. MayankBargali-MSFT 68,476 Reputation points
    2022-07-13T05:26:39.87+00:00

    @sachin Can you please confirm if your application settings has the keys and values that you have leveraging in your function app. In case if the values are defined correctly then please log the value of your environment variables to verify whether you are able to get the right value, or it is empty.

    var value = Environment.GetEnvironmentVariable("your_key_here")  
    

  3. Bruce (SqlWork.com) 56,021 Reputation points
    2022-07-13T16:01:28.373+00:00

    the response to your GetToken call is the html AzureLogin page (which is only supported by a browser or webview). this would suggest the endpoint you are calling has a different api then you are sending. check with your vendor.

    note: typically with current openid protocols, you can not login via post of user name / password. for applications its typically a client and secret.

    the vendor could also require different authentication based on the client ipaddress.


  4. satya karki 986 Reputation points MVP
    2022-07-14T04:06:12.053+00:00

    I think the parameters are different for the development environment where you are getting values successfully than after deployment in azure. From my experience, the vendor sometimes gives client ID, secret key, and so on different for development than the production, and when we deploy we need to change those parameters for production. You can consult with your Third part API provider.


  5. sachin 1 Reputation point
    2022-09-16T08:29:13.02+00:00

    Hi All,

    Thanks to all who replied and viewed this thread, especially to @MayankBargali-MSFT .

    We have found the actual problem and it's not from the code/development side. The vendor has migrated the API to azure server and now they have another level of authentication (might be azure Ad)

    So the original authentication which I believes (JWT Oauth) is returning it's token but we are not authenticating azure one so that's might be the reason we are getting azure html page.

    Now API team is looking what's need to be done. We can close this thread or if someone has any solution or suggestion they can share.

    Thanks,
    Sachin

    0 comments No comments