J.C Guzman
J.C Guzman

Reputation: 1334

I cannot add path parameter in my azure function and APIM

I am using azure api management.

I want to create a path parameter and be able to get this parameter to return some data with azure functions.

I have create an endpoint that look like this:

https://myapiname.azure-api.net/idloans/idloans/{value}

My azure function is called idloans

So I want to retrieve this value to use it in my azure function:

import logging
from sqlalchemy import create_engine
import psycopg2
import pandas as pd
import numpy as np
import azure.functions as func
import pyodbc
import sqlalchemy
import json 

def main(req: func.HttpRequest) -> func.HttpResponse:

    value = req.params.get('value')

    if not value:

        value = req.route_params.get('value')
        

    if not value:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            
            value = req_body.get('value')
            if value:
                logging.info(f'get_json value: {value}')

    if value:

        logging.info('value found')

        return func.HttpResponse('OK',status_code=200)
    else:
        logging.info('not found')
        return func.HttpResponse(
                "Not found",
                status_code=406
            )


But it is not working, the function is no being activated when I send a get request to this endpoint

Upvotes: 1

Views: 216

Answers (1)

suziki
suziki

Reputation: 14088

It seems that there is a problem with your trigger method.

If you don't have authentication level, you should hit:

https://yourfunctionappname.azurewebsites.net/api/yourfunctionname

If you have authentication level, you should hit:

https://yourfunctionappname.azurewebsites.net/api/yourfunctionname?code=xxxxxx

Upvotes: 1

Related Questions