Participant
April 11, 2024
Answered
Transition to OAuth: HTML to PDF error
- April 11, 2024
- 1 reply
- 633 views
Hi everyone,
I am able to convert a URL to PDF using the rest API with JWT credentials, but the same operation doesn’t succeed when switching to OAuth credentials. In the latter case, the PDF output (attached) only contains an error message followed by an error code.
In both approaches, the same http request is sent. Here is the (python) code for the OAuth approach:
# Load credentials
PDF_SERVICES_CLIENT_ID = os.getenv('PDF_SERVICES_CLIENT_ID')
PDF_SERVICES_CLIENT_SECRET = os.getenv('PDF_SERVICES_CLIENT_SECRET')
# Obtain access token
url_access_token = "https://ims-na1.adobelogin.com/ims/token/v3"
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
payload = f'grant_type=client_credentials&client_id={PDF_SERVICES_CLIENT_ID}&client_secret={PDF_SERVICES_CLIENT_SECRET}&scope=AdobeID,openid,read_organizations,additional_info.projectedProductContext,additional_info.roles,adobeio_api,read_client_secret,manage_client_secrets,DCAPI'
response = requests.post(url_access_token, headers=headers, data=payload)
access_token = response.json().get('access_token')
# Endpoint for the HTML to PDF conversion service
api_url = 'https://pdf-services-ue1.adobe.io/operation/htmltopdf'
# Headers for the request
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json',
'x-api-key': os.getenv('PDF_SERVICES_CLIENT_ID'),
}
# Data payload for the request
data = {
"inputUrl": url,
"includeHeaderFooter": True,
"json": "{}",
"pageLayout": {
"pageWidth": 11,
"pageHeight": 8.5
}
}
# POST request to convert HTML to PDF
response = requests.post(api_url, headers=headers, json=data)
Any clue on what is happening/missing here?
Thanks!
