0

So I am currently in the process of learning the new Javascript Cloud SDK. Of course there is also a package for attachments and document info records but I am still facing some problems.

So mainly I just want to get an attachment which is attached to a document info record and safe it to my local file system. I am working with the JS Cloud SDK so I am working with a Node application.

When working with the API directly (testing via Postman) I can get the media_src of the attachment simply by adding '$value' to the request path. When I try to access this URL outside of Postman with a simple Node https.get request I get a SAML 2.0 Error (SAML2 Service not accessible). I guess that is because I cannot access those URLs via browser and therefore I should use the SDK for that.

So the final problem I am facing is that I cannot find anything about getting the file itself in the JSDoc of the SDK.

Same goes also for creating an attachment. Should I use the 'builder()' method for that and pass a JSON object or how does a POST or PUT request work with that SDK? I cannot find any blogs etc. because they are only doing simple 'Hello World' programms or GET some data.

Marcel N.
  • 57
  • 2
  • 10

1 Answers1

0

thanks for reaching out to us! Currently, we do not support OData media streams in the JS SDK's VDM yet. If this functionality is critical for you, you can consider using the Java version of the SDK. Alternatively, you can open an issue here.

Regarding the SAML error I cannot comment, since I don't how your Postman is configured or how your system is setup.

Dennis H
  • 589
  • 4
  • 10
  • So currently it is only possible to CREATE, GET and UPDATE attachments with the Java SDK version, am I right ? Thanks in advance and thank you for the quick response beforehand. – Marcel N. Apr 24 '19 at 10:24
  • I'm not sure what exactly you mean by attachments. Let's stick with the document info records as an example, since you've mentioned them in your original question. For the entity `DocumentInfoRecord` of service `API_DMS_PROCESS_SRV` (represented by package `@sap/cloud-sdk-vdm-document-management-service`), there is a class `DocumentInfoRecordRequestBuilder` that offers all the available "CRUD options" for that entity. In general, we offer the same for any other entity of the SAP S/4HANA Cloud OData services. Does that answer your question? – Dennis H Apr 24 '19 at 12:04
  • Yes I am also working with that entity but I am talking specifically about the `@sap/cloud-sdk-vdm-attachment-service` which seems to me to be the module to go for the attachments (files etc. attached to the document info record). There is also a builder with the CRUD options but I was not sure how to create, get or update an `AttachmentContentSet` for a given document info record, not meaning the properties like `fileSize` because I can get those but the actual file (e.g. PDF or Word Document). – Marcel N. Apr 24 '19 at 12:41
  • So the actual question is how can I (if possible) create a new attachment (e.g. PDF, etc.) and how can I get an already existing attachment from a document info record. – Marcel N. Apr 24 '19 at 12:41
  • I don't have much experience with media streams in OData (which is what attachments are based on as far as I'm aware), but based on the assumption that you attach `/$value` to some URI, you can maybe use the request builder of the respective entity, instead of `execute` call `build`, which gives you the request, on which you can then call `headers()` and `url()` which you then might be able to repurpose to manually build the requests. Does that make sense to you? – Dennis H Apr 24 '19 at 13:21
  • The first thing I did was just basically testing the API [API_CV_ATTACHMENT_SRV](https://api.sap.com/api/API_CV_ATTACHMENT_SRV/resource) directly on a testsystem. With the `/$value` I was able to get for example the text of a `.txt`attachment and was also able to POST a new one to a specified document info record (which also felt a little bit unclean because the documentation is a little bit unclear about that as well). And because the package `@sap/cloud-sdk-vdm-attachment-service` represents this API I thought it would be possible to do this through the SDK as well. – Marcel N. Apr 24 '19 at 13:32
  • I also just tried your recommendation but unfortunately I am not able to call a `headers()` or `url()`method after `build()`. Would some screenshots help to understand the exact problem I am facing or do you know what issue I am facing exactly ? "Uploading" and "Downloading" a file from an `AttachmentContentSet` is a critical point in my use case but if that is currently not possible with the JS SDK then I have to switch to Java. I just wanna make clear that we are understanding each one correctly. – Marcel N. Apr 24 '19 at 13:43
  • I think I understood what you're trying to achieve, and there is no support in the VDM of the JS SDK for dealing with attachments in the form that you require it. So if you want this feature in a "nice way", i.e. with the same convenience you get when dealing only with entities and CRUD, you'll have to go with the Java SDK. In the JS SDK you'd have to somehow build it yourself on top of what we have. What error do you get when trying to call `headers()` or `url()`? – Dennis H Apr 24 '19 at 13:52
  • There is no `headers()` or `url()` method to call after the `build()` method because `build()` only returns a Promise object. I guess you meant to call `.url()` , `.withCustomHeaders()` or `.withCustomServicePath()` right after `getByKey(...)` or `getAll()` ? – Marcel N. Apr 24 '19 at 14:08
  • Well yeah, `build` is asynchronous, so ``` build().then(odataRequest => { //do something with the request like: const url = odataRequest.url() }) ``` you could also use `await` of course, though then you should wrap it with `try/catch`, otherwise errors will go missing – Dennis H Apr 24 '19 at 15:04