โ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.