Best answer

`create_invoice` action throwing an "Unexpected string" error.

  • 29 September 2021
  • 5 replies
  • 115 views

Hi all,

I create an action, testing and running it’s still returning Unexpected string.

 

Unexpected string What happened (You are seeing this because you are an admin): Executing creates.create_invoice.operation.perform with bundle Unexpected string

Console logs: Stack trace: SyntaxError: Unexpected string at new AsyncFunction (<anonymous>) at makeFunction (/var/task/node_modules/zapier-platform-core/src/tools/schema-tools.js:11:39) at replacer (/var/task/node_modules/zapier-platform-core/src/tools/schema-tools.js:40:17) at recurseReplace (/var/task/node_modules/zapier-platform-core/src/tools/data.js:107:11) at Object.keys.map.key (/var/task/node_modules/zapier-platform-core/src/tools/data.js:117:21) at Array.map (<anonymous>) at recurseReplace (/var/task/node_modules/zapier-platform-core/src/tools/data.js:115:22) at Object.keys.map.key (/var/task/node_modules/zapier-platform-core/src/tools/data.js:117:21) at Array.map (<anonymous>) at recurseReplace (/var/task/node_modules/zapier-platform-core/src/tools/data.js:115:22) at Object.keys.map.key (/var/task/node_modules/zapier-platform-core/src/tools/data.js:117:21) at Array.map (<anonymous>) at recurseReplace (/var/task/node_modules/zapier-platform-core/src/tools/data.js:115:22) at Object.keys.map.key (/var/task/node_modules/zapier-platform-core/src/tools/data.js:117:21) at Array.map (<anonymous>) at Object.recurseReplace (/var/task/node_modules/zapier-platform-core/src/tools/data.js:115:22) at Object.findSourceRequireFunctions (/var/task/node_modules/zapier-platform-core/src/tools/schema-tools.js:48:22) at compileApp (/var/task/node_modules/zapier-platform-core/src/tools/schema.js:106:24) at Object.prepareApp (/var/task/node_modules/zapier-platform-core/src/tools/schema.js:180:23) at createApp (/var/task/node_modules/zapier-platform-core/src/create-app.js:26:41) at loadApp.then.appRaw (/var/task/node_modules/zapier-platform-core/src/tools/create-lambda-handler.js:201:23) at bound (domain.js:402:14)

 

 

The code I use

const data = {
    [
        {
           'amountGross': bundle.inputData.amountGross,
            'amountNet': bundle.inputData.amountNet,
            'externalId': bundle.inputData.externalId,
            'externalRef': bundle.inputData.externalRef,
            'linkDoc': bundle.inputData.linkDoc,
            'invoiceNumber': bundle.inputData.invoiceNumber,
            'currency': bundle.inputData.currency,
            'externalCreatedDate': bundle.inputData.externalCreatedDate
            'invoiceState': bundle.inputData.invoiceState,
            'expectedDate': bundle.inputData.expectedDate,
            'dueDate': bundle.inputData.dueDate,
            'updatedDate': bundle.inputData.updatedDate,
            'client': {
              'name': bundle.inputData.name,
              'vatNumber': bundle.inputData.vatNumber,
              'exIdClient': bundle.inputData.exIdClient,
              'cf': bundle.inputData.cf,
              'address': bundle.inputData.address,
              'zipCode': bundle.inputData.zipCode,
              'city': bundle.inputData.city,
              'province': bundle.inputData.province,
              'addressExtra': bundle.inputData.addressExtra,
              'pec': bundle.inputData.pec,
              'email': bundle.inputData.email,
              'country': bundle.inputData.country,
              'telephone': bundle.inputData.telephone,
              'defaultPaymentDays': bundle.inputData.defaultPaymentDays
            }
        }
    ]
}

const options = {
  url: 'https://nibi2f2m6a.execute-api.us-east-1.amazonaws.com/memento-api/' + bundle.authData.merchantId,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'X-API-KEY': bundle.authData['Api-Key'],
    'X-API-SECRET': bundle.authData['Api-Secret']
  },
  params: {
    'Api-Key': bundle.authData['Api-Key'],
    'Api-Secret': bundle.authData['Api-Secret']
  },
  body: JSON.stringify(data),
}

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const results = response.json;

    // You can do any parsing you need for results here before returning them

    return results;
  });

 

Can somebody help me to find the solution

 

Thank you 

Rinaldo 

icon

Best answer by Zane 29 September 2021, 20:21

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 +14

Hi @Rinaldo Bonazzo 

What app and action are you using that is returning the error string?

Perhaps it’d be best to post some screenshots as well.

hi @Troy Tessalone  thanks for answer.

i am creating my zap which connects to my bflows system and loads the invoices according to the defined structure. I get the parameters and execute the call.

The name of my app is Bflows and the action is create_invoice

 

Tell what kind of screenshot may I share 

Thank you 

Userlevel 7
Badge +14

@Zane Can you advise?

Userlevel 7
Badge +9

I see a few problems with the data variable. I needs to be valid JSON for JSON.stringify to serialize it. Taking the declaration alone and printing the result of stringify… 

 

 

A couple of things:

 

  • 'externalCreatedDate': bundle.inputData.externalCreatedDate  needs a comma after it.
  • Wrapping a bare array in {} is not valid JSON and JSON.stringify is going to throw an error on that.

Hi @Troy Tessalone due your suggestion 

everything is working fine.

Thanks a lot for your great help 

 

Rinaldo