<#C01PKLU5D1R|> <#CMN8HELB0|> Hi All I have been d...
# getting-started
t
#C01PKLU5D1R #CMN8HELB0 Hi All I have been developing a tap that calls a REST API that returns information to pass to the next Rest API. I have been using the Parent-Child Streams feature that I have managed to implement. However, the next step is to pass more data from this API to yet another one and this time the information is in and Array within the Json Josn
Copy code
{
  "dob": "20230718",
  "storeId": "psi136678",
  "checks": [
    {
      "id": "9437185",
      "isClosed": true,
      "isEmpty": false,
      "isTraining": false,
      "link": "<https://www.api.com/v1/psi136678/20230718/sales/check/9437185>",
      "marker": 638252250666959000,
      "netAmount": 18.26,
      "printableId": "90001",
      "total": 21
    },
    {
      "id": "8388609",
      "isClosed": true,
      "isEmpty": false,
      "isTraining": false,
      "link": "//www.api.com/v1/psi136678/20230718/sales/check/8388609",
      "marker": 638252253271407100,
      "netAmount": 9.13,
      "printableId": "80001",
      "total": 10.5
    }
  ]
}
API to call https<//www.api.com/v1/{storeId}/{dob}/sales/check/{Checks.id}> I am having trouble trying to extract the data in the correct format to pass to the return{} in my streams.py. Below is my def_child_Context, but it keeps failing to run the API call
Copy code
def get_child_context(self, record: dict, context: dict) -> dict:
        """Return a context dictionary for child streams."""
        checks = record.get('checks', [])  # Retrieve the checks array from the record, providing an empty list as a default value
        check_ids = [int(check.get('id')) for check in checks]         

        # Extract the desired "id" values
        i = 0
        for check in record["checks"]:

            desired_ids = [{"storeId": record["storeId"], 
                          "dob": record["dob"], 
                          "id": record["checks"][i]["id"]} ]
            
            i = i + 1
            desired_ids.append(desired_ids)
        
        output = json.dumps(desired_ids)
        
        res_dict = {}
        for i in range(0, len(desired_ids), 2):
            res_dict[desired_ids[i]] = desired_ids[i + 1]
       
        return {
            storeId": res_dict["storeId"],
            dob": res_dict["dob"],
            id": res_dict["id"],
            }
I have altered my code and it works without failing. However, it only returns one check not all checks
Copy code
def get_child_context(self, record: dict, context: dict) -> dict:
        """Return a context dictionary for child streams."""
        desired_data_list = []
        for check in record["checks"]:
            desired_data = {
            "dob": record["dob"],
            "storeId": record["storeId"],
            "id": check["id"]
                }
            desired_data_list.append(desired_data)

        return {
            "storeId": desired_data_list[0]["storeId"],
            "dob": desired_data_list[0]["dob"],
            "id": desired_data_list[0]["id"],
            }
I tried moving the return into the loop, but it will still only return on check detail. There should be hundreds is anyone able to suggest a solution or see where the errors are in my code? Thank you for any help Tim
e
Hi Tim! I don't think you're doing anything wrong. The parent-child API currently assumes there's a one-to-one mapping between parent records and child syncs. It's probably not too hard to support fanning out each parent into zero or more child syncs. I'll open an issue.
t
Morning Edgar Thank you for you reply, you have been very generous with your time and knowledge and I appreciate it. Do I have to wait for the method to be added and then have to update the Tap framework?
e
That's correct. We probably won't prioritize it internally for some time but feel free to comment on the issue, leave a 👍, or even contribute a pull request 😄
t
👍