setValidationGroup() expects a list of valid input names - php

I am trying to send a PATCH request through cURL and i get this response:
HTTP/1.1 400 Bad Request Server: nginx Date: Fri, 01 Apr 2016 09:16:03 GMT Content-Type: application/problem+json Content-Length: 198 Connection: keep-alive X-Powered-By: PHP/5.6.19 {"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Internal Server Error","status":500,"detail":"setValidationGroup() expects a list of valid input names; \"\" was not found"}
My code:
sendData("2016-10-01", "2016-10-02", "1234");
function sendData($from, $to, $property){
$data = array(
"from" => $from,
"to" => $to,
"booking_id" => 3
);
$data = json_encode($data);
echo $data . "<br>";
$url = "https://api.urlhost.com/property/".$property."/avail";
echo $url. "<br>";
$headers = array('Authorization: Basic dGVhQGJsdW1lbnJpdmllcmEuOIT6Qmx1bQVucm17aAKyzTtyfw==','Content-Type: application/json-patch+json');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HEADER, true);
$response = curl_exec($curl);
echo ($response) . PHP_EOL;
//print_r(curl_getinfo($ch));
curl_close($curl);
}
When i echo the data and url i get these:
{"from":"2016-10-01","to":"2016-10-02","booking_id":3}
https://api.urlhost.com/property/1234/avail
But still is giving me this error. Any suggestions why this might happen?

Related

CURL put not sending data

I'm trying to create a curl PUT request. However, for some reason the json data doesn't get send to the api server.
public function sendRequest($endpoint, $method, $params = [], $data = null)
{
$curl = curl_init();
$url = $this->host . "/" . $endpoint . "?" . http_build_query($params);
$data = array(
'ItemCode' => '3505180',
'SearchCode' => '123456',
);
$data_string = json_encode($data);
switch ($method) {
case "GET":
curl_setopt($curl, CURLOPT_HTTPGET, 1);
break;
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
if ($data) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
}
break;
default:
break;
}
curl_setopt($curl, CURLOPT_PROXY, '127.0.0.1:51290');
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'X-ApiKey: ' . $this->apiKey,
'administration: ' . $this->administration,
'Content-Type: application/json'
));
$result = curl_exec($curl);
if(curl_errno($curl))
{
$result = 'Curl error: ' . curl_error($curl);
}
curl_close($curl);
return $result;
This is how I use the sendRequest function:
public function updateItem($item)
{
$this->sendRequest("api/Item", "PUT", [], "some json data should go here");
}
If I look up the request in Fiddler, the JSON body or raw body is empty. This is the raw data:
PUT http://appsrv:889/api/Item HTTP/1.1
Host: appsrv:889
Accept: */*
Proxy-Connection: Keep-Alive
X-ApiKey: xxxxx
administration: 002
Content-Type: application/json
Content-Length: 44
Expect: 100-continue
I get the following as result:
HTTP/1.1 408 Request body incomplete
Date: Wed, 17 Aug 2022 07:18:01 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Cache-Control: no-cache, must-revalidate
Timestamp: 09:18:01.979
The request body did not contain the specified number of bytes. Got 0, expected 44
What could be wrong here?

"WISO mein Büro" API doesnt work or it is my fault

unfortunately I get no good response from the api provider.
No I need your support. I build a test extension in "wiso mein büro" for testing.
I would like to create an order with php and this api:
https://api.meinbuero.de/openapi/documentation/#/orders/postorderCreate
My code:
$wisoApiKey = "XXX";
$wisoSecretApiKey = "XXX";
$wisoOwnershipId = "XXX";
$positionen[] = array ('id' => 769541, 'amount' => 60);
$ch = curl_init('https://api.meinbuero.de/openapi/order/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json" , "Authorization: Bearer ".$wisoToken));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $wisoApiKey . ":" . $wisoSecretApiKey);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
array (
"customerId" => 1698487,
"articles" => $positionen
)
));
$createOrder = curl_exec($ch);
curl_close($ch);
echo '<pre>';
print_r($createOrder);
Result:
HTTP/1.1 500 Internal Server Error
Server: nginx/1.19.0
Date: Mon, 09 Aug 2021 18:38:49 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Strict-Transport-Security: max-age=7776000; includeSubDomains; preload
Access-Control-Allow-Origin: *
All other apis works fine like create, get customer, create invoice from order, ...
Only the api create order doesn't work for me.
I don't know why ...

PayPal NVP API - TransactionSearch Error 10001 Timeout processing request

I'm trying to build a custom accounting report using the PayPal NVP API that will get all transactions for a specific date range.
My code:
$headers = array(
'USER' => $production_user,
'PWD' => $production_pass,
'SIGNATURE' => $production_sig
);
$nvp = array(
'METHOD' => 'TransactionSearch',
'TRANSACTIONCLASS' => 'RECEIVED',
'STARTDATE' => '2016-12-01T00:00:00Z',
'ENDDATE' => '2016-12-31T00:00:00Z'
);
$request_url = "https://api-3t.paypal.com/nvp?".http_build_query($nvp);
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
$result = curl_exec($curl);
$result = explode("&", $result);
foreach($result as $f=>$v){
$t = explode("=", $v);
echo $t[0]." => ".urldecode($t[1]);
echo "<br>";
}
Here is what gets printed:
HTTP/1.1 200 OK Date: Fri, 10 Feb 2017 19:51:20 GMT Server: Apache X-PAYPAL-OPERATION-NAME: X-PAYPAL-API-RC: 10001 Connection: close Cache-Control: max-age => 0, no-cache, no-store, must-revalidate Pragma: no-cache HTTP_X_PP_AZ_LOCATOR: slcb.slc Paypal-Debug-Id: 484a759b46e4a Set-Cookie: X-PP-SILOVER
CORRELATIONID => some_random_characters
ACK => Failure
L_ERRORCODE0 => 10001
L_SHORTMESSAGE0 => Internal Error
L_LONGMESSAGE0 => Timeout processing request
Any assistance with this issue would be greatly appreciated!
You are using a post request and have not post data.
I do not know what PayPal wants to see but I'm guessing it's not what you are sending.
Some things to try:
If you need to pass the USER, PWD, and SIGNATURE in the Request Header do it like this:
$request = array();
$request[] = "USER: $production_user";
$request[] = "PWD: $production_pass";
$request[] = "SIGNATURE: $production_sig";
curl_setopt($ch, CURLOPT_HTTPHEADER, $request);
If the $nvp parameters need to be post data, try this:
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp);
The $nvp can be passed as a query string in the post data also.
$query = http_build_query($nvp);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
The difference is the Content-Type.
The first method:
Content-Type: application/x-www-form-urlencoded
The second method:
Content-Type: multipart/form-data
To help in trouble shooting it would be good to see both the request and response header.
Use these options to get the headers:
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
The Request Header will be in the 'curl_getinfo()'
curl_setopt($ch, CURLOPT_HEADER, true);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
var_export($info);
The above gives lots of other details of the request. If you only want to see the header:
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
To get the response header:
$result = curl_exec($ch);
$skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE));
$response = substr($result ,0,$skip);
$result = substr($result ,$skip);

PUT upload php curl command response is "Missing Content-Length header."

I write a php script to upload a media file but when I use it the response occurs:
Missing Content-Length header.
The php code is:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://raz-ul.domenka.com/v1/AUTH_8a619275-f933-4da1-b289-0ca1a2a3a4a5/bcd/drop1.avi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "X-Auth-Token: AUTH_tkd78bedda5bec4613b80becb1b2b3b4b5";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$header_size = $info['header_size'];
$header = substr($response, 0, $header_size);
var_dump($header);
On the other hand When I do something like that in cli I succeed:
kinduser#43915-1-c1c2c3-01:~/public_html/adam$ curl -i -X PUT -H "X-Auth-Token: AUTH_tkd78bedda5bec4613b80bec0123456789" -T drop.avi https://raz-ul.domenka.com/v1/AUTH_8a619275-f933-4da1-b289-0ca1a2a3a4a5/bcd/drop.avi
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
Last-Modified: Thu, 16 Feb 2017 10:12:54 GMT
Content-Length: 0
Etag: fa60ba1b78299bfae5ac61d1d2d3d4d5
Content-Type: text/html; charset=UTF-8
X-Trans-Id: tx114b22027223415c850db-e1e2e3e4e5
Date: Thu, 16 Feb 2017 10:12:53 GMT
kinduser#43915-1-c1c2c3-01:~/public_html/adam$
But I would like to do this in php. How to fix my php code?
Update
I added some code to tell curl which file to send. It sent the file but the file changed on the server. It got a bigger weight from 660kB to 660.31kB. After downloading to my pc it got impossible to open via video player.
That code is like this now:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://raz-ul.domenka.com/v1/AUTH_8a619275-f933-4da1-b289-0ca1a2a3a4a5/bcd/drop7.avi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "X-Auth-Token: AUTH_tkd78bedda5bec4613b80becb1b2b3b4b5";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$curlFile = curl_file_create ('./drop.avi');
$post = array (
'extra_info' => '123456',
'file_contents' => $curlFile
);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$header_size = $info['header_size'];
$header = substr($response, 0, $header_size);
var_dump($header);
Any idea how to fix it?

CURL not working from PHP but it does from command line

I'm calling a URL of this kind:
http://localhost:9910/app/check?name=alvaro&test=true
Accessing through the browser URL I get the correct result. And the same when using the command line with curl, it retrieves the correct information:
C:\>curl "http://localhost:9910/boxreload/check?name=alvaro&test=true" -i
HTTP/1.1 200 OK
Content-type: application/json; charset=UTF-8
Content-length: 203
Server: Restlet-Framework/2.3.3
Accept-ranges: bytes
Date: Fri, 22 Jan 2016 18:01:30 GMT
{"restul": "true"}
But when doing it with PHP it never comes back from the curl_exec and the server times out after 30 seconds.
$stringData = http_build_query($data);
$url = sprintf("%s?%s", $url, $stringData);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;',
'Content-Length: ' . strlen($stringData))
);
// $url is "'http://localhost:9910/boxreload/check?name=alvaro&test=true'"
curl_setopt($curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
//never comes back from this call (server times out)
$curl_response = curl_exec($curl);
if(curl_response === FALSE){
echo "error en CURL";
echo curl_error($curl);
}
curl_close($curl);
//never reaches this point
print_r($curl_response);
Why is it? Am I doing anything wrong?
As suggested, I'm turning my comment into an answer.
change the print_r in the last line to echo so that you can see the raw string output.
This code fragment:
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;',
'Content-Length: ' . strlen($stringData))
);
means you're sending these headers to the server when making the request:
Content-Type: application/json
Content-Length: nnn
where nnn is an integer representing the length of $stringData.
Just make sure the proper headers are sent when making the request or you will likely receive undesired results. It is unusual to specify the content-type and content-length as headers being passed from client to server. It should be the other way around (where server sends to the client the content-type and content-length header).
You forgot to do curl_init
$curl = curl_init();
and your if statement has a missing $ in front of the variable.
check this code:
$data = [];
$stringData = http_build_query($data);
$url = sprintf("%s?%s", "http://google.ro/", $stringData);
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;',
'Content-Length: ' . strlen($stringData))
);
// $url is "'http://localhost:9910/boxreload/check?name=alvaro&test=true'"
curl_setopt($curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
//never comes back from this call (server times out)
$curl_response = curl_exec($curl);
if($curl_response === FALSE){
echo "error en CURL";
echo curl_error($curl);
}
curl_close($curl);
//never reaches this point
print_r($curl_response);

Categories