cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Problems with the Snaplogic "Import a Project" API

halpert
New Contributor II

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?

1 REPLY 1

halpert
New Contributor II

In case anyone else runs into this same issue. I got it to work by leaving out the 'Content-Type': 'multipart/form-data' header.