I have a curl request like below I'm trying to convert it to guzzle but when I send a request to cloudflare it keeps returning me an error. "decoding error" Is there a bug in my guzzle request? Normal curl request should be stable.
`curl \
-X POST \
-d '{"url":"https://storage.googleapis.com/zaid-test/Watermarks Demo/cf-ad-original.mp4","meta":{"name":"My First Stream Video"}}' \
-H "Authorization: Bearer <API_TOKEN>" \
https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/stream/copy`
My codes are available below.
$response = $client->request('POST', 'https://api.cloudflare.com/client/v4/accounts/' . $accountId . '/stream/copy', [
'headers' => [
'Authorization' => 'Bearer ' . $token,
],
'form_params' => [
"url" => "https://storage.googleapis.com/zaid-test/Watermarks Demo/cf-ad-original.mp4",
"meta" => [
"name": "My First Stream Video"
]
]
CodePudding user response:
Try setting the content type header as well.
$response = $client->request('POST', 'https://api.cloudflare.com/client/v4/accounts/' . $accountId . '/stream/copy', [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $token,
],
'form_params' => [
"url" => "https://storage.googleapis.com/zaid-test/Watermarks Demo/cf-ad-original.mp4",
"meta" => [
"name": "My First Stream Video"
]
]
CodePudding user response:
This answer is using Laravel's HTTP request.
Http::withBody('{"url":"https://storage.googleapis.com/zaid-test/Watermarks Demo/cf-ad-original.mp4","meta":{"name":"My First Stream Video"}}')
->withToken('<API_TOKEN>')
->post('https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/stream/copy');
Also, check this amazing tool owned by Shift
https://laravelshift.com/convert-curl-to-http
CodePudding user response:
hello friends This is how I found the solution. If anyone has problems, they can use this.
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/json',
],
'json' => [
"url" => "https://storage.googleapis.com/zaid-test/Watermarks Demo/cf-ad-original.mp4",
"meta" => [
"name": "My First Stream Video"
]
]