Best answer

Handling Line Items as Objects

  • 26 April 2020
  • 5 replies
  • 3869 views

Userlevel 7
Badge +10

Hi all, building an app on the Zapier Platform to integrate with Freshbooks since the native Freshbooks app doesn’t have the functionality I need. 

 

I need the line item section to be formatted like so:

 

   "lines": [

      {

        "name": "Test Item",

        "qty": "1",

        "unit_cost": {

          "amount": "27.00"

        }

      }

     ]

As seen here
However, when I test things in the Developer Platform under Test your API Request I get the following:

 

 "lines": [

      "{ 'name': 'Test Item'",

      "'qty': '1'",

      "'unit_cost': { 'amount': '27.00'  } }"

    ]

 

This is my current API Request configuration for those line items:

 

    'lines': [bundle.inputData.lines]

 

what function or formula do I need to put around the bundle.inputData.lines to prevent Zapier from separating it and adding quotes/commas?

 

When I submit this in the testing section I get the following error:

Required field "Name" (name) is missing. Required field "Quantity" (qty) is missing. Required field "Cost" (unit_cost__amount) is missing.

Which indicates that the name, qty, and unit_cost fields are not being recognized as fields due to the quotes Zapier adds. 

 

When I test it in a Zap I get the following error:

The app returned "Expected a nested dictionary".

Any Ideas?

icon

Best answer by PaulKortman 27 April 2020, 05:41

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

Userlevel 7
Badge +10

Argh, so I figured out what the problem was, and that is that Freshbooks wanted the price of a line item in a nested directory… so Zapier was formatting everything correctly… I just had to replace the value in “unit_cost”:”45” with {“amount”,”45”} to make “unit_cost”:{“amount”:”45”}

 

I did this by looping through the bundle like so:

 

var linesVar = bundle.inputData.lines

for( var am in linesVar ){

    linesVar[am].unit_cost = {"amount":linesVar[am].unit_cost}

}

 

and then I used the linesVar in place of bundle.inputDate.lines and Freshbooks accepted it and loved it!

Kinda fun to have solved this!

Userlevel 7
Badge +10

Yes

Userlevel 7
Badge +9

Yeah - I figured that you were creating an app - But the same logic, I think still applies.

You want to find a way to ensure that 

bundle.inputData.lines

is an array of objects, I think? 

Userlevel 7
Badge +10

@Saastronomical I haven’t been able to find any documentation on how line-item fields in an action step are provided to the bundle, just how to create line items via the CLI or via the UI. But is bundle.inputData.lines an array? An array of objects? or what? By default it seems to thing it’s a string as it puts quotes around it (by default). 

 

To be clear, I am talking about an app on the Zapier platform, not just a zap. I need to know how to handle it inside the app to be able to “parse” or get it formatted correctly for the way the API wants to receive it. 

Userlevel 7
Badge +9

Giving the answer I would give if I was testing, and not the answer I know to be true. 

 

BUT - Given then error you’re receiving - It seems to need a nested directory, which I would infer to be an array of arrays….

Is there no way to parse each line-item as an array?