Example #1
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = common.init(argv, __doc__, parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id

    if not account_id:
        account_id = merchant_id
    elif merchant_id != account_id:
        common.check_mca(
            config,
            True,
            msg='Non-multi-client accounts can only get their own information.'
        )

    status = service.accountstatuses().get(merchantId=merchant_id,
                                           accountId=merchant_id).execute()
    print('Account %s:' % status['accountId'])
    issues = status.get('dataQualityIssues')
    if not issues:
        print('- No data quality issues.')
        return
    print('- Found %d data quality issues:' % len(issues))
    for issue in issues:
        print('  - (%s) [%s]' % (issue['severity'], issue['id']))
        items = issue.get('exampleItems')
        if not items:
            print('    No example items.')
            continue
        print('    Have %d examples from %d affected items:' %
              (len(items), issue['numItems']))
        for example in items:
            print('    - %s: %s' % (example['itemId'], example['title']))
def main(argv):
    # Authenticate and construct service.
    service, config, flags = common.init(argv, __doc__, parents=[argparser])
    merchant_id = config['merchantId']
    account_ids = flags.account_ids
    common.check_mca(config, True)

    batch = {
        'entries': [{
            'batchId': i,
            'merchantId': merchant_id,
            'method': 'delete',
            'accountId': v,
        } for i, v in enumerate(account_ids)],
    }

    request = service.accounts().custombatch(body=batch)
    result = request.execute()

    if result['kind'] == 'content#accountsCustomBatchResponse':
        entries = result['entries']
        for entry in entries:
            errors = entry.get('errors')
            if errors:
                print('Errors for batch entry %d:' % entry['batchId'])
                print(
                    json.dumps(errors,
                               sort_keys=True,
                               indent=2,
                               separators=(',', ': ')))
            else:
                print('Account %s deleted (batch entry %d).' %
                      (account_ids[entry['batchId']], entry['batchId']))
    else:
        print('There was an error. Response: %s' % result)
Example #3
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = common.init(argv, __doc__, parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id

    if not account_id:
        account_id = merchant_id
    elif merchant_id != account_id:
        common.check_mca(
            config,
            True,
            msg='Non-multi-client accounts can only get their own information.'
        )

    status = service.accounttax().get(merchantId=merchant_id,
                                      accountId=merchant_id).execute()
    print('Account %s:' % status['accountId'])
    rules = status.get('rules')
    if not rules:
        print('- No tax settings, so no tax is charged.')
        return
    print('- Found %d tax rules:' % len(rules))
    for rule in rules:
        rate_percent = rule.get('ratePercent')
        if rate_percent:
            print('  - For %s in %s: %s%%' %
                  (rule['locationId'], rule['country'], rate_percent))
        use_global = rule.get('useGlobalRate')
        if use_global:
            print('  - For %s in %s: using the global tax table rate.' %
                  (rule['locationId'], rule['country']))
        taxed_shipping = rule.get('shippingTaxed')
        if taxed_shipping:
            print('   NOTE: Shipping charges are also taxed.')
Example #4
0
def main(argv):
    # Authenticate and construct service.
    service, config, _ = common.init(argv, __doc__)
    merchant_id = config['merchantId']
    common.check_mca(config, True)

    request = service.accountstatuses().list(merchantId=merchant_id,
                                             maxResults=MAX_PAGE_SIZE)

    while request is not None:
        result = request.execute()
        statuses = result.get('resources')
        if not statuses:
            print('No statuses were returned.')
            break
        for status in statuses:
            print('Account %s:' % status['accountId'])
            issues = status.get('dataQualityIssues')
            if not issues:
                print('- No data quality issues.')
                continue
            print('- Found %d data quality issues:' % len(issues))
            for issue in issues:
                print('  - (%s) [%s]' % (issue['severity'], issue['id']))
                items = issue.get('exampleItems')
                if not items:
                    print('    No example items.')
                    continue
                print('    Have %d examples from %d affected items:' %
                      (len(items), issue['numItems']))
                for example in items:
                    print('    - %s: %s' %
                          (example['itemId'], example['title']))
        request = service.accountstatuses().list_next(request, result)
Example #5
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = common.init(argv, __doc__, parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id
    common.check_mca(config, True)

    request = service.accounts().delete(merchantId=merchant_id,
                                        accountId=account_id)
    request.execute()
    print('Account %s was deleted.' % account_id)
Example #6
0
def main(argv):
  # Authenticate and construct service.
  service, config, flags = common.init(
      argv, __doc__, parents=[argparser])
  merchant_id = config['merchantId']
  product_id = flags.product_id
  common.check_mca(config, False)

  status = service.productstatuses().get(
      merchantId=merchant_id, productId=product_id).execute()

  print('- Product "%s" with title "%s":' %
        (status['productId'], status['title']))
  print(json.dumps(status, sort_keys=True, indent=2, separators=(',', ': ')))
Example #7
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = common.init(argv, __doc__, parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id
    common.check_mca(config, True)

    new_name = 'updated-account%s' % common.get_unique_id()
    request = service.accounts().patch(merchantId=merchant_id,
                                       accountId=account_id,
                                       body={'name': new_name})

    result = request.execute()
    print('Account with id %s was updated with new name "%s".' %
          (account_id, result['name']))
Example #8
0
def main(argv):
    # Authenticate and construct service.
    service, config, _ = common.init(argv, __doc__)
    merchant_id = config['merchantId']
    common.check_mca(config, True)

    name = 'account%s' % common.get_unique_id()
    account = {'name': name, 'websiteUrl': 'https://%s.example.com/' % name}

    # Add account.
    request = service.accounts().insert(merchantId=merchant_id, body=account)

    result = request.execute()

    print('Created sub-account ID %s for MCA %d.' %
          (result['id'], merchant_id))
Example #9
0
def main(argv):
  # Authenticate and construct service.
  service, config, _ = common.init(argv, __doc__)
  merchant_id = config['merchantId']
  common.check_mca(config, True)

  request = service.accounts().list(
      merchantId=merchant_id, maxResults=MAX_PAGE_SIZE)

  while request is not None:
    result = request.execute()
    accounts = result.get('resources')
    if not accounts:
      print('No accounts were found.')
      break
    for account in accounts:
      print('Account %s with name "%s" was found.' %
            (account['id'], account['name']))
    request = service.accounts().list_next(request, result)
Example #10
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = common.init(argv, __doc__, parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id

    if not account_id:
        account_id = merchant_id
    elif merchant_id != account_id:
        common.check_mca(
            config,
            True,
            msg='Non-multi-client accounts can only get their own information.'
        )

    account = service.accounts().get(merchantId=merchant_id,
                                     accountId=merchant_id).execute()
    print('Account %s with name "%s" was found.' %
          (account['id'], account['name']))
Example #11
0
def main(argv):
  # Authenticate and construct service.
  service, config, _ = common.init(argv, __doc__)
  merchant_id = config['merchantId']
  common.check_mca(config, False)

  request = service.productstatuses().list(
      merchantId=merchant_id, maxResults=MAX_PAGE_SIZE)

  while request is not None:
    result = request.execute()
    statuses = result.get('resources')
    if not statuses:
      print('No product statuses were returned.')
      break
    for stat in statuses:
      print('- Product "%s" with title "%s":' %
            (stat['productId'], stat['title']))
      print(json.dumps(stat, sort_keys=True, indent=2, separators=(',', ': ')))
    request = service.productstatuses().list_next(request, result)
Example #12
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = common.init(argv, __doc__, parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id

    if not account_id:
        account_id = merchant_id
    elif merchant_id != account_id:
        common.check_mca(
            config,
            True,
            msg='Non-multi-client accounts can only get their own information.'
        )

    status = service.shippingsettings().get(merchantId=merchant_id,
                                            accountId=merchant_id).execute()
    print('Account %s:' % status['accountId'])
    postal_groups = status.get('postalCodeGroups')
    if not postal_groups:
        print('- No postal code groups.')
    else:
        print('- %d postal code group(s):' % len(postal_groups))
    services = status.get('services')
    if not services:
        print('- No services.')
    else:
        print('- %d service(s):' % len(services))
        for service in services:
            print('  Service "%s":' % service['name'])
            print('  - Delivery country: %s' % service['deliveryCountry'])
            print('  - Currency: %s' % service['currency'])
            print('  - Active: %s' % service['active'])
            print('  - Delivery time: %d - %d days' %
                  (service['deliveryTime']['minTransitTimeInDays'],
                   service['deliveryTime']['maxTransitTimeInDays']))
            rate_groups = service.get('rateGroups')
            if not rate_groups:
                print('  - No rate groups.')
            else:
                print('  - %d rate group(s).' % len(rate_groups))
Example #13
0
def main(argv):
  # Authenticate and construct service.
  service, config, _ = common.init(argv, __doc__)
  merchant_id = config['merchantId']
  common.check_mca(config, True)

  account_names = [
      'account%s' % common.get_unique_id() for i in range(BATCH_SIZE)
  ]
  batch = {
      'entries': [{
          'batchId': i,
          'merchantId': merchant_id,
          'method': 'insert',
          'account': {
              'name': v,
              'websiteUrl': 'https://%s.example.com/' % v,
          },
      } for i, v in enumerate(account_names)],
  }

  request = service.accounts().custombatch(body=batch)
  result = request.execute()

  if result['kind'] == 'content#accountsCustomBatchResponse':
    for entry in result['entries']:
      account = entry.get('account')
      errors = entry.get('errors')
      if account:
        print('Account %s with name "%s" was created.' %
              (account['id'], account['name']))
      elif errors:
        print('Errors for batch entry %d:' % entry['batchId'])
        print(json.dumps(errors, sort_keys=True, indent=2,
                         separators=(',', ': ')))
  else:
    print('There was an error. Response: %s' % result)