2017-09-27 9 views
0

나는이 API에 문제가있어 혹을 극복 할 수 없다. HTTP gem을 사용하면 (유연성이 있지만 RestClient을 사용하면 더 빨리 답변을 얻을 수 있습니다!). 어쨌든 배열을 게시하는 데 문제가 있습니다. 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 

을 그리고 내 출력이 인 다른 모든 좋은, 그냥 "itemsarray"는 addorder 방법에 여기에있는 printaura API를이 알아낼 수 없습니다 :

{"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 PHP 문서의 예제에서 내가 'itemsarray'만들 필요가 변경 생각 – bwatson30