Results 1 to 4 of 4

Thread: Help with NetworkRequest and Magento

  1. #1
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,882

    Help with NetworkRequest and Magento

    Hi all,
    I'm tryng to connect ianja to REST API of Magento.

    I've before try with PostMan and work fine.

    Then I've try with Lianja
    Code:
    oRequest = createObject("networkrequest")
    oRequest.async = .f.
    oRequest.setHeader("Authorization", "Bearer obfuscateToken")
    oRequest.setHeader("Accept", "application/json")
    oRequest.setHeader("Content-Type", "application/json")
    
    
    oRequest.GetFile("http://libher.it/rest/V1/order/id?id='100035770'","c:\temp\myfile.json")
    but I get every time:
    {"code":"401","message":"Accesso negato"}

    this is a working php code, sent me from the web master:
    Code:
    <?php
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    
    $api_endpoint = 'http://libher.it/rest/V1/order';
    $token = 'obfuscateToken';
    
    
    
    function curl_get ($url,$oauth_header){
        try{
            if (($curl = curl_init()) == false) throw new \Exception('Get - Impossibile inizializzare curl');
            $curl_opt = array(
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => false,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_ENCODING => "",
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 500,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => "GET",
                CURLOPT_HTTPHEADER => array(
                    "Accept: application/json",
                    "Content-Type: application/json",
                    "Authorization: " . $oauth_header,
                ),
            );
            if (curl_setopt_array($curl, $curl_opt) == false) throw new \Exception('Get - Impossibile settare le opzioni nel curl');
    
            if (($resp = curl_exec($curl)) === false) throw new \Exception('Get - '.curl_error($curl));
            $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
            curl_close($curl);
    
            if ($httpcode != 200) return "$httpcode";
            else return $resp;
        } catch (\Exception $e) {
            curl_close($curl);
            return $e;
        }  
    }
    
    
    try {
        $oauth_header = "Bearer $token";
        // GET ORDER
        $api_url = "$api_endpoint/id";
        print_r(curl_get($api_url, $oauth_header));
    
    } catch (OAuthException $e) {
        print_r($e);
    }
    can someone help me with a missing/wrong code?

    thanks
    Fabio

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,882
    this is the Postman test
    Name:  2020-05-06 18_40_05-Postman.jpg
Views: 41
Size:  61.9 KB

  3. #3
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,882
    Hi all,
    just to add some info..


    this code
    Code:
    headers = array()
    headers[] = "Host: libher.it"
    headers[] = "Authentication: Bearer obfuscateToken"
    headers[] = "Content-Type: application/json"
    
    url = "http://libher.it/rest/V1/order/from/"
    posturl(url, 30, headers, "c:\temp\myfile.json")
    work fine

  4. #4
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,882
    Ok, the problem is on the PHP page server side.. :-)
    The admin have send me a wrong information.

    All work fine.
    thanks
    Fabio

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us