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&UserName=anurag.111@gmail.com';

 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

  • 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 Feb 19 '18 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 Feb 19 '18 at 9:33
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&UserName=anurag.111@gmail.com';

     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, privacy policy and cookie policy

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