Databricks API Error When Importing Notebook: “MALFORMED_REQUEST” with Base64 Encoding Issue

I am attempting to copy a notebook within my Databricks workspace using the Databricks REST API. I successfully export the notebook using the export API but encounter a problem when trying to import it into another folder.

Here’s how I’m exporting the notebook:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
# Data to export the notebook
export_data = {
'path': source_path,
'direct_download': True
}
# Execute the GET request to export the notebook
export_response = requests.get(f'https://{host}/api/2.0/workspace/export', headers=headers, params=export_data)
</code>
<code>headers = { 'Authorization': f'Bearer {token}', 'Content-Type': 'application/json' } # Data to export the notebook export_data = { 'path': source_path, 'direct_download': True } # Execute the GET request to export the notebook export_response = requests.get(f'https://{host}/api/2.0/workspace/export', headers=headers, params=export_data) </code>
headers = {
    'Authorization': f'Bearer {token}',
    'Content-Type': 'application/json'
}



# Data to export the notebook
export_data = {
    'path': source_path,
    'direct_download': True
}

# Execute the GET request to export the notebook
export_response = requests.get(f'https://{host}/api/2.0/workspace/export', headers=headers, params=export_data)

And it seems to work fine:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>export_response
<Response [200]>
export_response.text
'{"content":"IyBEYXRhYnJpY2tzIG5vdGVib29rIHNvdXJjZQojIFNob3cvaGlkZSBub3RlYm9vayBjZWxscwpmcm9tIElQeXRob24uZGlzcGxheSBpbXBvcnQgSFRNTCwgSmF2YXNjcmlwdCwgZGlzcGxheSwgY2xlYXJfb3V0cHV0CgpIVE1MKAogICAgJycnCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgZnVuY3Rpb24gY29kZV90b2dnbGUoKXsKICAgICAgICAgICAgICAgIGlmIChjb2RlX3Nob3duKXsKICAgICAgICAgICAgICAgICAgICAkKCdkaXYuaW5...
</code>
<code>export_response <Response [200]> export_response.text '{"content":"IyBEYXRhYnJpY2tzIG5vdGVib29rIHNvdXJjZQojIFNob3cvaGlkZSBub3RlYm9vayBjZWxscwpmcm9tIElQeXRob24uZGlzcGxheSBpbXBvcnQgSFRNTCwgSmF2YXNjcmlwdCwgZGlzcGxheSwgY2xlYXJfb3V0cHV0CgpIVE1MKAogICAgJycnCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgZnVuY3Rpb24gY29kZV90b2dnbGUoKXsKICAgICAgICAgICAgICAgIGlmIChjb2RlX3Nob3duKXsKICAgICAgICAgICAgICAgICAgICAkKCdkaXYuaW5... </code>
export_response
<Response [200]>

export_response.text
'{"content":"IyBEYXRhYnJpY2tzIG5vdGVib29rIHNvdXJjZQojIFNob3cvaGlkZSBub3RlYm9vayBjZWxscwpmcm9tIElQeXRob24uZGlzcGxheSBpbXBvcnQgSFRNTCwgSmF2YXNjcmlwdCwgZGlzcGxheSwgY2xlYXJfb3V0cHV0CgpIVE1MKAogICAgJycnCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgZnVuY3Rpb24gY29kZV90b2dnbGUoKXsKICAgICAgICAgICAgICAgIGlmIChjb2RlX3Nob3duKXsKICAgICAgICAgICAgICAgICAgICAkKCdkaXYuaW5...

Then I try to paste the notebook in the destination folder with the import api call:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import_data = {
'content': export_response.content,
'path': dest_path
}
import_response = requests.post(f'https://{host}/api/2.0/workspace/import', headers=headers, json=import_data)
</code>
<code>import_data = { 'content': export_response.content, 'path': dest_path } import_response = requests.post(f'https://{host}/api/2.0/workspace/import', headers=headers, json=import_data) </code>
import_data = {
'content': export_response.content,
'path': dest_path
}

import_response = requests.post(f'https://{host}/api/2.0/workspace/import', headers=headers, json=import_data)

And I get:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import_response
<Response [400]>
import_response.text
'{"error_code":"MALFORMED_REQUEST","message":"Could not parse request object: Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character '{' (code 0x7b) in base64 contentn at [Source: (ByteArrayInputStream); line: 1, column: 14]n at [Source: java.io.ByteArrayInputStream@3fbdb5c3; line: 1, column: 14]"}n'
</code>
<code>import_response <Response [400]> import_response.text '{"error_code":"MALFORMED_REQUEST","message":"Could not parse request object: Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character '{' (code 0x7b) in base64 contentn at [Source: (ByteArrayInputStream); line: 1, column: 14]n at [Source: java.io.ByteArrayInputStream@3fbdb5c3; line: 1, column: 14]"}n' </code>
import_response
<Response [400]>

import_response.text
'{"error_code":"MALFORMED_REQUEST","message":"Could not parse request object: Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character '{' (code 0x7b) in base64 contentn at [Source: (ByteArrayInputStream); line: 1, column: 14]n at [Source: java.io.ByteArrayInputStream@3fbdb5c3; line: 1, column: 14]"}n'

I’m stuck I don’t understand would should I put as a correct content, can you please assist me?
Thanks

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật