Godaddy api 使用

Godaddy API 参考文档

根据参考文档说明,获取到 keysecret

Python3 sdk 可以使用 godaddypy

环境信息

  • Python 3.11.2
  • godaddypy

godaddypy 主要提供了 2 个类,分别为

  • account - 使用 keysecretclient 生成鉴权头部
  • client - 连接 Godaddy API 并执行相应的请求

具体使用方法可以查看帮助信息,或者查看 Godaddy API 参考文档

>>> help(godaddypy)

godaddypy 常见用法示例

获取账号中的所有域名

>>> import godaddypy

>>> ak = 'AAAAAAAAAAAAAA'
>>> sk = 'BBBBBBBBBBBBBBB'

>>> account = godaddypy.Account(ak, sk)
>>> client = godaddypy.Client(account)

根据 Godaddy API 文档说明,获取域名,每次默认获取 500 个,最多可以一次性获取 1000 个。

# 获取域名,默认 100 个。如果账户内的域名数量少于 100,则一次性可以获取完毕,多于 100,获取前 100 个
>>> client.get_domains()

# 获取前 1000 个,最多一次性获取 1000 个。如果账户内的域名数量少于 1000,则一次性可以获取完毕,多于 1000,获取前 1000 个
>>> client.get_domains(limit=1000)

# 超过 1000 会报错
>>> client.get_domains(limit=1001)
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/godaddypy/client.py", line 105, in _validate_response_success
response.raise_for_status()
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://api.godaddy.com/v1/domains?limit=1001

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/site-packages/godaddypy/client.py", line 149, in get_domains
data = self._get_json_from_response(url, params=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/godaddypy/client.py", line 75, in _get_json_from_response
return self._request_submit(requests.get, url=url, json=json, **kwargs).json()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/godaddypy/client.py", line 97, in _request_submit
self._validate_response_success(resp)
File "/usr/local/lib/python3.11/site-packages/godaddypy/client.py", line 107, in _validate_response_success
raise BadResponse(response.json())
godaddypy.client.BadResponse: Response Data: {'code': 'VALUE_OVER', 'message': 'Limit must have a value no greater than 1000'}

如果账户内域名数量大于 1000,可以通过 API 提供的 marker 标记,获取到所有域名。流程为获取到前 100 个域名,使用第 100 个域名作为 marker,会获取到第 101 - 200 个域名,以此类推,获取所有域名

>>> client.get_domains()
[..., '100.com']

>>> client.get_domains(limit=100, marker='100.com')
['101.com', ..., '200.com']

获取指定域名的详细信息

>>> client.get_domain_info('test.app')

API REST 接口用法示例

godaddypy 库无法实现的功能需要调用原生的 API 实现。 [1]

API 调用示例 [1]

$ curl -X GET -H "Authorization: sso-key TtbYHEHLWmyVvXB:CrezwNmyEsh" "https://api.godaddy.com/v1/domains/available?domain=example.guru"
{"available":false,"definitive":true,"domain":"example.guru"}

部分接口需要传入 customerId,需要通过 shopperId 来获取到 customerId [2]

shopperId 登陆 godaddy 账号后,在账号信息中可以看到

$ curl -X GET -H "Authorization: sso-key e42pmipGG8rv:JYHg2i" "https://api.godaddy.com/v1/shoppers/208231111/?includes=customerId"
{"shopperId":"208231111","marketId":"en-PH","email":"kdjgies@163.com","externalId":null,"nameFirst":"dgeaf","nameLast":"F","customerId":"5d072871-6f2d-42d6-96ed-kd09rkjkkg"}

以下示例查询域名的续费信息

$ curl -X GET -H "Authorization: sso-key e42pmipGG8rv:JYHg2i" "https://api.godaddy.com/v2/customers/5d072871-6f2d-42d6-96ed-kd09rkjkkg/domains/1af7.com"
{"createdAt":"2020-12-23T06:26:02.000Z","domain":"1af7.com","domainId":335211690,"expirationProtected":false,"expiresAt":"2023-12-23T06:26:02.000Z","holdRegistrar":false,"locked":true,"modifiedAt":"2022-11-13T18:54:35.730Z","nameServers":["b.ns.cloudflare.com","d.ns.cloudflare.com"],"privacy":true,"redemption":{"redeemable":false},"registrarCreatedAt":"2020-12-23T04:20:54.913Z","renewAuto":false,"renewDeadline":"2024-02-06T06:26:02.000Z","renewal":{"currency":"USD","price":9450000,"renewable":true},"status":"ACTIVE","transferProtected":false}

脚注