Masive PDF download tool

I Epicor Users Help,

Hope you are doing great!

I want too see if you have any idea that could help me with this request.

I need a tool or way to get a bunch of customer shipment entry PDF files (like 6000 files) instead to generate one by one.

Those files are not save it in any windows server path, it should be generating any time that we need.

This is the menu that we use to generate:

We just put the pack id number, then just click on the printer icon to see the printer options and report style, then we just select the report style and finally we just make a click on the preview option to see the temporally pdf file after this we just save it to the local machine.

I think there should be a better way to get all these files (Like BPM) because do it one by one it’s going to take a few days.

I will appreciate any help.

Regards!

Create a python script to call the api.

Run one manually in kinetic with the dev menu open (F12)
Look at the calls it makes, copy the payloads. Thats the object you have to send to the api endpoint. There should only be a couple of fields that need changed for each packNum and they should be labeled easily enough to find. Then you can just loop through a list that you want and save the files to a local computer. Each task needs a unique taskNote so you can fetch it.

I threw a quick rough outline together.


import random
import time

class TaskStatus(Enum):
    Active = "ACTIVE"
    Pending = "PENDING"
    Complete = "COMPLETE"
    Error = "ERROR"
    MultipleTasks = "MULTIPLE_TASKS"
    FailedToFindTask = "FAILED_TO_FIND_TASK"

def calculateTaskNoteID():
    now = datetime.now()
    return str(now.year) + str(now.month) + str(now.day) + str(now.hour) + str(now.minute) + str(now.microsecond) + str(random.randint(0, 4294967295))


async def getTaskStatusFromTaskNote(taskNoteID):
    resp = await ApiRequest_Get("IceBo.SysTaskSvc/GetList?whereClause=TaskNote%20%3D%20%27" + taskNoteID + "%27&pageSize=100&absolutePage=0"
    )
    try:
        resp = resp["returnObj"]
        if len(resp["SysTaskList"]) > 1:
            return TaskStatus.MultipleTasks
        return TaskStatus(resp["SysTaskList"][0]["TaskStatus"])

    except:
        return TaskStatus.FailedToFindTask

async def getReportBytesFromSysRowID(sysRowID):
    return await ApiRequest_Post("IceBo.ReportMonitorSvc/GetReportBytes", {"sysRowId": sysRowID})

packReportObj = { #The Json object you got from the payload of the call
}

listOfPacks = [""]

async def main():

    for pack in listOfPacks:
       noteID = calculateTaskNoteID()
       packReportObj ["ds"]["SomeReportNameParams"][0]["TaskNote"] = noteID
       packReportObj ["ds"]["SomeReportNameParams"][0][PackNumField] = pack
       await apiPostToEpicorAPI_RPT/ReportService/SubmitToAgent (packReportObj)

       # Need to wait for task to finish       
       
      taskStatus = TaskStatus.Active
  
      while taskStatus == TaskStatus.Active or taskStatus == TaskStatus.Pending:
          time.sleep(5)
          print("Checking task status")
          taskStatus = await getTaskStatusFromTaskNote(noteID)
          print(taskStatus, " - ", TaskStatus.Active.value)


    if taskStatus == TaskStatus.Complete:
        task = (await getReportFromTaskNote(noteID))["returnObj"]["SysRptLstList"][0]

         pdfBytes = base64.b64decode((await getReportBytesFromSysRowID(task["SysRowID"]))["returnObj"])

        with open('reportPythonTest.pdf', 'wb') as f:
        f.write(pdfBytes)