Re: How do I recreate a data source export using the Zuora API?

Reply
DavidW Z-Documentation Team

Z-Documentation Team

Z-Documentation Team
Posts: 14
Registered: ‎08-23-2016
Accepted Solution

How do I recreate a data source export using the Zuora API?

I've used the Zuora UI to generate a data source export (as explained in Generate a Data Source Export) and I can access the exported data in the Zuora UI:

 

Export_Result.png

 

Now I'd like to generate the same export again using the Zuora API. How can I do that?

DavidW Z-Documentation Team

Z-Documentation Team

Z-Documentation Team
Posts: 14
Registered: ‎08-23-2016

Re: How do I recreate a data source export using the Zuora API?

[ Edited ]

When you used the Zuora UI to generate the data source export, Zuora internally created an Export object in your tenant. This Export object contains information about the export, such as the status of the export and the Export ZOQL query that specifies which data was exported from your tenant.

 

To recreate the export using the Zuora API, you will first need to get the contents of the Export object. The simplest way to do this is to call POST /v1/action/query with the following request body:

 

{
  "queryString": "select Id, Status, Query from Export where CreatedDate >= 2017-11-28T00:00:00"
}

Replace 2017-11-28 by today's date. The response will list the Export objects that were created in your tenant today. For example:

 

{
  "records": [
    {
      "Status": "Completed",
      "Query": "select Invoice.Amount, Invoice.InvoiceDate, Invoice.InvoiceNumber, Invoice.Status, Account.AccountNumber from Invoice where Invoice.Status = 'Posted'",
      "Id": "2c92c0f85fde706f016000b3f9aa308e"
    }
  ],
  "size": 1,
  "done": true
}

Locate the Export object that corresponds to your data source export, then note down the value of Query. This value is the Export ZOQL query that specifies which data was exported from your tenant. You should notice that the query matches the fields and filters that you selected in the Zuora UI.

 

You are now ready to recreate the export using the Zuora API.

 

NOTE: You cannot use POST /v1/action/query to recreate the data source export. This API operation supports ZOQL queries, which are less powerful than Export ZOQL queries, and is intended to be used to quickly return a small number of results.

 

Recreate the Data Source Export

 

  1. Use CRUD: Create Export to create an Export object. Specify the Export ZOQL query in the request body.

     

    Example request body:

     

    {
      "Format": "csv",
      "Query": "select Invoice.Amount, Invoice.InvoiceDate, Invoice.InvoiceNumber, Invoice.Status, Account.AccountNumber from Invoice where Invoice.Status = 'Posted'"
    }
    

    Example response body:

     

    {
      "Success": true,
      "Id": "2c92c0f95fde79bd016001277b166638"
    }
    

    Note down the value of Id. This is the internal ID of the Export object. You will need this ID in the next step.

     

  2. Use CRUD: Retrieve Export to get the contents of the Export object.

     

    Example request URL:

     

    GET /v1/object/export/2c92c0f95fde79bd016001277b166638
    

    Example response body:

     

    {
      "Zip": false,
      "Query": "select Invoice.Amount, Invoice.InvoiceDate, Invoice.InvoiceNumber, Invoice.Status, Account.AccountNumber from Invoice where Invoice.Status = 'Posted'",
      "Encrypted": false,
      "CreatedById": "2c92c0f956bc8fcb0156f8eee04b4d54",
      "CreatedDate": "2017-11-28T06:44:12.000+01:00",
      "FileId": "2c92c0855fde7093016001277cdf2b0d",
      "Size": 76,
      "Id": "2c92c0f95fde79bd016001277b166638",
      "Status": "Completed",
      "UpdatedById": "2c92c0f956bc8fcb0156f8eee04b4d54",
      "UpdatedDate": "2017-11-28T06:44:13.000+01:00",
      "Format": "csv"
    }
    

    If the value of Status is Completed, you can access the exported data. If the value of Status is Pending or Processing, retry the API call after allowing some time for the export to complete.

     

    Note down the value of FileId. This is the internal ID of the exported data file. You will need this ID in the next step.

     

  3. Use Get files to download the exported data.

     

    Example request URL:

     

    GET /v1/files/2c92c0855fde7093016001277cdf2b0d
    

    The response contains the exported data file.

Highlighted
bolaurent Master

Master

Master
Posts: 99
Registered: ‎04-10-2016

Re: How do I recreate a data source export using the Zuora API?

My zuora query command line utility does this for you; the code might be useful to look at, even if you are not writing python.

 

See python-cmdline-zoql. The code snippet (from zuora_restful_python) is:

 

    def query_export(self, query):
        export_id = self.create_export('temp.csv', query)
        export_response = self.retrieve_export(export_id, block=True)
        if export_response['Status'] != 'Completed':
            return export_response

        file_response = self.get_files(export_response['FileId'])
        self.delete_export(export_id)
        return file_response