11-16-2022 10:51 AM
I exported a project as a zip file and saved it locally, but I’m having trouble getting the Snaplogic Import a Project API to work.
I’ve tried to get this API to work on Postman and as a Python script, but I keep getting a 400 - BAD REQUEST response and the error “Expecting body argument for endpoint import_project: file_handle”.
So I assume something is wrong with how I’m trying to send the file, but I can’t figure out what. Here is an example of a Python script I’ve tried:
import requests
from requests.auth import HTTPBasicAuth
import os
pod_path = 'elastic.snaplogic.com'
import_path = 'Partners/Company/x_Imported'
url = f'https://{pod_path}/api/1/rest/public/project/import/{import_path}'
params = {'duplicate_check': 'true'}
headers = {'Content-Type': 'multipart/form-data'}
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, 'project_files/xImport.zip')
file_obj = open(filename, "rb")
files = {'file': ('xImport.zip', file_obj, 'application/zip')}
r = requests.post(url,
auth=HTTPBasicAuth(
<username>, <password>),
headers=headers,
params=params,
files=files)
Any ideas about what’s wrong with this script?
11-17-2022 02:17 PM
In case anyone else runs into this same issue. I got it to work by leaving out the 'Content-Type': 'multipart/form-data'
header.