Hello,
In October last year I made a Message Routing Service to my azure functions.
From then it worked almost without issue. Now I try to do the same with an azure account linked to my company. With the same code it works half. I linked the Message Routing Service to azure functions and I get from all devices a massage when they send it to nrf cloud. I receive HTTP method, URL, headers with all info, query parameters etc. But the json body keeps appearing empty. I did bring back my azure function code to the minimum but no json body. The only difference that I did find is the old one runs on App Service plan and the new on Linux plan. But that I can't change. Did something change on the nrf cloud side? This is probably not something frequently asked, but help is appreciated.
Here is my code I use for the function.
import azure.functions as func
import logging
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
@app.function_name(name="HttpTrigger_nrf")
@app.route(route="http_trigger_nrf")
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a nrf request.')
# Log HTTP method
logging.info("HTTP Method: %s", req.method)
# Log URL
logging.info("URL: %s", req.url)
# Log headers
logging.info("Headers: %s", req.headers)
# Log query parameters
logging.info("Query Parameters: %s", req.params)
# Log route parameters
logging.info("Route Parameters: %s", req.route_params)
all_headers = req.headers
# Log each header
for key, value in all_headers.items():
logging.info(f"{key}: {value}")
# Get the request body as bytes
request_body_bytes = req.get_body()
# Convert the bytes to a string
request_body_str = request_body_bytes.decode('utf-8')
# Log the length of the request body
body_length = len(request_body_bytes)
logging.info(f"Request body length: {body_length} bytes & body {request_body_str}")
try:
# logging.info("Request body: %s", req.get_body().decode('utf-8'))
req_body = req.get_json()
logging.info(req_body)
except ValueError:
logging.info("No get_json in request.")
response = func.HttpResponse("This HTTP triggered nrf function executed successfully.", status_code=200)
response.headers['x-nrfcloud-team-id'] = 'MY_API'
return response