I’m trying to use the API example from this URL:
I’ve successfully deployed MANY API calls to Square, but for some strange reason, this one requires “version: 0” to be sent, unlike almost every other call I’ve used.
I’m using curl in PHP to make the call:
$postfields = ‘{“version”: “0”}’;
$curl_url = “https://connect.squareup.com/v2/invoices/” . $invoice_id . “/cancel”;
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $curl_url,
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HTTPHEADER => array(
‘Square-Version: 2024-12-18’,
'Authorization: Bearer ’ . $square_access_token,
‘Content-Type: application/json’
)
));$response = curl_exec($ch);
$parsed_response = json_decode($response, true);
When that code is ran, it gives me this error message:
{“errors”:[{“code”:“VERSION_MISMATCH”,“detail”:“Version is not up to date”,“field”:“version”,“category”:“INVALID_REQUEST_ERROR”}]}
The even more bizarre thing is that it was working perfectly fine (literally running the script with a while loop of people to cancel invoices for) and all of a sudden, using the exact same code, it stopped working in the middle of the script running.
I’m guessing it’s just something stupid I’m doing in the PHP code when trying to pass the value for “version”, but I could be wrong. Any help would be greatly appreciated!
Thanks,
Andy