Pinterest Generated API Client
The `pinterest-generated-client` is an auto-generated Python SDK for interacting with the Pinterest REST API (v5). It provides programmatic access to Pinterest's platform, enabling developers to manage ads, pins, boards, users, and more. As an auto-generated client, it aims to quickly reflect changes in the Pinterest API specification. It is actively maintained with frequent minor releases reflecting API spec updates.
Common errors
-
ModuleNotFoundError: No module named 'pinterest_generated_client'
cause The package is either not installed or was installed under an older, different name. Also, ensure you are running in the correct Python environment.fixRun `pip install pinterest-generated-client` to install the package. If previously installed, verify the current import paths match the new package name. -
pinterest_generated_client.rest.ApiException: (401) Unauthorized
cause Your Pinterest access token is either missing, expired, or invalid. The API client requires a valid OAuth2 access token to authenticate requests.fixEnsure the `PINTEREST_ACCESS_TOKEN` environment variable is correctly set with a valid and unexpired Pinterest access token, or pass it directly via `configuration.access_token`. -
TypeError: 'datetime.datetime' object is not JSON serializable
cause While the client handles most date/time serialization, custom objects or specific date inputs might not be automatically converted to the expected ISO 8601 string format.fixManually convert `datetime` objects to ISO 8601 strings (e.g., `my_datetime.isoformat()`) before passing them to API methods if the client does not handle it automatically for your specific use case. -
pydantic.v1.error_wrappers.ValidationError: ... (or similar Pydantic V1/V2 mismatch errors)
cause You have Pydantic V2 installed, but this library requires Pydantic V1 (due to the `pydantic < 2` dependency). Pydantic V2 introduced breaking API changes.fixUninstall Pydantic V2 (`pip uninstall pydantic`) and then install Pydantic V1: `pip install 'pydantic<2'`.
Warnings
- breaking The package name for this client changed in version 0.1.5. If you were using an older, pre-0.1.5 version of the Pinterest Python SDK (possibly named differently), your import paths will need to be updated to `pinterest_generated_client`.
- gotcha This library explicitly depends on `pydantic < 2`. Installing `pydantic` version 2.x will cause breaking changes and runtime errors due to its major API overhaul. Ensure Pydantic is pinned to a 1.x version.
- deprecated Specific API endpoints or parameters may become deprecated or change between versions. For instance, the 'Get catalog product groups' endpoint was deprecated in version 0.1.8.
- gotcha The quickstart examples often use the sandbox API host (`https://api-sandbox.pinterest.com/v5`). Remember to change this to the production host (`https://api.pinterest.com/v5`) when moving your application to a production environment.
Install
-
pip install pinterest-generated-client
Imports
- Configuration
import pinterest_generated_client configuration = pinterest_generated_client.Configuration(...)
- ApiClient
import pinterest_generated_client api_client = pinterest_generated_client.ApiClient(...)
- ApiException
from pinterest_generated_client.rest import ApiException
- UserAccountApi
import pinterest_generated_client api_instance = pinterest_generated_client.UserAccountApi(api_client)
Quickstart
import os
import pinterest_generated_client
from pinterest_generated_client.rest import ApiException
# Configure OAuth2 access token for authentication
configuration = pinterest_generated_client.Configuration(
host = "https://api-sandbox.pinterest.com/v5"
)
configuration.access_token = os.environ.get("PINTEREST_ACCESS_TOKEN", "")
# Create an instance of the API client
api_client = pinterest_generated_client.ApiClient(configuration)
# Create an instance of the specific API you want to use
api_instance = pinterest_generated_client.UserAccountApi(api_client)
try:
# Get user account information
user_account = api_instance.get_user_account()
print("User Account Data:", user_account)
except ApiException as e:
print(f"Exception when calling UserAccountApi->get_user_account: {e}")
if e.status == 401:
print("Hint: Check your PINTEREST_ACCESS_TOKEN environment variable.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
finally:
api_client.close()