Passing multiple values to api endpoint key

Von1974
Von1974 Registered Posts: 11 ✭✭✭✭
edited July 16 in Using Dataiku

Hi,

Is it possible to pass multiple values to an api endpoint?

I have a lookup api endpoint, that i want to take all rows from a dataset where the rule value is equal to the request, this could be vr1, vr2 on one call, but vr1, vr2, vr3 on another.

I am having difficulty getting this to work (very new to dataiku, like a week in!) If i change to bring back only one record (lookup_record vs loookup_records) and change the test query to one value, this works great.

Can anyone offer some guidance please?

Here is function in api endpoint;

def GetDate(pol_qte_ref, (rule_no)):
        client = utils.get_self_client()
        data = client.lookup_record("1_GetData", {"pol_qte_ref" : pol_qte_ref})
        
        rule_client =  client.lookup_records("1_GetRules", {"rule_no" : rule_no})
        
        return(rule_client)

Here is test query;

{
   "pol_qte_ref": "100651018CMI",
   "rule_no": [
      {
         "rule_no": "vr1"
      },
      {
         "rule_no": "vr2"
      }
   ]
}

Many THanks in advance

Answers

  • Triveni
    Triveni Dataiker, Registered Posts: 20 Dataiker

    Hi,

    It seems like your data that you are passing to the endpoint is not configured appropriately. The documentation for the lookup_records method states :

    Python list of records. Each record must be a Python dict, containing at least one entry called “data”: a dict containing the input columns

    This means that your rules_no data should be a list of dictionaries - one dictionary per record, and with at least an entry called 'data' for the input information.

  • Von1974
    Von1974 Registered Posts: 11 ✭✭✭✭
    edited July 17

    Thanks for responding.

    This is my issue, i have seen that documentation, but i have no idea how to create this list of dictionaries, nor where!

    So the flow i have is;

    1 - getRules lookup api endpoint that uses rule_no reference to get data from dataset

    This is the sample query that runs ok.

    {
       "data": {
          "rule_no": "vr1"
       }
    }

    2 - invoke python api end point that calls getRules end point, and other end points, with a view to doing some data wrangling

    From what you say, the data in getRule endpoint is not configured properly?

    It would be great if the documentation included some example code of typical user flows!

  • Triveni
    Triveni Dataiker, Registered Posts: 20 Dataiker
    edited July 17

    Can you try passing your multi-record data like this?

    {
      "records": [
        {
          "data": {
            "rule_no": "vr1"
          }
        },
        {
          "data": {
            "rule_no": "vr2"
          }
        }
      ]
    }

    I used the reference for the REST API found here to get an example of how to send the request.

  • Von1974
    Von1974 Registered Posts: 11 ✭✭✭✭
    thanks! ill have a play with that!
Setup Info
    Tags
      Help me…