0

I have rest API URL but how to run the in rest API.

    $service_url='http://testing.com/data/rest/Masters/CheckPartnerId?Key=121&Type=CREATE&PartnerId=13&BrandId=67&StoreId=main_website_store&ValidateId=Mpnid&[email protected]';

 try {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $service_url);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
           // curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            $response = curl_exec($ch);

            $response1 = json_decode($response, true);
            echo '<pre>'; print_r($response1); exit;
        } catch (Exception $e) {
            echo $e->getMessage();
            //$debugshipData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
        }

Can you please help me

2
  • why are you commenting the $CURLOPT_POSTFIELDS? that is the line supposed to send the data in the POST variable... what is the problem?
    – sissy
    Commented Feb 19, 2018 at 9:09
  • So, is it solved in this way? then i will put my comment as answer and you could mark it as accepted to help out others.
    – sissy
    Commented Feb 19, 2018 at 9:33

1 Answer 1

0

This code is working.

$service_url='http://testing.com/data/rest/Masters/CheckPartnerId?Key=121&Type=CREATE&PartnerId=13&BrandId=67&StoreId=main_website_store&ValidateId=Mpnid&[email protected]';

     try {
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $service_url);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                $response = curl_exec($ch);

                $response1 = json_decode($response, true);
                echo '<pre>'; print_r($response1); exit;
            } catch (Exception $e) {
                echo $e->getMessage();
                //$debugshipData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
            }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.