Passing data to function does not work using the provided command

Royer, Alexis 0 Reputation points
2025-02-01T16:43:05.1366667+00:00

Hi,
in Exercise - Add logic to the function app - Secure HTTP triggers
the data section of the following command never pass the name variable correctly to the function on the function app. it run but ignore the fact that a variable was passed.

is it still the proper command as of today? I've tried with different combinaison of single or double quote.. can't seems to find the proper usage.

curl --header "Content-Type: application/json" --header "x-functions-key: <your-function-key>" --request POST --data "{\"name\": \"Azure Function\"}" <your-https-url>

This question is related to the following Learning Module

Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop new skills.
2,036 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Pradeep M 5,680 Reputation points Microsoft Vendor
    2025-02-03T04:21:03.36+00:00

    Hi Royer, Alexis,

    Thank you for reaching out to Microsoft Q & A forum. 

    It looks like the issue may be due to a missing or incorrect function key or function URL. Please check the following: 

    1.Function Key: Make sure your function key is included in the x-functions-key header. You can find it in the Azure Portal under: 

    Function App > Your Function > Function Keys. 

    2.Function URL: Ensure you're using the correct function URL by navigating to: 

    Azure Portal > Function App > Your Function > Get Function URL. 

    Once you've verified these details, try running the following command with the correct values: 

    curl --header "Content-Type: application/json" \
         --header "x-functions-key: YOUR_ACTUAL_FUNCTION_KEY" \
         --request POST \
         --data '{"name": "Azure Function"}' \
         YOUR_ACTUAL_FUNCTION_URL
    
    

    Additionally, you can check the Logs under Code + Test in the Azure Portal to see if the request is being received. 

    Please feel free to contact us if you have any additional questions.     

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.  


  2. Pradeep M 5,680 Reputation points Microsoft Vendor
    2025-02-05T12:04:32.82+00:00

    Hi Royer, Alexis,

    Thank you for your message. I see that you're encountering issues when trying to pass the name variable to your function via the curl command. 

    Based on your command and the details you’ve provided; it seems that the issue may be due to a few key points: 

    1.Correct curl Command Syntax: It looks like there was a minor issue with the syntax in your curl command. The correct version should wrap the URL in quotes, like this: 

    curl --header "Content-Type: application/json" --header "x-functions-key: roZ1JivKlhsHJcxB0c7Nz3pyNBB8-axVbgFrT_jNmsf_AzFudcfaTA==" --request POST --data "{\"name\": \"Azure Function\"}" "https://RoyerAlexisfunction.azurewebsites.net/api/DriveGearTemperatureService?code=C1tpMcg6fIf-dhUgDhG0HXlGbKD1TLhH6WkuC68ariZxAzFuhSOKnw%3D%3D"
    
    

    Notice the quotes around the entire URL — this ensures the command executes properly in the terminal. 

    2.JSON Format: Ensure that you're sending the correct JSON payload in the request body. For your exercise, the payload you're passing should look like this: 

    {
        "Readings": [
            {
                "driveGearId": 1,
                "timestamp": 1534263995,
                "temperature": 23
            },
            {
                "driveGearId": 3,
                "timestamp": 1534264048,
                "temperature": 45
            },
            {
                "driveGearId": 18,
                "timestamp": 1534264050,
                "temperature": 55
            }
        ]
    }
    
      
    

    This JSON data should be included in the body of the curl request. It seems that you might have missed adding this in your previous attempt. 

    3.Valid Function Key: Ensure that you're using the correct function key in the x-functions-key header. This key should be valid and match the one generated by your Azure Function app. 

    Once you update your curl command with the correct syntax and the proper JSON data in the body, the function should be able to process the incoming request and pass the name variable correctly.

    We've tried everything on our end, and everything looks fine. Please find the screenshots attached for your reference:  

    050225_all 050225_all1 050225_all22

    Please feel free to contact us if you have any additional questions.     

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.  


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.