简体   繁体   English

如何使用 REST API 获取 Zuora 帐户的集合

[英]How to fetch collection of Zuora Accounts using REST API

I want to fetch all customer accounts from Zuora.我想从 Zuora 获取所有客户帐户。 Apart from Exports REST API, Is there any API available to fetch all accounts in a paginated list?除了导出REST API,是否有任何 API 可用于获取分页列表中的所有帐户?

This is the format I used to fetch revenue invoices, use this code and change the endpoint这是我用来获取收入发票的格式,使用此代码并更改端点

import pandas as pd

# Set the sleep time to 10 seconds
sleep = 10

# Zuora OAUTH token URL
token_url = "https://rest.apisandbox.zuora.com/oauth/token"

# URL for the DataQuery
query_url = "https://rest.apisandbox.zuora.com/query/jobs"

# OAUTH client_id & client_secret
client_id = 'your client id'
client_secret = 'your client secret'

# Set the grant type to client credential
token_data = {'grant_type': 'client_credentials'}

# Send the POST request for the OAUTH token
access_token_resp = requests.post(token_url, data=token_data,
                                      auth=(client_id, client_secret))

# Print the OAUTH token respose text
#print access_token_resp.text

# Parse the tokens as json data from the repsonse
tokens = access_token_resp.json()
#print "access token: " + tokens['access_token']

# Use the access token in future API calls & Add to the headers
query_job_headers = {'Content-Type':'application/json',
    'Authorization': 'Bearer ' + tokens['access_token']}

# JSON Data for our DataQuery
json_data = {
        "query": "select * from revenuescheduleiteminvoiceitem",
        "outputFormat": "JSON",
        "compression": "NONE",
        "retries": 3,
        "output": {
                "target": "s3"
        }
}

# Parse the JSON output
data = json.dumps(json_data)

# Send the POST request for the dataquery
query_job_resp = requests.post(query_url, data=data,
                                  headers=query_job_headers)
# Print the respose text
#print query_job_resp.text

# Check the Job Status

# 1) Parse the Query Job Response JSON data
query_job = query_job_resp.json()

# 2) Create the Job URL with the id from the response
query_job_url = query_url+'/'+query_job["data"]["id"]

# 3) Send the GETrequest to check on the status of the query
query_status_resp = requests.get(query_job_url, headers = query_job_headers)
#print query_status_resp.text

# Parse the status from teh response
query_status = query_status_resp.json()["data"]["queryStatus"]
#print ('query status:'+query_status)

# Loop until the status == completed
# Exit if there is an error
while (query_status != 'completed'): 
    time.sleep(sleep)
    query_status_resp = requests.get(query_job_url, headers = query_job_headers)
    #print query_status_resp.text
    query_status = query_status_resp.json()["data"]["queryStatus"]
    if (query_status == 'failed'):
        print ("query: "+query_status_resp.json()["data"]["query"]+' Failed!\n')
        exit(1)

# Query Job has completed
#print ('query status:'+query_status)


# Get the File URL
file_url = query_status_resp.json()["data"]["dataFile"]
print (file_url)```

If you don't want to use Data Query or any queue-based solution like that, use Zoql instead.如果您不想使用数据查询或任何类似的基于队列的解决方案,请改用Zoql
Note !注意 You need to know all fields from the Account object you need, the asterisk ( select * ) doesn't work here:您需要知道您需要的 Account 对象中的所有字段,星号( select * )在这里不起作用:

select Id, ParentId, AccountNumber, Name from Account

You may also add custom fields into your selection.您还可以将自定义字段添加到您的选择中。 You will get up to 200 records per page.每页最多可获得 200 条记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用REST API直接执行Zuora ZOQL查询 - How to execute Zuora ZOQL query directly using REST API 通过Zuora REST API执行ZOQL - ZOQL Execution via Zuora REST API 如何使用PHP更新Zuora中的付款方式 - How to update payment method in Zuora using PHP 如何使用REST API使用angularjs删除集合? - How to delete collection with angularjs using REST api? 如何使用Firestore API从集合中获取所有文档? - How to fetch all documents from a collection using Firestore API? 如何使用他们的REST API在WooCommerce中一起获取所有订单 - How to fetch all orders together in WooCommerce using their REST API 如何使用 Shopify REST API 在日期范围内获取订单? - How to fetch orders between date range using Shopify REST API? 如何使用REST API从Sugarcrm获取所有帐户记录,包括已删除的记录 - how to get all accounts records including deleted records from sugarcrm using REST api 使用 REST API 向 Google Cloud Platform 上的服务帐户添加角色 - Adding roles to service accounts on Google Cloud Platform using REST API 使用 VBA 通过 REST API 向 Spotify Accounts 服务发出 POST 请求 - Using VBA for a POST request to the Spotify Accounts service via REST API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM