PHP Curl Double Submission Issue

Hi There,

I am having an issue with a CURL POST causing double submissions for some reason. I have seen in some previous posts that this can be to do with how the results are printed however I have removed these steps and Im experiencing the same issues.

$final_JSON = json_encode($main_array2);
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "API-URL-HERE",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n    \"APIKey\": \"API-KEY\",\n    \"SiteID\": \"SITE-ID\",\n    \"UserID\":USER-ID\",\n    \"OrderItems\": [\n        {\n            \"ID\": \"cce12148-62c0-4704-a5a2-8b81a5d7734f\",\n            \"Quantity\": \"1\",\n            \"ModifierOptions\": [\n                {\n                    \"ID\": \"69904\",\n                    \"Quantity\": \"1\"\n                },\n                {\n                    \"ID\": \"69907\",\n                    \"Quantity\": \"1\"\n                },\n                {\n                    \"ID\": \"69913\",\n                    \"Quantity\": \"1\"\n                },\n                {\n                    \"ID\": \"69924\",\n                    \"Quantity\": \"1\"\n                },\n                {\n                    \"ID\": \"70137\",\n                    \"Quantity\": \"1\"\n                }\n            ]\n        }\n    ],\n    \"OrderType\": \"0\",\n    \"RequiredDate\": \"27/04/20\",\n    \"RequiredTime\": \"18:30\",\n    \"Name\": \"DO NOT PREP\",\n    \"DeliveryAddress\": \"PICKUP FROM SHOP\",\n    \"DeliveryPostcode\": \"KT21 2DB\",\n    \"TelNo\": \"00000\",\n    \"Email\": \"[email protected]\",\n    \"Payment\": {\n        \"PaymentType\": \"4\",\n        \"TransactionID\": \"1234\"\n    },\n    \"Discount\": \"0.00\",\n    \"OrderTotal\": \"12.25\"\n}",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/json"
  ),
));
curl_exec($curl);
curl_close($curl);

Any Ideas of what is occurring ?

Thanks

First, your json is not valid.

That code is fine, but does something call it?

Hi @astonecipher thanks for the reply

This is a direct copy from POSTMAN

<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "API-URL-HERE", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS =>"{\n \"APIKey\": \"B242F6AC-2E68-4ED3-ABD6-77A436EEDF64\",\n \"SiteID\": \"9E398669-E0DD-43E8-B6A9-AA642052E2D6\",\n \"UserID\": \"c2e0ec4c-a2d5-4530-a5b4-dc0515d05810\",\n \"OrderItems\": [\n {\n \"ID\": \"cce12148-62c0-4704-a5a2-8b81a5d7734f\",\n \"Quantity\": \"1\",\n \"ModifierOptions\": [\n {\n \"ID\": \"69904\",\n \"Quantity\": \"1\"\n },\n {\n \"ID\": \"69907\",\n \"Quantity\": \"1\"\n },\n {\n \"ID\": \"69913\",\n \"Quantity\": \"1\"\n },\n {\n \"ID\": \"69924\",\n \"Quantity\": \"1\"\n },\n {\n \"ID\": \"70137\",\n \"Quantity\": \"1\"\n }\n ]\n }\n ],\n \"OrderType\": \"0\",\n \"RequiredDate\": \"27/04/20\",\n \"RequiredTime\": \"18:30\",\n \"Name\": \"DO NOT PREP\",\n \"DeliveryAddress\": \"PICKUP FROM SHOP\",\n \"DeliveryPostcode\": \"KT21 2DB\",\n \"TelNo\": \"00000\",\n \"Email\": \"[email protected]\",\n \"Payment\": {\n \"PaymentType\": \"4\",\n \"TransactionID\": \"1234\"\n },\n \"Discount\": \"0.00\",\n \"OrderTotal\": \"12.25\"\n}", CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "Content-Type: application/json" ), )); $response = curl_exec($curl); curl_close($curl); echo $response;

Sorry to hide the API url but im under an NDA towards the API links…

running the POST in POSTMAN works fine and only generates the record once however this code output from POSTMAN creates it twice!

Not understanding. Postman shouldn’t be outputting php, or are you referring to the json?

@astonecipher
I have set the JSON POST up in POSTMAN and it runs fine. The below PHP code is generated from the code section within POSTMAN

> <?php
> 
> $curl = curl_init();
> 
> curl_setopt_array($curl, array(
> CURLOPT_URL => "https://api.pointone.co.uk/OOAppService.svc/GuestOrder/JSON",
> CURLOPT_RETURNTRANSFER => true,
> CURLOPT_ENCODING => "",
> CURLOPT_MAXREDIRS => 10,
> CURLOPT_TIMEOUT => 0,
> CURLOPT_FOLLOWLOCATION => true,
> CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
> CURLOPT_CUSTOMREQUEST => "POST",
> CURLOPT_POSTFIELDS =>"{\"APIKey\":\"B242F6AC-2E68-4ED3-ABD6-77A436EEDF64\",\"SiteID\":\"9E398669-E0DD-43E8-B6A9-AA642052E2D6\",\"UserID\":\"c2e0ec4c-a2d5-4530-a5b4-dc0515d05810\",\"OrderItems\":[{\"ID\":\"cce12148-62c0-4704-a5a2-8b81a5d7734f\",\"Quantity\":\"1\",\"ModifierOptions\":[{\"ID\":\"69904\",\"Quantity\":\"1\"},{\"ID\":\"69907\",\"Quantity\":\"1\"},{\"ID\":\"69913\",\"Quantity\":\"1\"},{\"ID\":\"69924\",\"Quantity\":\"1\"},{\"ID\":\"70137\",\"Quantity\":\"1\"}]}],\"OrderType\":\"0\",\"RequiredDate\":\"28\\/04\\/20\",\"RequiredTime\":\"15:00\",\"Name\":\"DO NOT PREP\",\"DeliveryAddress\":\"PICKUP FROM SHOP\",\"DeliveryPostcode\":\"KT21 2DB\",\"TelNo\":\"00000\",\"Email\":\"[email protected]\",\"Payment\":{\"PaymentType\":\"4\",\"TransactionID\":\"test-id-here\"},\"Discount\":\"0.00\",\"OrderTotal\":\"12.25\"}",
> CURLOPT_HTTPHEADER => array(
> "Content-Type: application/json"
> ),
> ));
> 
> $response = curl_exec($curl);
> 
> curl_close($curl);
> echo $response; ?>

And for some reason when this command is run it generates two submissions. I have no idea why!

Further to this I have run this script using google chrome and it doesn’t cause double submission! :flushed::face_with_monocle:

I am not seeing a reason it would run twice

I have tried running on safari and chrome.

every time its run on safari it generates two records, on chrome it doesn’t!

Im very confused!

Sponsor our Newsletter | Privacy Policy | Terms of Service