Exporting datatables via Platform API CLI

I am trying to export data tables using the API, specifically using the GC tool. The problem I'm having is accessing the data table CSV file after creating the job.

Example:

$ gc flows datatables export jobs create xxxxxxxx-f35e-4853-b125-c2ba1f4200d4
{
  "id": "xxxxxxxx-2e46-4b9e-b131-b421887fb729",
  "owner": {
    "id": "xxxxxxxx-9032-4c5b-8a16-15dbbb16d152",
    "selfUri": "/api/v2/users/xxxxxxxx-9032-4c5b-8a16-15dbbb16d152"
  },
  "status": "Processing",
  "dateCreated": "2023-11-06T09:53:37Z",
  "countRecordsProcessed": 0
}

This succeeds, and I can the get the status of the job, which returns a URL to download the CSV file from:

$ gc flows datatables export jobs get xxxxxxxx-f35e-4853-b125-c2ba1f4200d4 xxxxxxxx-2e46-4b9e-b131-b421887fb729
{
  "id": "xxxxxxxx-2e46-4b9e-b131-b421887fb729",
  "status": "Succeeded",
  "dateCreated": "2023-11-06T09:53:37Z",
  "dateCompleted": "2023-11-06T09:53:37Z",
  "downloadURI": "https://api.mypurecloud.de/api/v2/downloads/xxxx73317bf9ec0a",
  "countRecordsProcessed": 6
}

I can access this file simply using my browser as I'm already authenticated, but how do I pull the file (e.g., curl or wget)? What authentication token do I need to use?

Simply attempting to pull the file using curl or wget does not work, so I assume it needs an authentication token, I just do not know what to provide. I have tried passing username/password in both plain text and also in base64 using curl.

Hi Andrew

With most file exports, you need to pass the download ID at the end of the downloadURI ("xxxx73317bf9ec0a" in your case) to the endpoint GET /api/v2/downloads/{downloadId} to get the url that will work on a simple curl request.

After trying it myself, it didn't work as expected, so you might want to ask the Architect team or possibly the team in charge of the downloads service. If you find the solution, please to post it here for future forum users to find should they encounter this obstacle.

-Charlie

1 Like

@raindog

So the call to GET /api/v2/downloads/{downloadId} was not working for me originally, but after trying it with a different data table, it worked okay.

After your call to GET /api/v2/flows/datatables/{datatableId}/export/jobs/{exportJobId}, you received a downloadURI "https://api.mypurecloud.de/api/v2/downloads/xxxx73317bf9ec0a"

You now want to take the download ID at the end (xxxx73317bf9ec0a) and pass it to GET /api/v2/downloads/{downloadId}.

The CLI command looks like this:

gc downloads get <download ID> --issueRedirect=false

This should return a url. From here you can run a simple curl request to pull the file using this url.

curl "<url>" --output ./datatabeX.csv

Hope this helps
-Charlie

Excellent, this works - be sure to wrap the URL in quotes. Thank you for researching this it has really helped.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.