我想使用OVH API在OVH with Python中添加一个新的DNS区域。
我写了一个脚本,包含以下步骤:
- 创建新购物车
- 将新DNS区域添加到购物车
- 查看购物车内容
- 确认订单
- 查看订单状态
我是否忘记了某个步骤或者哪里出错了?因为当我查看GET订单时,我没有看到新订单,而且它们也没有出现在GUI中。
cart = client.post('/order/cart', ovhSubsidiary='PL')
#Get the cart ID
cart_id = cart.get('cartId')
#Set data for the new DNS zone
zone_name = 'testttt.pl' # DNS zone name
#Add the new DNS zone to the cart
result = client.post(f'/order/cart/{cart_id}/dns',
domain=zone_name,
duration="P1Y",
planCode="zone",
pricingMode="default",
quantity=1)
#Check if the operation was successful
if 'itemId' in result:
print(f'DNS zone {zone_name} was added to the cart.')
else:
print('Error while adding DNS zone to the cart.')
#Display the cart contents
cart_info = client.get(f'/order/cart/{cart_id}')
print(f'Cart contents:\n{json.dumps(cart_info, indent=4)}')
#Make sure the cart is ready to order
order = client.post(f'/order/cart/{cart_id}/checkout', autoPayWithPreferredPaymentMethod=True)
print(f'Order {order.get("orderId")} has been placed.')
order_id = cart_info['orders'][-1]
#Check the status of the order
order_status = client.get(f'/me/order/{order_id}/status')
print(f'Order {order_id} status: {order_status}')```
1条答案
按热度按时间nnsrf1az1#
创建购物车后,在将您的DNS区域(或任何其他产品)添加到此购物车之前,您需要将此购物车 * 分配 * 给自己。
可以通过以下途径完成:
因此,您的脚本应如下所示: