2017-09-27 2 views
0

私はこのapiに問題があり、やりとりを乗り越えるように見えません。 HTTP gemを使用しています(ただし、柔軟性があり、回答が早い場合はRestClientを使用できます)。とにかく、配列のポストに問題があります。他のすべてが良いですが、私はちょうどprintaura APIで、この「itemsArrayの」を把握することはできませんaddorder方法でここに見つける:PrintAura APIAPI HTTPのgem(またはRestClient)を使用した配列のPOST

私はこの実行している:

def self.submitorder 
    req = HTTP.post("https://api.printaura.com/api.php", :json => { 
     :key => APIKEY, 
     :hash => APIHASH, 
     :method => "addorder", 
     :businessname => "this is a secret too", 
     :businesscontact => "thats a secret", 
     :email => "[email protected]", 
     :your_order_id => "1", 
     :returnlabel => "FakeAddress", 
     :clientname => "ShippingName", 
     :address1 => "ShippingAddressLine1", 
     :address2 => "ShippingAddressLine2", 
     :city => "ShippingCity", 
     :state => "ShippingState", 
     :zip => "ShippingZip", 
     :country => "US", 
     :customerphone => "dontcallme", 
     :shipping_id => "1", 
     :itemsarray => {:item => [ 
      :product_id => 423, 
      :brand_id => 33, 
      :color_id => 498, 
      :size_id => 4, 
      :front_print => 1389517, 
      :front_mockup => 1390615, 
      :quantity => 1 
      ]} 

    }) 

    puts JSON.parse(req) 




end 

そして、私の出力は、このです:

{"status"=>false, "error_code"=>19, "result"=>19, "message"=>"You cannot place an order without items, Please fill the items array with all the required information. Full API documentation can be found at https:/www.printaura.com/api/"} 

誰かがそれを見て私を助けてくれたら、私は永遠にそれを感謝します。

答えて

0
def self.submitorder 
    itemsarray = { :items => [ { :product_id => 423, :brand_id => 33, :color_id => 498, :size_id => 4, :quantity => 1, :front_print => 1389517, 
     :front_mockup => 1390617 } ] } 
    req = HTTP.post("https://api.printaura.com/api.php", :json => { 
    :key => APIKEY, 
    :hash => APIHASH, 
    :method => "addorder", 
    :businessname => "this is a secret too", 
    :businesscontact => "thats a secret", 
    :email => "[email protected]", 
    :your_order_id => "1", 
    :returnlabel => "FakeAddress", 
    :clientname => "ShippingName", 
    :address1 => "ShippingAddressLine1", 
    :address2 => "ShippingAddressLine2", 
    :city => "ShippingCity", 
    :state => "ShippingState", 
    :zip => "ShippingZip", 
    :country => "US", 
    :customerphone => "dontcallme", 
    :shipping_id => "1", 
    :items => Base64.encode64(itemsarray.to_json)} 
) 

    puts JSON.parse(req) 

私は本当にこれは、同じメッセージを動作しませんでした今笑

0

JSONで配列を作成するには、Rubyで配列を使用します。それは簡単です。

require 'json' 

def self.submitorder 
    req = HTTP.post("https://api.printaura.com/api.php", :json => { 
     :key => APIKEY, 
     :hash => APIHASH, 
     :method => "addorder", 
     :businessname => "this is a secret too", 
     :businesscontact => "thats a secret", 
     :email => "[email protected]", 
     :your_order_id => "1", 
     :returnlabel => "FakeAddress", 
     :clientname => "ShippingName", 
     :address1 => "ShippingAddressLine1", 
     :address2 => "ShippingAddressLine2", 
     :city => "ShippingCity", 
     :state => "ShippingState", 
     :zip => "ShippingZip", 
     :country => "US", 
     :customerphone => "dontcallme", 
     :shipping_id => "1", 
     :items => [ 
      { 
      :product_id => 423, 
      :brand_id => 33, 
      :color_id => 498, 
      :size_id => 4, 
      :front_print => 1389517, 
      :front_mockup => 1390615, 
      :quantity => 1 
      } 
     ] 
    }) 

    puts JSON.parse(req) 

APIには、オブジェクトの配列を含むitemsパラメータがリストされています。それはitemsarrayについて何も言わない。

+0

から何年か誰かを助けたいと考えています。私はとても困惑しています。私は早くもそれを試みた。私はちょうどそれが$ postfieldから$ itemsarrayに変更されて以来、私は 'itemsarray' – bwatson30

関連する問題