Python requests to Javascript fetch?

I’m trying to translate this working Python 3.x code, that uses Python’s “requests” library, into Javascript ES6 code that uses 'fetch", but I cannot seem to replicate the request using Javascript. The problem seems to be that the requests “files” parameter does some kind of form encoding. Anyone have ideas?

import json
import requests

url="https://something.com/dosomething"
something ="1"

headers = {
    'Bearer': 'mysecretkey'
}

params = {
     "type": "G",
     "numImages": 1,
     "generateParams": {
     "query": "a query here"
      }
}

data = {
      'mode': (None, something),
      'params': (None, json.dumps(params), 'application/json')
}

response = requests.post(url, headers, files=data)

Hey @sashimikid :wave:

Welcome to the Postman Community! :postman:

Do you have or are you working of any documentation that has a cURL example attached? You could paste that straight into the request bar and it will create the Request in Postman.

There looks to be tools like this on that might help you out here:

Once you have the Postman request created, you can use the code snippet generator to grab the fetch syntax.

I’m not familiar with Python so I couldn’t translate all of your request, not sure that some of that need to be within a json file or not:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.