• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Transition to OAuth: HTML to PDF error

New Here ,
Apr 11, 2024 Apr 11, 2024

Copy link to clipboard

Copied

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!

TOPICS
PDF Services API , REST APIs

Views

98

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Apr 15, 2024 Apr 15, 2024

Try switching to this API for getting the access token: https://developer.adobe.com/document-services/docs/apis/#tag/Generate-Token

Votes

Translate

Translate
Adobe Employee ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

Try switching to this API for getting the access token: https://developer.adobe.com/document-services/docs/apis/#tag/Generate-Token

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

LATEST

That worked! Thanks a lot!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources