how to write header content type json data to csv file in php? -


we have been working 3d cart rest response have here code.file name example.php located in wamp server

<?php  $host = 'https://apirest.3dcart.com'; $version = 1; $service = 'orders'; $secureurl = 'https://xxxxyyyyy.3dcart.net';   // secure url set in settings->general->storesettings $privatekey = 'xxxxxxxxxxxxxxxx'; // private key obtained when registering app @ http://devportal.3dcart.com $token = 'xxxxxxxxxxxxx';      // token generated when customer authorizes app // initialize curl session $ch = curl_init($host . '/3dcartwebapi/v' . $version . '/' . $service); // set headers $httpheader = array(         'content-type: application/json;charset=utf-8',         'accept: application/json',         'secureurl: ' . $secureurl,         'privatekey: ' . $privatekey,         'token: ' . $token, ); curl_setopt($ch, curlopt_httpheader, $httpheader); // [ ... addtional curl options needed ... ] $response = curl_exec($ch);    if ($response === false) {     $response = curl_error($ch); }   curl_close($ch); 

we have access file on browser using url http://localhost/social/example.php response in json without json encoded. want array response can write csv file.i have many try google no more luck appropriate solution.thanks in advance.

[{"invoicenumberprefix":"ab-","invoicenumber":1000,"orderid":1,"customerid":1,"orderdate":"2014-01-10t12:44:37","orderstatusid":1,"lastupdate":"0001-01-01t00:00:00","userid":"","salesperson":"","continueurl":"http://71745179439.3dcart.net/continue_order.asp?orderkey=tl31s22wts7b0hf1","billingfirstname":"john","billinglastname":"doe","billingcompany":"","billingaddress":"123 street","billingaddress2":"","billingcity":"coral springs","billingstate":"fl","billingzipcode":"33065","billingcountry":"us","billingphonenumber":"800-828-6650","billingemail":"test@3dcart.com","billingpaymentmethod":"online credit card","billingonlinepayment":true,"billingpaymentmethodid":"1","shipmentlist":[{"shipmentid":0,"shipmentlastupdate":"0001-01-01t00:00:00","shipmentboxes":1,"shipmentinternalcomment":"sample order 3dcart","shipmentorderstatus":1,"shipmentaddress":"123 street","shipmentaddress2":"","shipmentalias":"","shipmentcity":"coral springs","shipmentcompany":"","shipmentcost":0.0,"shipmentcountry":"us","shipmentemail":"","shipmentfirstname":"test","shipmentlastname":"test","shipmentmethodid":0,"shipmentmethodname":"free shipping","shipmentshippeddate":"","shipmentphone":"800-828-6650","shipmentstate":"fl","shipmentzipcode":"33065","shipmenttax":0.0,"shipmentweight":1.0,"shipmenttrackingcode":"","shipmentuserid":"","shipmentnumber":1,"shipmentaddresstypeid":0}],"orderitemlist":[{"catalogid":3,"itemindexid":1,"itemid":"1003k","itemshipmentid":0,"itemquantity":1.0,"itemwarehouseid":0,"itemdescription":"tote bag color: khaki","itemunitprice":1.0,"itemweight":3.0,"itemoptionprice":0.0,"itemadditionalfield1":"","itemadditionalfield2":"","itemadditionalfield3":"","itempageadded":"tote-bag_p_3.html","itemdateadded":"2009-06-22t12:05:07","itemunitcost":0.0,"itemunitstock":5.0,"itemoptions":",1","itemcatalogidoptions":"","itemserial":"","itemimage1":"http://71745179439.3dcart.net/assets/images/default/handbag.jpg","itemimage2":"http://71745179439.3dcart.net/assets/images/default/handbag.jpg","itemimage3":"http://71745179439.3dcart.net/assets/images/default/handbag.jpg","itemimage4":"http://71745179439.3dcart.net/assets/images/default/handbag.jpg","itemwarehouselocation":"","itemwarehousebin":"","itemwarehouseaisle":"","itemwarehousecustom":""}],"promotionlist":[],"orderdiscount":0.0,"salestax":0.0,"salestax2":0.0,"salestax3":0.0,"orderamount":1.0,"affiliatecommission":0.0,"transactionlist":[],"cardtype":"","cardnumber":"","cardname":"john doe","cardexpirationmonth":"","cardexpirationyear":"","cardissuenumber":"","cardstartmonth":"","cardstartyear":"","cardaddress":"","cardverification":"","rewardpoints":"1","questionlist":[],"referer":"http://www.google.com","ip":"","customercomments":"sample order 3dcart","internalcomments":"","externalcomments":""}] 

you can use json_decode php function : http://php.net/manual/fr/function.json-decode.php

on code :

    <?php      $host = 'https://apirest.3dcart.com';     $version = 1;     $service = 'orders';     $secureurl = 'https://xxxxyyyyy.3dcart.net';   // secure url set in settings->general->storesettings     $privatekey = 'xxxxxxxxxxxxxxxx'; // private key obtained when registering app @ http://devportal.3dcart.com     $token = 'xxxxxxxxxxxxx';      // token generated when customer authorizes app     // initialize curl session     $ch = curl_init($host . '/3dcartwebapi/v' . $version . '/' . $service);     // set headers     $httpheader = array(             'content-type: application/json;charset=utf-8',             'accept: application/json',             'secureurl: ' . $secureurl,             'privatekey: ' . $privatekey,             'token: ' . $token,     );     curl_setopt($ch, curlopt_httpheader, $httpheader);     // [ ... addtional curl options needed ... ]     $response = curl_exec($ch);        if ($response === false) {         $response = curl_error($ch);     }      curl_close($ch);  $arrayresponse = json_decode($response, true); //do array 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -