curl Command Converter (Python, JavaScript fetch, PHP, Go, PowerShell)
Completely free, with no extra charges. You may freely use the output commercially.
About this tool
Paste a curl command from an API's documentation, or one you grabbed with “Copy as cURL” in your browser's developer tools, and this tool turns it into code that sends the same request in Python (requests), JavaScript (fetch), PHP (cURL), Go (net/http) or PowerShell (Invoke-WebRequest). It rewrites the method, URL, headers, JSON and form bodies, file uploads (-F), Basic authentication (-u), cookies (-b), timeouts, proxies and even the “don't verify the certificate” flag (-k) so that they mean the same thing they do in curl.
Besides bash and zsh syntax, it reads commands copied for the Windows Command Prompt, full of ^", and PowerShell commands split across lines with `. Along with the conversion, it lists which method, headers and body the request sends, so you can also use it just to check what a long curl command actually does. All processing happens entirely in your browser (no data is sent).
Convert a curl command
About this code
What the request contains
The request the curl command sends, as read from the command. URL-encoded query and form values are decoded back to the original characters, and JSON is pretty-printed.
How to use
- Paste the command into “curl command”. Commands split across lines with
\or^can be pasted as they are. - Choose a language under “Convert to”. “Converted code” updates as soon as you change the input or a setting.
- Use “Copy code” to take the result, or “Save as file” to get a file such as request.py or main.go. “About this code”, below the result, lists where the code behaves differently from curl and what it needs to run.
The example that is loaded first is a call to an orders API, copied from the browser's developer tools. Convert it to Python and the headers become a dict, the -b cookie becomes a Cookie header, and the JSON body becomes a Python dict passed to json= (false becomes False). Turn on “Omit headers the browser adds automatically” and the two lines for sec-ch-ua and sec-fetch-mode disappear from the code.
Converting from “Copy as cURL” in the developer tools
When you want to call, from your own program, an API that a website calls behind the scenes, the most reliable starting point is the request your browser actually sent. In Chrome and Edge, open the developer tools (F12), go to the “Network” tab, right-click the request and choose “Copy” → “Copy as cURL”. On Windows you will see two entries, “Copy as cURL (cmd)” and “Copy as cURL (bash)”. Whichever one you copy, the tool detects the format and reads it. “Copy as cURL” in Firefox's “Network” panel works the same way.
Commands copied from a browser include many headers the browser added on its own, such as sec-ch-ua, sec-fetch-site and priority. Most APIs respond without them, so try turning on “Omit headers the browser adds automatically” first and turn it off only if the request fails; the code is much easier to read that way. authorization and cookie carry your logged-in token or session as is. Before pasting the code into a chat or a public repository, delete those values or change the code to read them from environment variables.
curl options the tool understands
- Method and URL:
-X(--request),-I(HEAD),-G(send the-dvalues as a query with GET),--url,--url-query. When the URL has no scheme,http://is added, as curl does. - Headers:
-H,-A(User-Agent),-e(Referer),-b(Cookie),--oauth2-bearer. As in curl, an empty value such as-H 'Accept:'means “don't send this header”, and-H 'X-Empty;'means “send it with an empty value”. - Body:
-d(--data),--data-raw,--data-binary,--data-urlencode,--json,-F(--form),--form-string,-T(--upload-file). Several-dvalues are joined with&, and if no Content-Type is given,application/x-www-form-urlencodedis added, as curl does.--jsonsets both Content-Type and Accept toapplication/json. - Other:
-u(Basic authentication),-L(redirects),-k(don't verify the certificate),-m(--max-time),--connect-timeout,-x(proxy),-U,--compressed,-i,--http2and more. Options that only affect display or output, such as-s,-vand-o, do not change the request and are ignored.
When a value is read from a file, as in -d @data.json, the converted code reads that file too. With -d @file curl strips line breaks from the file before sending it, while --data-binary @file sends it unchanged. The converted code reflects this difference.
Where each language behaves differently from curl
The converted code sends the same request as curl, but some libraries behave differently from curl by default. Any that apply are listed below the result. The three most common are these.
- Redirects: Without
-L, curl does not follow redirects and returns the 301 or 302 response as is. Python requests, fetch, Go and PowerShell follow redirects by default. The PHP cURL extension behaves like curl and setsCURLOPT_FOLLOWLOCATIONonly when-Lis given. - Timeouts: curl's
--max-timelimits the whole transfer. Thetimeoutin requests limits how long it waits to connect and how long it waits for the next piece of data, so if data trickles in, it can wait longer than the number of seconds you gave. In fetch the code usesAbortSignal.timeout(), and in Go theTimeoutofhttp.Client, to impose a total limit. - Error handling: curl prints the response and exits even on 404 or 500. PowerShell's Invoke-WebRequest stops with an error by default, so the code adds
SkipHttpErrorCheckto show the response as curl does.
A JSON body becomes a dict passed to json= in Python and an object passed to JSON.stringify() in JavaScript, so the values are easy to edit. In both cases only the whitespace of the JSON that is sent changes; the data is the same as in the original command. When the body contains a large integer that a JavaScript number cannot represent exactly, such as 12345678901234567890, or a number whose notation would change, such as 1.10, the code sends the original string unchanged.
For a comparison of the headers and body that arrive when the original curl and the converted code are sent to the same server, and an example of JSON sent with -d without a Content-Type arriving as a form, see “Converting curl commands to Python requests or JavaScript fetch”, with screenshots.
Using curl on Windows
Windows 10 (version 1803) and later include the real curl (curl.exe), but typing curl in Windows PowerShell 5.1 runs Invoke-WebRequest under an alias instead. That is why passing curl options produces errors such as “A parameter cannot be found that matches parameter name 'X'.” To use curl in PowerShell, type curl.exe with the extension, or convert the command to Invoke-WebRequest code with this tool's “PowerShell” option. In PowerShell 7 the curl alias is gone and curl.exe runs.
The Command Prompt (cmd) does not support '…' quotes, and a " inside " must be written as \". Commands from Linux or macOS manuals often fail when pasted there as they are. On Windows, convert them to PowerShell code; to use a command copied on Windows under Linux, convert it to “curl (bash)”. Either way you save yourself the rewriting.
What this tool cannot tell you
The tool only translates the command; it never actually sends the request. Whether the converted code works depends on the API's specification and on whether the credentials are still valid. Shell variables such as $TOKEN and command substitutions such as $(cat token.txt) cannot be expanded, so they are kept literally and a warning is shown. Authentication other than Basic, such as --digest or --ntlm, client certificates with --cert, and config files with -K are not converted. Options the conversion does not support are listed below the input box as ignored.