We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 54322
    • 6 Posts
    I need to install a modx revo and some content will be use a api example of api:

    "example GET require:

    $ch = curl_init(""https://autoprokat24.ru/api/crm/bagholerange"");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ""GET"");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(########################## //autorize (token)
    $result = curl_exec($ch);
    curl_close($ch);
    $response = json_decode($result); "
    and:

    "post require"

    $data = array(
    ""phone""=>""+7(555)555-55-55"",
    ""model_id""=>""15"",
    ""tip_arendy""=>""daily"",
    ""sum""=>""999""
    );

    $ch = curl_init(""https://autoprokat24.ru/api/crm/oneclickorder"");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(#######################));
    $result = curl_exec($ch);
    curl_close($ch);
    $response = json_decode($result); "
    Who can help me how i can use this for modx revo, because i have not found the answer in off site
    Please give me a works example [ed. note: imagination last edited this post 5 years, 10 months ago.]
      • 3749
      • 24,544 Posts
      If I'm understanding you, you'd just create a standard HTML form and put the code above into one or more snippets so the code would run when the form was submitted.

      If you want to display the information returned from the API, you can use it to create a string containing the HTML code to display and return that string from the snippet. Or, better, you can create a chunk with placeholders for the information and do this in the snippet:

      // set the variables from the data
      $fields = array(
         'placeholdername1' => $placeholder1Value,
         'placeholdername2' => $placeholder2Value,
          // etc.
      );
      
      return $modx->getChunk('chunkName', $fields);


      BTW, I hope you didn't just post your own authorization code for the API in a public forum. wink
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 54322
        • 6 Posts
        Quote from: BobRay at Jun 18, 2018, 03:52 AM


        BTW, I hope you didn't just post your own authorization code for the API in a public forum. wink
        Thank you)



        Yes you are right;

        Now this code return me a data which is into text file.
        And this data i need to parse and show in my site
        but i can not to find how i can do this
        Here is two objects and two array with TC MAX and MIN
        Can you help me to write a right code for parsing this file and display this information of cars into my tags in hmtl
          • 3749
          • 24,544 Posts
          Uploading files doesn't work in the forums, so I can't see your file, but I'm going to guess that you need something like this:

          $placeholders = $modx->fromJSON($data);
          return $modx->getChunk('YourChunk', $placeholders);


          Put placeholder tags in the chunk with the names of the keys in the returned array. They will show the corresponding values:

          [[+keyName]]


          If it's a multi-dimensional array, you may have to use some code to set the placeholder array correctly. To see exactly what you get from $modx->fromJSON(), do this:

          $placeholders = $modx->fromJSON($data);
          return '<pre>' . print_r($placeholders, true) . '</pre>';
          

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting