0

I have a task to create products programmatically using the JSON data.

I created a new module to make a custom controller. Then I hit the url using the http requester add on through Mozilla browser, and submitted the JSON data by POST method. But it does not fetch the submitted data.

If I am able to submit the JSON data through http requester to my controller, then I will be able to create the products using the same.

My controller code is updated here

<?php
class Probytes_Productcreate_IndexController extends Mage_Core_Controller_Front_Action {        

   public function indexAction() {
    $this->getResponse()->clearHeaders()->setHeader('Content-type','application/json',true);

    $this->getResponse()->setBody(json_encode($response));
    $params = $this->getRequest()->getPost('test');
    echo $params;
    //die();
    }

}
?>

Is there any solution to sumbit a JSON data to the custom controller in magento. I am using magento version 1.9. Any help would be appreciated. Thanks in advance.

  • put your code for posting JSON data – Minesh Patel Mar 22 '16 at 6:09
  • I have updated it. – SIBHI S Mar 22 '16 at 6:44
  • $params = $this->getRequest()->getPost('test'); put this as first line – Minesh Patel Mar 22 '16 at 6:46
  • not working! returns empty. – SIBHI S Mar 22 '16 at 6:50
  • how can I submit a json data with a web request url – SIBHI S Mar 22 '16 at 6:52
1

As Per discussion for http requester plug-in

Use Content Type application/x-www-form-urlencoded and use content as your JSON Data

  • No need for the Content Type as application/x-www-form-urlencoded. As per your suggestion during the discussion $this->getRequest()->getRawBody() did the magic for me. – SIBHI S Mar 23 '16 at 4:53

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.