sgw
February 25, 2023, 11:44am
1
Describe the issue/error/question
I try to POST a pdf file to the DATEV “document management API”.
The call looks like this:
https://developer.datev.de/datev/platform/en/product/32018/api/30987#/documentmanagement_130/operation/%2Fdocuments/post
So the curl-example there is:
curl --request POST \
--url https://localhost:58454/platform/api/dms/v1/documents \
--header 'Authorization: Basic REPLACE_BASIC_AUTH' \
--header 'accept: application/json;charset=utf-8' \
--header 'content-type: application/json;charset=utf-8' \
--header 'document.id: REPLACE_THIS_VALUE' \
--data REPLACE_BODY
So the pdf file should be transferred via “–data”, right?
Additional info: “document.id” is optional , I dont’ need it in my HTTP request (just in case you want to point me at that detail )
What is the error message (if any)?
I can’t figure out how to send the body correctly, searched the forum for examples, tried “Raw”, “binary data”, etc
The datev error code just says “body not correct” more or less. Right …
Please share the workflow
last try, still failing:
Information on your n8n setup
**n8n version: 0.216.1 **
**Database you’re using (default: SQLite): default **
Running n8n with the execution process [own(default), main]: default
Running n8n via [Docker, npm, n8n.cloud, desktop app]: docker
jonflow
February 25, 2023, 8:12pm
2
If I’m right, the Body Content Type should be ‘n8n Binary Data’ like you thought, and the Data Field Name in your case is just data
, not as an {{ expression }}
1 Like
sgw
February 26, 2023, 8:49am
3
thanks for the suggestion, doesn’t work either.
Maybe my input pdf is faulty … but it opens fine when I view it.
sgw
February 26, 2023, 9:02am
4
If I check the docs it seems to be just wrong to try to send a file via this call.
As far as I understand, I would have to create a document there by providing a json description of that document, and then I can add files to that document-structure using this call .
So it seems I bark at the wrong tree right now
I will try to figure out first how to create the “document structure” as it’s called there.
Or try to POST the pdf to an existing structure for a test.
1 Like
sgw
February 27, 2023, 9:34am
5
I get lost again … so many issues to fix and I am still lacking some basic knowledge, as far as I understand
Currently I try to build the body to match this:
{
"name": "EST.pdf",
"type": 1,
"document_link": "96e01d5b-952d-4c1f-a634-76bebcc7ee99",
"file": {
"creation_date": "2012-11-07T15:26:40+01:00",
"last_modification_date": "2021-01-04T11:37:40.7188738+01:00",
"data": "SGVsbG8gV29ybGQ="
}
}
From my previous nodes I have a pdf with various properties, see screenshot
Now the goals are:
get the filename from the previous node or even better, build a new filename containing a timestamp and some prefix
put the binary data (= the actual pdf) into the field “data”
All that generated json should then go into the API-call in a following node.
Could someone help me achieving this? Is the approach with the Code-Node the right one?
sgw
February 27, 2023, 12:01pm
6
OK; I think I have to use “Set” between generating the pdf and creating the push-call.
Trying something like:
In the following Code-Node I want to drag and drop the fields from the left into the code, but this doesn’t work. Why that? Where’s my mistake?
1 Like
sgw
February 27, 2023, 12:30pm
7
I think (and hope) I am getting closer.
Having this now:
I think It only fails because of how I reference the actual pdf data.
Please look at the last Node mainly, the stuff before is just drafting etc
sgw
February 27, 2023, 12:48pm
8
Did my first “create document structure” call right now. Oh my.
1 Like
sgw
February 27, 2023, 2:40pm
9
I also had success doing an UPDATE, but only with mock data for the actual pdf content.
So far I fail at adding the content right:
In “data” I need to add the actual binary data.
The Node “pdf set name and type” returns an OK pdf which I can download/view. Please advise how to get that data into my API-call. Thanks in advance.
Hi @sgw , to be honest with you I am having a hard time understanding the Datev documentation on the endpoint you are calling. It doesn’t seem to describe the expected content of the file.data
field. Do you have your request working outside of n8n? If so, can you perhaps share a working curl request?
sgw
February 28, 2023, 3:31pm
11
@MutedJam thanks for looking at this in the first place
I haven’t yet tried to do that with curl
.
Maybe this helps:
It’s a bit hidden under “Schema” in “Parameters - Body”.
I was able to create a document by hardcoding the value from the example:
"data": "SGVsbG8gV29ybGQ="
That was working yesterday, done via HTTP request in n8n
.
Ah excellent, I have indeed missed this piece.
I think you can try using the Move Binary Data node to generate the content required here. I don’t have access to the Datev API, but the below workflow is at least working in principle:
It POSTs a valid base64-encoded PDF to the server I’ve used for testing:
I’ve verified this through this service :
(Careful when testing this, while these services are great for debugging, you don’t want to send anything confidential to them.)
1 Like
sgw
February 28, 2023, 5:05pm
13
Great, we are getting closer.
I now have a node “Move Binary Data1” like your example.
I try to use its output in the Node that should update that file in DATEV:
At first it didn’t work when I pulled over (drag and drop) the “data” item, I fiddled with the formatting etc …
Now I have this:
And the API-call seems to accept that field
Great, thanks @MutedJam !
I now have to figure out other details like the timestamp(s) etc
Currently the API doesn’t accept the change because of issues with “creation_date”, but I think I know my way around this issue.
1 Like
sgw
March 1, 2023, 8:25am
14
Trying to pick a date from the “Move Binary to JSON” node.
Clicking the button next to “last-modified” left leads to pasting:
"$node["Move Binary Data1"].json["headers"]["last-modified"]"
which seems not to work.
If I modify this to:
"last_modification_date": "{{ $node["Move Binary Data1"].json["headers"]["last-modified"] }}"
it works.
Why do I have to do this manually, what is the difference and where does this behavior come from?
I use n8n-0.217.2 in docker.
sgw
March 1, 2023, 9:32am
15
But to add something positive: I was now able to successfully update that pdf in that DATEV DMS via n8n
… nice.
2 Likes
system
Closed
March 8, 2023, 9:33am
16
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.