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

How can I use the PDF Service API with SharePoint Online as external storage (not PowerPlatform)?

Community Beginner ,
Feb 02, 2024 Feb 02, 2024

Hello everyone,

I have a free tier of the PDF service and have successfully converted Word documents via the REST API by using the internal (adobe) storage (with Postman). Now I wanted to convert a document from SharePoint Online using JavaScript and fetch command. The query looks like this:

fetch('https://pdf-services-ew1.adobe.io/operation/createpdf', {
     method: "POST",
	headers: {
	  "Authorization": token,
	  "x-api-key": apiKey,
	  "Content-Type": "application/json",
	},
    body: JSON.stringify({ 
		input: { 
			"uri": "https://mytenant.sharepoint.com/documents/MyDoc.docx",
			"storage": "SHAREPOINT"
		}})
});

 

I get the following answer:

 

{
"error":
{
"code":"BAD_PARAMS",
"message":"Not able to infer an input media type. Check the provided input and try again."
}
}

 

I assume that it is an error that the Sevrice cannot simply access the file, because logically it has no access. The question I have is, what do I have to do so that the PDF service can read this file? I have searched the whole internet yesterday and today (at least it feels like that) and have not gotten an answer. There is also nothing on the Adobe documentation page. What am I doing wrong? Can someone please help me?


I don't want to do this via the PowerPlatform connector. Because this works well. The question really refers to "direct" access.

3.5K
Translate
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
Adobe Employee ,
Feb 02, 2024 Feb 02, 2024

All the cloud storage systems we support have SDKs/API calls that let you create 'readable' and 'writeable' urls for resources. Basically, "Given this path, give me a URL that is anonymously readable." You will need to look into the Sharepoint SDK to see how this done. We don't document it as it's specific to the cloud storage provider.

Translate
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
Community Beginner ,
Feb 02, 2024 Feb 02, 2024

Okay, thanks for the answer. That's a really important point. Because I can't share the internal files with "the whole world". But whatever. Just for the interest of it, I created a document and shared it with "everyone". That means if someone knows the URL, he/she can download the file.

And when I run the same code as above, I get this error message with this file:



"Not able to infer an input media type. Check the provided input and try again."

 
And yes, in the incognito tab/window I get the "Download" dialog

Translate
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
Adobe Employee ,
Feb 02, 2024 Feb 02, 2024

To be clear, all the cloud storage providers let you create URLs with expirations. Most should also allow you to remove the URL when done. This is pretty standard. And it's a unique URL, so yes, it may allow anonymous reading, it won't be something people can guess. And finally, if it really bothers you, don't forget you can *copy* the file from the cloud locally and then send it to us that way. That feels like overkill, but you have options. 

 

To your last error, it may be the way you generated the URL. When you click it, it should download the file, NOT open up Sharepoint and render the file. There's two kinds of sharable URLs, one that's "in context", for example, on Dropbox it would show the DB user interface and stuff, and the file. Or a link *directly* to the file itself. 

Translate
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
Community Beginner ,
Feb 02, 2024 Feb 02, 2024

You can specify an expiration date when sharing, but this functionality (share with anyone) must be allowed tenant wide at all. Almost nobody will set this in the tenant/site.

In the beginning I thought that I might have to provide an app from you in my tenant, which gets access to the SharePoint (like the "Adobe Document Cloud" app). And you then make internal queries to access this URL/File.

By the way, what I did is exactly about sharing (with everyone). And when I provide the link that SharePoint generates for me to your API, it shows an 'URL INVALID' error. I think it's because of a link like 'https://tenant.sharepoint.com/:w:/g/E...wBg5aRnu_SYA?e=ZBbsr6' (specifically, the part '/:w:/'). Yes, this link would display the file in the browser. But with the additional parameter '&download=1,' the file is directly downloaded.

Therefore, I then used this link: https://tenant.sharepoint.com/_layouts/15/Download.aspx?SourceUrl={DocumentPath}

And yes, this link also works in the "new incognito window." It's NOT a web view; the file is directly downloaded, just like when I click the "Download" button.

I am, of course, aware that I can also "save" the file with you. But there is a reason why I want to use my "own storage," isn't there?

I guess you as developers and providers of this function have tested it, and you can provide me with some code examples or explain how I can configure it.

Translate
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
Adobe Employee ,
Feb 02, 2024 Feb 02, 2024

"I am, of course, aware that I can also "save" the file with you. But there is a reason why I want to use my "own storage," isn't there?"

 

Right, but you don't seem to be happy with creating a link though. 🙂 To be clear, Adobe needs a way to read the data, and it can't login as you, so creating a temporary readable URL is fairly common and not something unexpected with APIs like this, in my opinion of course.

 

I haven't generated Sharepoint URLs in a long time, but the Download part just doesn't seem right. Can you share the code where you are generating your readable links?

Translate
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
Community Beginner ,
Feb 02, 2024 Feb 02, 2024

I am well aware that access to a file is necessary. Thats why my suspicion was whether I might have forgotten to configure something so that Adobe can access it (e.g., with a specific Adobe app permission, similar to the "Adobe Document Cloud" app).

But, as mentioned, I activated this feature in my test tenant to try out your service. I did NOT generate the URL through an API but rather through the SharePoint UI. Share Document ==> Link ==> Allow Anyone to edit with this link. See screen:

Seryoga89_0-1706900166673.png


The result of the URL looks like this (I appended the Download=1 parameter):

https://tenant.sharepoint.com/:w:/s/{SITE_NAME}/{CODE}?e={ANOTHER_CODE}&download=1

When I send this LINK to the Adobe PDF Service, I get an error messagem that the URL is invalid or not supported.

If I use this link:

https://tenant.sharepoint.com/sites/{SITE_NAME}/_layouts/15/download.aspx?SourceUrl={PATH_TO_FILE}

I receive the same Media-Type error as mentioned before.


BOTH links work in incognito mode. And I have now specifically copied these two links into a different PDF service (not Adobe), and there it works without any problems.

Translate
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
Adobe Employee ,
Feb 02, 2024 Feb 02, 2024

I know we apply a string matcher on the URLs, and it's possible we do NOT allow the links as you have made them, but only allow them per how the SDK makes em. From what I see in the docs, the only thing mentioned is tenant.sharepoint.com... although looking now, the docs show <tenant>.sharepoint.com. I bet if you used the SDK, which is the expectation, it's going to be something.sharepoint.com instead. 

 

My suggestion now is - and since you would need to do this anyway - make a quick script that uses the SDK and look at the URLs generated.

Translate
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
Community Beginner ,
Feb 02, 2024 Feb 02, 2024

but could you clarify the differnece between:

tenant.sharepoint
<tenant>.sharepoint.com
and something.sharepoint.com?

I want to mention that my link examples are also in the format of "something.sharepoint.com."

But okay, here is the result from SDK:

Seryoga89_0-1706901864056.png


And yes, this is the same syntax. You know, the one that hasn't been working since the first post... 

Or do you have your own SDK for SharePoint from Adobe?

Translate
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
Adobe Employee ,
Feb 02, 2024 Feb 02, 2024

We don't have a special SDK or anything. If you feel comfortable doing so, if you can directly share with me the code you use to generate the link, I can try it here and see if I get the same error. My email is jedimaster@adobe.com.

Translate
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
Community Beginner ,
Feb 03, 2024 Feb 03, 2024

So, in SharePoint you have several options for creating something.

There is the server-side object model (SSOM). But this is only for on-premises. Then there is the SP Management Shell, with which you can do much more than via SSOM or the interface. But this is also only for on-premises.

 

In SP Online (and also possible in On-Premises) you therefore use:
Client Server Object Model (CSOM). This is also the SDK. There is also the SharePoint Online Management Shell (only for SPO). Of course, there is also the REST API, which usually has a similar range of functions to CSOM. But often can/has less. The easiest way is to use PnP PowerShell to access SharePoint using CSOM and the API. It also includes many Teams cmdlets or other M365 products. PnP PowerShell uses CSOM (=SDK) internally.

Here is a guide on how to set it up: (Note: at least PowerShell v7.2 required): https://pnp.github.io/powershell/articles/installation.html

These are the commands to generate a anonymous link:

Import-Module PnP.SharePoint
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite"
Add-PnPFileAnonymousSharingLink -FileUrl "/sites/yoursite/yourLib/yourDoc.docx" -ShareType Edit
$link = Get-PnPFileSharingLink -FileUrl "/sites/yoursite/yourLib/yourDoc.docx"
$link.Link


Here ist the documentation for this command: https://pnp.github.io/powershell/cmdlets/Add-PnPFileAnonymousSharingLink.html

If CSOM cannot do something, then it uses REST-API or vice versa.

Is that enough for you?

BTW: This Microsoft article recommends using the PnP components: https://learn.microsoft.com/de-de/archive/blogs/vesku/external-sharing-api-for-sharepoint-and-onedri... 

Translate
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 ,
Feb 08, 2024 Feb 08, 2024

Hey @Seryoga89  is your issue resolved? because I am also facing the same thing and there is no reference for SharePoint in the documentation.

Translate
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
Community Beginner ,
Feb 08, 2024 Feb 08, 2024

Hi @Bhupendra35330800krlj Unfortunately, no! I haven't heard from @Raymond Camden  since my last reply

Translate
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
Adobe Employee ,
Feb 08, 2024 Feb 08, 2024

Unfortunately I've been swamped the last few days and will be the next few days. I'd like to help with this, but I can't until next week. @Bhupendra35330800krlj  As stated, we don't document how to use cloud storage SDKs as that's not our area of concern per se, it's up to each provider. 

Translate
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 ,
Aug 06, 2024 Aug 06, 2024
LATEST

I also run into this issue. If I click on the link, it does directly download the file.


Maybe the validation logic is a little too strict to verify that it is indeed a sharepoint link?

From example in Adobe docs:

https://dcalpine2.sharepoint.com/sites/Docgen/_layouts/15/download.aspx?UniqueId=XXX&Translate=false...",


Generated using Microsoft Graph API:
https://aaa.sharepoint.com/personal/bbb/_layouts/15/download.aspx?UniqueId=XXX&Translate=false&tempa...",

Translate
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