2017-10-02 1 views
-2

Shopifyで製品を作成するにはshopify-api-nodeを使用しています。 Iはshopify-api-nodeは余分なキーで解析します

shopify.metafield.create({ 
    key: 'warehouse', 
    value: 25, 
    value_type: 'integer', 
    namespace: 'inventory', 
    owner_resource: 'product', 
    owner_id: 632910392 
}).then(
    metafield => console.log(metafield), 
    err => console.error(err) 
); 

この構文を使用すると、このコードに変換:

self.parsedOutgoingItem(req, item, function(err, parsedItem) { 
          // get the corresponding method name for this type of model request 
          var recordType = modelMapping.key; 
          var postMethod = modelMapping.methods.post; 
          console.log(parsedItem); 
          console.log(JSON.stringify(parsedItem)); 
          shopify[recordType][postMethod]({ 
           parsedItem 
          }).then(
           metafields => console.log(metafields), 
           err => console.error(err) 
          ); 
         }); 

項目オブジェクト parsedItemがShopifyキー値

parsedItemコンソールとobjをマッピングされています出力

この状態

if (params) { 
    const body = key ? { [key]: params } : params; 

    options.headers['Content-Type'] = 'application/json'; 
    options.body = body; 
    } 

enter image description here

を使用している行番号115 ... でindex.jsのコードの結果として

{ 
images:[ {"src":"https://s3.amazonaws.com/com.rugcopro.photos.turcopersian/images/268d6fd8-cb43-4309-b85e-1e747421df25.png"},          {"src":"https://s3.amazonaws.com/com.rugcopro.photos.turcopersian/images/c8af415e-2c6a-44df-9a18-42425389641a.png"} 
], 
product_type:"Rug", 
tags:["Oversize","Kerman Ravar","Rug","traditional",700,"Runner","Rectangle","Blue","Green"], 
title:"tirlw hsdka", 
variants:{"price":700,"option3":"wool","title":"Rug wool","sku":"13698,27411i","option1":"3.9x17.1","option2":"Green"} 
} 

210は、それが

として私のJSON OBJを構文解析しました
{"product": `//it is what we need` 
{"parsedItem": `//it is what comes up which is causing the error` 
{ 
images:[ {"src":"https://s3.amazonaws.com/com.rugcopro.photos.turcopersian/images/268d6fd8-cb43-4309-b85e-1e747421df25.png"}, {"src":"https://s3.amazonaws.com/com.rugcopro.photos.turcopersian/images/c8af415e-2c6a-44df-9a18-42425389641a.png"} 
], 
product_type:"Rug", 
tags:["Oversize","Kerman Ravar","Rug","traditional",700,"Runner","Rectangle","Blue","Green"], 
title:"tirlw hsdka", 
variants:{"price":700,"option3":"wool","title":"Rug wool","sku":"13698,27411i","option1":"3.9x17.1","option2":"Green"} 
} 
} 

objの余分な "parsedItem"キーのために、エラーが発生してポストリクエストが発生しています。 どうすればこのエラーを解決できますか?

私は初心者です。ここで問題を作成する前に、私はすでにStackOverflowに投稿しましたが、誰もそれに答えませんでした。誰かが私を助けてくれたら親切です。

答えて

0

愚かな私!

self.parsedOutgoingItem(req, item, function(err, parsedItem) { 
          // get the corresponding method name for this type of model request 
          var recordType = modelMapping.key; 
          var postMethod = modelMapping.methods.post; 
          console.log(parsedItem); 
          console.log(JSON.stringify(parsedItem)); 
          shopify[recordType][postMethod](
           parsedItem 
          ).then(
           metafields => console.log(metafields), 
           err => console.error(err) 
          ); 
         }); 

だけ{}

parsedItem 周りを除去するために必要
関連する問題