Expand my Community achievements bar.

Moving Document Generation From JWT to OAuth Server-to-Server

Avatar

Level 1

I have an application that uses JWT approach with the .Net SDK to generate a PDF invoice using Json and word. Is in production and works great, but JWT is being deprecated and there is very limited documentation on doing this using OAUTH with the Adobe API.

Using the Services api (https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generation) I can properly authenticate and get the token but to hit the endpoint https://pdf-services-ue1.adobe.io/operation/documentgeneration I am required to first upload an asset to https://pdf-services-ue1.adobe.io/assets but the documentation falls short on using the upload pre-signed URI. I tried to upload my Word document but I got a Bad Request (400)

{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Transfer-Encoding: chunked
Connection: keep-alive
x-amz-request-id: 4976S82736VN526H
x-amz-id-2: /k5mBs1csvHfoJWcQ8IniLv3OxxXfRMhVxCgU65HORApfWrnh7YqdGKaj3zOjZ4n8c6ae1VaTKY=
Date: Wed, 27 Mar 2024 21:42:05 GMT
Server: AmazonS3
X-Cache: Error from cloudfront
Via: 1.1 36a32e6b670d2dbfbdde067986e163ce.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: MIA3-P8
X-Amz-Cf-Id: b7074tYp4ribZn9oaEL73ujIJ-mSG48gmsNHtr92M1OlGv4UydFTwA==
Content-Type: application/xml
}, Trailing Headers:
{
}}

Testcode:

private async Task UploadFile(AdobeToken adobeToken, string clientId, string templateName, Stream wordTemplate, string uploadUri)
{
    // Initialize HttpClient
    var client = _httpClientFactory.CreateClient();
    // Make POST request to the API endpoint
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", adobeToken.AccessToken);
    client.DefaultRequestHeaders.Add("x-api-key", clientId);

    using var content = new MultipartFormDataContent();
    var template = wordTemplate;//Stream of the template 
    var fileContent = new StreamContent(template);
    content.Add(fileContent, "file", templateName);

    var fileResponse = await client.PostAsync(uploadUri, content);
}

The uploadUri Parameter comes from the end point https://pdf-services-ue1.adobe.io/assets which I am able to properly call with a success call.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Reply

Avatar

Level 1

I figured it out. One of the issues is that the documentation lists x-api-key header key as lower case but it needs to be X-API-Key. Passing this key as lowercase results in a 400 error.

I recommend downloading the PostMan libraries and try it there first.