2017-11-24 14 views
1

サブスクライバをmailchimpリストに追加しようとしていますが、エラーメッセージTypeError: name.toUpperCase is not a functionが続きます。ここに私のコードがあり、完全な出力は以下の通りです。 mailchimpにバグがある場合は誰でも知っていますか、何か間違っていますか?mailchimpサブスクライバエラーを追加:name.toUpperCaseは関数ではありません

IN ADD SUBSCRIBER 
err with mailchimp request [TypeError: name.toUpperCase is not a function] 

答えて

0

CODE

const addSubscriber = function addSubscriber(user) { 
    console.log('IN ADD SUBSCRIBER'); 
    return axios({ 
    method: 'post', 
    url: `https://${mailchimpDC}.api.mailchimp.com/3.0/lists/${mailchimpListId}/members`, 
    data: { 
     email_address: user.email, 
     status: "subscribed", 
     merge_fields: { 
      FNAME: user.name.firstName, 
      LNAME: user.name.lastName, 
      ID: user._id, 
     }, 
    }, 
    headers: `Authorization: apikey ${mailchimpAPIKey}`, 
    }) 
    .then(res => { 
    console.log('res', res); 
    }) 
    .catch((err) => { 
    console.log('err', err); 
    }) 
}; 

OUTPUTは、最後にそれを考え出しました。承認ヘッダーの形式が正しくありませんでした。承認はヘッダーオブジェクトの下のキーである必要があります。私はContent-Typeも追加しました。今はすべてが動作します!

const addSubscriber = function addSubscriber(user) { 
    console.log('IN ADD SUBSCRIBER'); 
    return axios({ 
    method: 'post', 
    url: `https://${mailchimpDC}.api.mailchimp.com/3.0/lists/${mailchimpListId}/members`, 
    data: { 
     email_address: user.email, 
     status: "subscribed", 
     merge_fields: { 
      FNAME: user.name.firstName, 
      LNAME: user.name.lastName, 
      ID: user._id, 
     }, 
    }, 
    headers: { 
     'Content-Type': 'application/json', 
     Authorization: `apikey ${mailchimpAPIKey}`, 
    }, 
    }) 
    .then(res => { 
    console.log('res', res); 
    }) 
    .catch((err) => { 
    console.log('err with mailchimp request', err); 
    }) 
}; 
関連する問題