1

I'm using an API package send data to endboint using cURL

function create_customer_event() {
  $data =  [
    'email'                   => $shopify_json['email'] ?? '',
    'firstname'               => $shopify_json['first_name'] ?? '',
    'lastname'                => $shopify_json['last_name'] ?? '',
  ];

  $api = new MauticApi();
  $contactApi = $api->newApi('contacts', $auth, $apiUrl);
  $contactApi->create($data);
}

Then i have a webhook that send POST request to the same page and when this page that has this function receive this post request it run this function. The problem im facing is that the app that send that POST requests to my script if found that the response took more than few seconds it re-send the request again.

So im wondering if there is a way to receive that POST request to my script and respond with 200 then run my function in the background independantly (Since my function can take more than 2 seconds to excute).

I understand that it can be done by coding my curl function but it will be hard to implement since i will have to handle the oAuth2 also which was dont by the package.

Islam Mohamed
  • 117
  • 2
  • 10

1 Answers1

1

I believe redirecting the user with header("Location: blabla"); and having code you want executed after this would achieve what you want.

atoms
  • 2,993
  • 2
  • 22
  • 43
  • Thank you for your answer... actually i need to get the response from that webhook POST and pass it to the API... but actually your answer inspired me with an idea to create an intermediate page that capture that post data from the webhook and post it to my api script using cURL – Islam Mohamed May 01 '20 at 23:10