Discussions

Ask a Question
Back to All

Want to Test the API -- Use Credits Endpoint and short Python script (Skip postman)

import requests
import base64
import config #Comment -- This config.py has you API key in it (See below)
import json

url = "https://api.d-id.com/credits"

api_key = config.API_KEY
auth_string = f"{api_key}:"

base64_auth_string = base64.b64encode(auth_string.encode()).decode()

headers = {
"accept": "application/json",
"Authorization": f"Basic {base64_auth_string}"
}

response = requests.get(url, headers=headers)

print(json.dumps(json.loads(response.text), indent=4))

So you undersand this impot config -- the config.py is a file with your API Key in same dir as this program you make and save above. When you run the script above it calls that config.py to get your key.

config.py contains a single line with your API that you cut and paste in to the file --- the entire key string

API_KEY = "YOUR_API_KEY_HERE"

The Program above calls the file so you do not have your API key in your python program for security etc.

Once you get this to work go and do all the other tutorials in Python if yo do not know Rest and Postman...

Best of Luck -- you can do this....

Output sample:

C:/Projects/DID_Demo.py
{
"credits": [
"owner_id": "google-oauth2|103063615415625432322",
"expire_at": "2023-05-24T21:38:03.000Z",
"created_at": "2023-04-24T22:39:17.200Z",
"remaining": 21,
"valid_from": "2023-04-24T22:39:17.200Z",
"total": 40,
"product_billing_interval": "month",
"product_id": "prod_Mtdcdk3ogGxd6Y",
"modified_at": "2023-05-01T01:41:14.064Z"
},
{
"owner_id": "google-oauth2|103063615415625432322",
"expire_at": "2023-06-12T21:39:56.217Z",
"created_at": "2023-04-13T21:39:56.554Z",
"remaining": 100,
"valid_from": "2023-04-13T21:39:56.554Z",
"total": 100,
"modified_at": "2023-04-13T21:39:56.517Z"
}
],
"remaining": 21,
"total": 40
}