I’m working with a third-party API that only provides command line cURL examples in their documentation. They don’t have any PHP examples, which makes it hard for me to implement.
I need help understanding how to convert these terminal cURL commands into proper PHP cURL syntax.
Here are the command line examples I’m trying to convert:
Your PHP code treats a GET request like a POST request. The -G flag in your first cURL forces GET, and the second example defaults to GET. But your PHP has CURLOPT_POST => 1, making it POST instead. You’re also putting the auth token in CURLOPT_POSTFIELDS when it belongs in headers. Move the Authorization-Token to CURLOPT_HTTPHEADER - that’s where it goes, not in post data. For the first example, build your URL with query parameters and set the auth header correctly. Ditch all the POST settings since both cURL commands are GET requests. That’s why you’re getting false back - the API probably doesn’t accept POST on that endpoint. I ran into the same thing when I started converting cURL to PHP. Remember: -H means headers, -d with -G means query params, and no method flag usually means GET.
Everyone’s right about the core issue, but here’s how to skip this headache completely.
I used to waste hours debugging cURL conversions. Then I realized there’s a better approach - just automate the whole process instead of manually converting command line cURL to PHP every time.
I built a workflow in Latenode that handles API calls without any cURL code. Paste your endpoint, add headers and params through the visual interface, and it handles HTTP methods automatically. No more guessing GET vs POST.
For your case, you’d set up two HTTP request nodes. First gets your endpoint URL, second handles the auth token as a header. The platform knows it’s a GET request and builds everything right.
I use this for all our third party integrations now. 5 minutes setup vs 30 minutes debugging PHP cURL each time. You can chain multiple API calls and add error handling without code.
The visual workflow shows exactly what’s happening - no more mystery false responses.
You’re mixing up HTTP methods and parameter placement. Your cURL commands use GET requests, but your PHP has CURLOPT_POST => 1 which forces POST. Just remove both CURLOPT_POST and CURLOPT_POSTFIELDS entirely. Put the Authorization-Token in CURLOPT_HTTPHEADER, not POST data. I’ve debugged tons of these conversions - the -G flag forces GET method in cURL, and -d parameters become query string data with -G. For your PHP version, build the complete URL with parameters first, then only set the header and return options. Add curl_error($ch) after curl_exec() to see what’s actually failing. Most APIs give you detailed error messages that’ll tell you if it’s auth, method, or parameter problems. Your code’s probably failing because the endpoint wants GET but gets POST with mangled parameters.
I’ve hit this before. The -H flag always translates to CURLOPT_HTTPHEADER. When you see -G with -d, those parameters go in the URL query string. Drop all the POST stuff - these are GET requests.
Use http_build_query() instead of building URLs manually. Much cleaner.
You’re mixing up HTTP methods and where to put parameters. Both your cURL examples are GET requests, but your PHP code has CURLOPT_POST => 1 which forces POST. Delete that line and CURLOPT_POSTFIELDS too. Headers from cURL’s -H flag always go in CURLOPT_HTTPHEADER in PHP. Put your Authorization-Token there, not in POST fields. When you see -G -d in cURL, those parameters become URL query strings in PHP. I’ve worked with APIs for years - this exact mistake gets most developers. cURL defaults to GET unless you tell it otherwise, but PHP cURL needs explicit setup. Double-check your HTTP method matches what the API wants. Many endpoints reject POST when they expect GET, which explains the false response you’re getting.
you’re sending POST requests when those curl commands expect GET. drop CURLOPT_POST => 1 and CURLOPT_POSTFIELDS entirely. also check if curl_exec is returning false - throw in curl_error($ch) to see what’s actually breaking. could be ssl or network issues, not just your code.