Skip to main content
Question

parse XML response in zapier custom app

  • May 28, 2022
  • 1 reply
  • 844 views

Hi I am trying to create an zapier custom app but when I am trying to do a search and parse the response. It returns an xml which is correct response from the service. This is a rest service but uses XMLs only.
This is highrise api  I am trying to use:  https://github.com/basecamp/highrise-api

I get an error it does not recognize the xml format.
This is my code
I tried referencing these zapier docs here
https://platform.zapier.com/legacy/scripting
I looked at the Trigger Post-Poll Examples 

When i try to use some of the code from there. It did not recognize * or $ 

So any help on how could parse response and get certain fields for the below will help.
Is there any other docs for the scripting for the xml ?
xml snippet from the Legacy docs

my*xml_doc_post_poll: function(bundle) {
// bundle.response.content is xml string from API, $ is preloaded jQuery
    var xml = $(\$.parseXML(bundle.response.content)).find('message');
// build javascript primitives: array of objects
var results = *.map(xml, function(element){
return {
id: $(element).find('id').text(),
        title: $(element).find('title').text(),
body: \$(element).find('body').text()
};
});




If someone could help me with the below that will be great thank you.
The request i currently using

const options = {
  url: `${bundle.authData.Highrise_BaseUrl}/people/search.xml`,
  method: 'GET',
  headers: {
    'Authorization': `Basic ${bundle.authData.Authorization}`,
    'Accept': 'application/xml'
  },
  params: {
    'term': `${bundle.inputData.firstname}+${bundle.inputData.last_name}`
  }
}

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

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

    return results;
  });

Error message
#####################

Invalid API Response: - Results must be an array, got: object, ({"status":200,"content":"<?xml version=\"1.0\" enc) What happened (You are seeing this because you are an admin): Executing searches.search_contact_by_fullname.operation.perform with bundle Invalid API Response: - Results must be an array, got: object, ({"status":200,"content":"<?xml version=\"1.0\" enc) Console logs: Stack trace: CheckError: Invalid API Response: - Results must be an array, got: object, ({"status":200,"content":"<?xml version=\"1.0\" enc) at checkOutput (/var/task/node_modules/zapier-platform-core/src/app-middlewares/after/checks.js:42:15) at Object.<anonymous> (/var/task/node_modules/zapier-platform-core/src/middleware.js:80:37) at bound (domain.js:421:15) at Object.runBound (domain.js:432:12) at Object.tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:547:31) at Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:604:18) at Promise._settlePromiseCtx (/var/task/node_modules/bluebird/js/release/promise.js:641:10) at _drainQueueStep (/var/task/node_modules/bluebird/js/release/async.js:97:12) at _drainQueue (/var/task/node_modules/bluebird/js/release/async.js:86:9) at Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:102:5) at Immediate.Async.drainQueues [as _onImmediate] (/var/task/node_modules/bluebird/js/release/async.js:15:14) at processImmediate (internal/timers.js:464:21) at process.topLevelDomainCallback (domain.js:152:15) at process.callbackTrampoline (internal/async_hooks.js:128:24)

#####################

Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Forum|alt.badge.img+9
  • Zapier Staff
  • 331 replies
  • June 3, 2022