Azure Function App with Stripe - Receive Request but empty headers in JavaScript

Catherine Zhou 0 Reputation points
2025-02-03T16:44:32.4233333+00:00

Hi team, I have a function app connecting with Stripe with a customized handler:

app.http('Stripe-Connect', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    handler: async (request, context) => {
        context.log("🔹 Received Webhook Request");
		context.log("🔹 Request:", request);
        context.log("🔹 Request Method:", request.method)
        context.log("🔹 Request Headers:", JSON.stringify(request.headers, null, 2));
        try {
            const rawBody = await request.text();
            context.log("🔹 Raw Request Body:", rawBody);
        } catch (err) {
            context.log("❌ Error Reading Request Body:", err.message);
        }
        
        const stripe = new Stripe(process.env['STRIPE_SECRET_KEY_TESTING']);
        const sig = request.headers['stripe-signature'] || request.headers['Stripe-Signature'];
		// Other stuffs after this
}

When I trigger it with cURL command:

curl -v -X POST http://localhost:7071/api/Stripe-Mailchimp \
  -H "Content-Type: application/json" \
  -H "stripe-signature: t=1620000000,v1=xyz,v0=abc" \
  -d '{"type":"payment_intent.succeeded"}'

My app receives:

  • The request method: Request Method: POST
  • The request body: Raw Request Body: {"type":"payment_intent.succeeded"}

but nothing else was reading:

Request: HttpRequest { query: URLSearchParams {}, params: {} }
Request Headers: {}

My local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "node",
        "WEBSITE_NODE_DEFAULT_VERSION": "18",
        "WEBSITE_ENABLE_SYNC_UPDATE_SITE": "true",
        "AzureFunctionsJobHost__Logging__Console__IsEnabled": "true"
    },
    "Host": {
        "LocalHttpPort": 7071,
        "CORS": "*",
        "CORSCredentials": false
    }
}

My host.json:

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    },
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[4.*, 5.0.0)"
    }
}

I have tried everything on Google and GPT but nothing is working. Any assistance would be greatly appreciated! Thank you in advance for your help!

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

2 answers

Sort by: Most helpful
  1. Catherine Zhou 0 Reputation points
    2025-02-03T20:17:49.8+00:00

    I was able to solve this question eventually. For those who might have similar problem, my problem was that I put my env variable in .env but didn't include it in local.settings.json after adding them in json it was fine.

    0 comments No comments

  2. Shireesha Eeraboina 2,235 Reputation points Microsoft External Staff
    2025-02-04T06:33:20.09+00:00

    Hi @Catherine Zhou ,

    Thank you for your patience and for sharing your feedback on the Q&A community platform. I’m glad to hear that you were able to resolve your issue, and I appreciate you sharing your solution! Your contribution is valuable and can help others in the community facing similar challenges.

    As per the Microsoft Q&A community policy, "The question author cannot accept their own answer. They can only accept answers by others"

    I’m reposting your solution here so you can mark it as accepted if it resolves your query:

    I initially placed my environment variable in the .env file but did not include it in local.settings.json. After adding it to the JSON file, everything worked correctly.

     If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue. 

    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members. 

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.