The input is not a valid Base-64 string as it contains a non-base 64 character, more than two paddin
            
                
                    vremeni4                
                
                    Member Posts: 323                
            
                        
            
                    Hi all,
In Postman I need to use/call REST API from the version BC365 BC18 Cu2.
I want to add an attachment to the GL Journal Line.
All works fine until I try to upload a file.
1/ I create the record (Incoming Documents) by calling
https://localhost:18348/BC180/api/v2.0/companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments
and body
{
"parentId" : "ccd09dda-f0c7-eb11-bb69-000d3a21ebdb",
"fileName": "C:\\Temp\\ANAV.pdf",
"parentType": "Journal"
}
the response body is which means all is good
{
"@odata.context": "https://localhost:18348/BC180/api/v2.0/$metadata#companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments/$entity",
"@odata.etag": "W/\"JzQ0O1I5ay9wMWVlTTJ4QkpHNWphZmRneWU0WU5sbEhlNXFBLzVmdGl5VmRuT0U9MTswMDsn\"",
"id": "4ad5f039-6da1-ec11-afa1-00090faa0001",
"parentId": "ccd09dda-f0c7-eb11-bb69-000d3a21ebdb",
"fileName": "C:\\Temp\\ANAV.pdf",
"byteSize": 0,
"attachmentContent@odata.mediaEditLink": "https://localhost:18348/BC180/api/v2.0/companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments(4ad5f039-6da1-ec11-afa1-00090faa0001)/attachmentContent",
"attachmentContent@odata.mediaReadLink": "https://localhost:18348/BC180/api/v2.0/companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments(4ad5f039-6da1-ec11-afa1-00090faa0001)/attachmentContent",
"lastModifiedDateTime": "2022-03-11T18:58:25Z",
"parentType": "Journal"
}
2/ I then try to upload the pdf file by using the @odata.etag in the header and calling the
https://localhost:18348/BC180/api/v2.0/companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments(4ad5f039-6da1-ec11-afa1-00090faa0001)/attachmentContent
In the Body I tried to pass Base64 as raw (json, or just the base64 string) and binary, I think I tried all options in postman
but I always get the error message
{
"error": {
"code": "Unknown",
"message": "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. CorrelationId: 7ef17846-8731-4716-a79c-7d7d2e436534."
}
}
Does anyone know how to upload the file by using the REST API call above ?
by the way the Documentation regarding this
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_attachment_update
is wrong as it is a copy from api1.0
I also tried api1.0 but I am getting the same error message.
Thanks for your help.
                
                In Postman I need to use/call REST API from the version BC365 BC18 Cu2.
I want to add an attachment to the GL Journal Line.
All works fine until I try to upload a file.
1/ I create the record (Incoming Documents) by calling
https://localhost:18348/BC180/api/v2.0/companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments
and body
{
"parentId" : "ccd09dda-f0c7-eb11-bb69-000d3a21ebdb",
"fileName": "C:\\Temp\\ANAV.pdf",
"parentType": "Journal"
}
the response body is which means all is good
{
"@odata.context": "https://localhost:18348/BC180/api/v2.0/$metadata#companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments/$entity",
"@odata.etag": "W/\"JzQ0O1I5ay9wMWVlTTJ4QkpHNWphZmRneWU0WU5sbEhlNXFBLzVmdGl5VmRuT0U9MTswMDsn\"",
"id": "4ad5f039-6da1-ec11-afa1-00090faa0001",
"parentId": "ccd09dda-f0c7-eb11-bb69-000d3a21ebdb",
"fileName": "C:\\Temp\\ANAV.pdf",
"byteSize": 0,
"attachmentContent@odata.mediaEditLink": "https://localhost:18348/BC180/api/v2.0/companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments(4ad5f039-6da1-ec11-afa1-00090faa0001)/attachmentContent",
"attachmentContent@odata.mediaReadLink": "https://localhost:18348/BC180/api/v2.0/companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments(4ad5f039-6da1-ec11-afa1-00090faa0001)/attachmentContent",
"lastModifiedDateTime": "2022-03-11T18:58:25Z",
"parentType": "Journal"
}
2/ I then try to upload the pdf file by using the @odata.etag in the header and calling the
https://localhost:18348/BC180/api/v2.0/companies(e03e92aa-f0c7-eb11-bb69-000d3a21ebdb)/attachments(4ad5f039-6da1-ec11-afa1-00090faa0001)/attachmentContent
In the Body I tried to pass Base64 as raw (json, or just the base64 string) and binary, I think I tried all options in postman
but I always get the error message
{
"error": {
"code": "Unknown",
"message": "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. CorrelationId: 7ef17846-8731-4716-a79c-7d7d2e436534."
}
}
Does anyone know how to upload the file by using the REST API call above ?
by the way the Documentation regarding this
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_attachment_update
is wrong as it is a copy from api1.0
I also tried api1.0 but I am getting the same error message.
Thanks for your help.
0                
            Best Answer
- 
            I managed to find the solution, so I am sharing it here with everyone.
The problem was in the etag and If-Match tag in the header
snip---
HEADERS:
If-Match * (you can also use the eTag: "W/\"JzQ0O1I5ay9wMWVlTTJ4QkpHNWphZmRneWU0WU5sbEhlNXFBLzVmdGl5VmRuT0U9MTswMDsn\"",
---snip---
If you use the etag
"JzQ0O1I5ay9wMWVlTTJ4QkpHNWphZmRneWU0WU5sbEhlNXFBLzVmdGl5VmRuT0U9MTswMDsn\"
you will get the error message "The input is not a valid Base-64 string as it contains a non-base 64 character, ..."
If you use
"JzQ0O1I5ay9wMWVlTTJ4QkpHNWphZmRneWU0WU5sbEhlNXFBLzVmdGl5VmRuT0U9MTswMDsn"
then you can upload the file only once after that you will get the error
"Another user has already changed the record. CorrelationId: 4b20e80f-1924-4465-8fd0-5c9bd84ec140."
So the best option is to use
If-Match *
in the header as this works fine.
0 
Answers
- 
            I managed to find the solution, so I am sharing it here with everyone.
The problem was in the etag and If-Match tag in the header
snip---
HEADERS:
If-Match * (you can also use the eTag: "W/\"JzQ0O1I5ay9wMWVlTTJ4QkpHNWphZmRneWU0WU5sbEhlNXFBLzVmdGl5VmRuT0U9MTswMDsn\"",
---snip---
If you use the etag
"JzQ0O1I5ay9wMWVlTTJ4QkpHNWphZmRneWU0WU5sbEhlNXFBLzVmdGl5VmRuT0U9MTswMDsn\"
you will get the error message "The input is not a valid Base-64 string as it contains a non-base 64 character, ..."
If you use
"JzQ0O1I5ay9wMWVlTTJ4QkpHNWphZmRneWU0WU5sbEhlNXFBLzVmdGl5VmRuT0U9MTswMDsn"
then you can upload the file only once after that you will get the error
"Another user has already changed the record. CorrelationId: 4b20e80f-1924-4465-8fd0-5c9bd84ec140."
So the best option is to use
If-Match *
in the header as this works fine.
0 
Categories
- All Categories
 - 73 General
 - 73 Announcements
 - 66.6K Microsoft Dynamics NAV
 - 18.7K NAV Three Tier
 - 38.4K NAV/Navision Classic Client
 - 3.6K Navision Attain
 - 2.4K Navision Financials
 - 116 Navision DOS
 - 851 Navision e-Commerce
 - 1K NAV Tips & Tricks
 - 772 NAV Dutch speaking only
 - 617 NAV Courses, Exams & Certification
 - 2K Microsoft Dynamics-Other
 - 1.5K Dynamics AX
 - 323 Dynamics CRM
 - 111 Dynamics GP
 - 10 Dynamics SL
 - 1.5K Other
 - 990 SQL General
 - 383 SQL Performance
 - 34 SQL Tips & Tricks
 - 35 Design Patterns (General & Best Practices)
 - 1 Architectural Patterns
 - 10 Design Patterns
 - 5 Implementation Patterns
 - 53 3rd Party Products, Services & Events
 - 1.6K General
 - 1.1K General Chat
 - 1.6K Website
 - 83 Testing
 - 1.2K Download section
 - 23 How Tos section
 - 252 Feedback
 - 12 NAV TechDays 2013 Sessions
 - 13 NAV TechDays 2012 Sessions