dosubot[bot] commented on issue #33659:
URL: https://github.com/apache/superset/issues/33659#issuecomment-2928892881

   <!-- Greeting -->
   Hi @Nagarajkalasagonda! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m 
helping the superset team.
   
   <!-- Answer -->
   The error "Arguments are not correct" when using the import chart API is 
likely due to the structure of your request payload. The /api/v1/chart/import/ 
endpoint expects a multipart/form-data request where the form field formData 
contains the ZIP file itself, not a JSON string, and the overwrite flag is a 
separate form field, not embedded in formData. Your script is currently sending 
formData as a JSON string and bundle as the ZIP file, which does not match the 
API's expectations.
   
   Here’s how you should structure your request:
   
   - The form field formData should be the ZIP file (not a JSON string).
   - The overwrite flag should be a separate form field with the string value 
"true" (not a boolean or JSON).
   - You do not need a bundle field.
   
   Here’s a corrected version of your import_chart_bundle function:
   
   ```python
   def import_chart_bundle(url, access_token, zip_path):
       import_url = f"{url}/api/v1/chart/import/"
       headers = {
           "Authorization": f"Bearer {access_token}"
       }
       with open(zip_path, "rb") as f:
           files = {
               "formData": ("zz.zip", f, "application/zip"),
           }
           data = {
               "overwrite": "true"
           }
           response = requests.post(import_url, headers=headers, files=files, 
data=data)
       response.raise_for_status()
       return response.json()
   ```
   
   This matches the API’s requirements: formData is the ZIP file, and overwrite 
is a string field in the form data, not part of the file upload or a JSON 
string. The API will then correctly recognize the arguments and process the 
import as it does in the UI.
   
   For reference, the API expects these fields in the multipart form: formData 
(ZIP file), overwrite (string "true" or "false"), and optionally passwords and 
SSH tunnel fields if needed. See the implementation details 
[here](https://github.com/apache/superset/blob/c09f8f6f7665e503a376926700fa815add6892ca/superset/charts/api.py).
   
   If you still get errors, double-check that your ZIP file contains a valid 
metadata.yaml with the correct version field (version: 1.0.0) as required by 
the import logic 
[here](https://github.com/apache/superset/blob/c09f8f6f7665e503a376926700fa815add6892ca/superset/commands/importers/v1/utils.py).
   
   This adjustment should resolve the "Arguments are not correct" error and 
allow your script to import charts just like the UI.
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/ca69721f-3ec4-4b31-8694-d66b6f33dd1f?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/ca69721f-3ec4-4b31-8694-d66b6f33dd1f?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/ca69721f-3ec4-4b31-8694-d66b6f33dd1f?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/ca69721f-3ec4-4b31-8694-d66b6f33dd1f?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/ca69721f-3ec4-4b31-8694-d66b6f33dd1f?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/ca69721f-3ec4-4b31-8694-d66b6f33dd1f?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/ca69721f-3ec4-4b31-8694-d66b6f33dd1f?feedback_type=other)</sup>&nbsp;&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[!
 [Share on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/33659)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to