Happy Business Starts Here

Re: How Can I Export a CSV in Node and transform the response stream into JSON objects?

Highlighted
Zuora Alumni

How Can I Export a CSV in Node and transform the response stream into JSON objects?

How Can I Export a CSV in Node and transform the response stream into JSON objects?



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Zuora Alumni

Re: How Can I Export a CSV in Node and transform the response stream into JSON objects?

This is a simple example meant as a reference for using our API's and transforming the result into a json object

 

It is not an example on how to write for node.js

 

Attached is the working sample code that generates objects with this schema

 

Account: { 
  Id: '2c92c0f95a246217015a29b6b7311576',
  Name: 'New Subscribe Account',
  Subscriptions: 
  [ 
    { 
      Id: '2c92c0f95a246217015a29b6b75d157a',
      Name: 'A-S00000076',
      Invoices: 
      [
        '2c92c0855a6b070f015aab4044d65dff' 
      ] 
    } 
  ],
  Invoices: 
  [ 
    { 
      Id: '2c92c0855a6b070f015aab4044d65dff',
      Number: 'INV00000063',
      Amount: '8',
      Source: 'BillRun',
      SourceId: 'BR-00000054',
      Items: 
      [
        { 
          Id: '2c92c0855a6b070f015aab4044d95e01',
          ChargeAmount: '1',
          ChargeDate: '2017-03-07T16:10:00-0800',
          SubscriptionId: '2c92c0f95a246217015a29b6b75d157a'
        }
      ] 
    } 
  ] 
}

 


Notes:

  • Technically, there can be many Subscriptions for a single invoice, so this example aggregates them at the Account level
  • there is a reference in the subscription to an array of invoices
  • each invoice item can only be associated to one invoice, so the id field is there for reference

Setup:

This example is importing the following libraries

 

npm install node-rest-client
npm install csvtojson
npm install node-json-transform
npm install hashmap

To run the example:

node test.js


References:



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

View solution in original post

2 REPLIES 2
Highlighted
Zuora Alumni

Re: How Can I Export a CSV in Node and transform the response stream into JSON objects?

This is a simple example meant as a reference for using our API's and transforming the result into a json object

 

It is not an example on how to write for node.js

 

Attached is the working sample code that generates objects with this schema

 

Account: { 
  Id: '2c92c0f95a246217015a29b6b7311576',
  Name: 'New Subscribe Account',
  Subscriptions: 
  [ 
    { 
      Id: '2c92c0f95a246217015a29b6b75d157a',
      Name: 'A-S00000076',
      Invoices: 
      [
        '2c92c0855a6b070f015aab4044d65dff' 
      ] 
    } 
  ],
  Invoices: 
  [ 
    { 
      Id: '2c92c0855a6b070f015aab4044d65dff',
      Number: 'INV00000063',
      Amount: '8',
      Source: 'BillRun',
      SourceId: 'BR-00000054',
      Items: 
      [
        { 
          Id: '2c92c0855a6b070f015aab4044d95e01',
          ChargeAmount: '1',
          ChargeDate: '2017-03-07T16:10:00-0800',
          SubscriptionId: '2c92c0f95a246217015a29b6b75d157a'
        }
      ] 
    } 
  ] 
}

 


Notes:

  • Technically, there can be many Subscriptions for a single invoice, so this example aggregates them at the Account level
  • there is a reference in the subscription to an array of invoices
  • each invoice item can only be associated to one invoice, so the id field is there for reference

Setup:

This example is importing the following libraries

 

npm install node-rest-client
npm install csvtojson
npm install node-json-transform
npm install hashmap

To run the example:

node test.js


References:



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

View solution in original post

Zuora Staff

Re: How Can I Export a CSV in Node and transform the response stream into JSON objects?

Great post Adam!