question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a BlockIP entry

See original GitHub issue

Kudos for a good library. I’m trying to create a block IP criterion for a campaign and it’s failing with the following error:

"Fault": { "faultcode": "soap:Client", "faultstring": "Unexpected wrapper element mutate found. Expected {https://adwords.google.com/api/adwords/cm/v201609}mutate." }

I’m following the PHP library as advised and as a matter of fact have a working implementation of the same functionality in PHP with the one difference - in PHP I’m instantiating a NegativeCampaignCriterion which I’m not able to do here since the lib is using a standard object notation. This is why this looks like an issue with the library itself.

These are the methods/entities used:

Here’s my implementation:

blockIp(accountNumber,campaignId,ip) {
    var _this = this;

    return _this.configure().then(function onApiConfigured() {
      // prepare
      var user = _this.prepareUser(accountNumber);
      var service = user.getService('CampaignCriterionService', _this.gapi.version);

      // build
      var criterion = {
        campaignId: campaignId,
        isNegative: true,
        criterion: { ipAddress: ip }
      };
      var operation = { operator: 'ADD', operand: criterion };

      // wrap the call in a promise
      return new Promise(function executeBlockIp(resolve,reject) {
        service.mutate([operation], function onBlockIpDone(err, result) {
          if(err) {
            reject({ message: 'Google API error', error: err });
          }
          else {
            resolve(result);
          }
        });
      });
    });
  }

Please note that _this.prepareUser(accountNumber); is working in other functionality implementations so there are no hidden problems, just the fact I seem to be failing at implementing this operation.

Can you advise? Needless to say I will appreciate a quick reply and assistance.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ChrisAlvarescommented, Mar 22, 2017

Yes, it is functional. There are a ton of examples inside the test folder: https://github.com/ChrisAlvares/node-adwords/blob/master/test/adwords/services

and the readme explains how to use it.

0reactions
Nastromocommented, Dec 26, 2018

Additionally, here’s a fully working example of removing the IP block using the lib:

  /**
   * Attempts to unblock an IP address for a campaign
   *
   * @param {String} accountNumber
   * @param {String} campaignId
   * @param {String} blockId
   * @return {Promise}
   */
  unblockIp(accountNumber,campaignId,blockId) {
    debug(`Unblocking IP address on campaign {$campaignId} for account number ${accountNumber}.`);
    var _this = this;

    return _this.configure().then(function onApiConfigured() {
      // prepare
      var user = _this.prepareUser(accountNumber);
      var service = user.getService('CampaignCriterionService', _this.gapi.version);

      // build
      var criterion = {
        campaignId: campaignId,
        isNegative: true,
        criterion: {
          id: blockId,
          type: 'IP_BLOCK',
          'Criterion.Type': 'IpBlock'
        },
        'CampaignCriterion.Type': 'NegativeCampaignCriterion'
      };
      var operation = { operator: 'REMOVE', operand: criterion };

      // wrap the call in a promise
      return new Promise(function executeBlockIp(resolve,reject) {
        service.mutate({operations: [operation]}, function onBlockIpDone(err, result) {
          if(err) {
            debug(`Error unblocking IP address.`);
            reject({ message: 'Google API error', error: err });
          }
          else {
            debug(`Successfully unblocked IP address.`);
            resolve();
          }
        });
      });
    });
  }

Where did you get the id (blockId) in you criterion?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ipset to block IP addresses - firewall
It really helps in easily adding IP addresses and maintaining IP address blocklists. The below guide sets up ipset to block a list...
Read more >
Add-IPBlockListEntry (ExchangePowerShell) - Microsoft Learn
Use the Add-IPBlockListEntry cmdlet to add IP Block list entries to the IP Block list that's used by the Connection Filtering agent on...
Read more >
How to Block an IP Address (IP Deny Tool, Cloudflare, Nginx ...
How to Identify Troublesome IP Addresses; How to Block IP ... To create a new IP access rule, add an IP address, select...
Read more >
Add IP address to cPanel account's block list
Add IP address to cPanel account's block list. This function blocks IP addresses from accessing the domains on a cPanel account. Important.
Read more >
Windows Firewall Block IP Address / Blacklist - YouTube
How to create an IP block rule in the Firewall rules page.If you are using Windows and have not installed a "complete" security...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found