PHP Post to MySQL DB using POST Script (post.post_process)

Hi,

I’m trying to add records to a new table after successful insertion of record to parent table through post script.

The record gets inserted but it runs in a indefinite loop and inserting like 180+ records instead of one record before it end up showing an error.

Error code : 502 Proxy Error
The proxy server received an invalid response from an upstream server.

Code Used :

$content = $event['response']['content'];
if(!empty($content['resource'])){
    foreach($content['resource'] as $k => $record){
        $record['extraField'] = 'Feed the dog';
        $content['resource'][$k] = $record;

        $api = $platform['api'];
        $post = $api->post;            
        // json string
        $json = '{"resource":[{"Name":"test", "Message":"test source"}]}';
        // converts json to php array
        $payload = json_decode($json, true);
        
        // makes POST call
        $result = $post('mysql/_table/test', $payload);
    }
    $event['response']['content'] = $content;
}

Kindly advise, I’ve searched the forum for hours and haven’t found any solution.

Many Thanks.