2016-06-14 10 views
1

documentation hereにはcurlを使用してすべての例で認証されています。さまざまな言語用のsome examples hereもあります。ただし、iron-ajax要素でAPIを使用しようとしていますが、認証に問題があります。iron-ajaxを使用してfreshDeskにAPIトークンを使用して認証する

nodejsサンプルをベースにしてparamsに含めようとしましたが、まだ動作していません。

<template is="dom-bind" id="app"> 
    <iron-ajax auto 
       url="https://<mydomain>.freshdesk.com/api/v2/tickets" 
       params='{ "user": "<myapitoken>", "pass": "X", "sendImmediately": "true" }' 
       handle-as="json" 
       last-response="{{ajaxResponse}}"></iron-ajax> 

    <template is="dom-repeat" items="[[ajaxResponse.items]]"> 
     <mhc-ticket ticket-id="[[item.id]]"></mhc-ticket> 
    </template> 

</template> 

私はちょうど401 (Unauthorized)を取得します。どのように認証する必要がありますか?

答えて

1

パラメータをヘッダーに移動する必要がありました。with-credentialsをtrueに設定し、methodに「GET」を強制してください。今すぐ動作します:

<template is="dom-bind" id="app"> 
    <iron-ajax auto 
       url="https://<mydomain>.freshdesk.com/api/v2/tickets" 
       headers='{ "user": "<myapikey>", "pass": "X", "sendImmediately": "true" }' 
       handle-as="json" 
       method="GET" 
       last-response="{{ajaxResponse}}" 
       with-credentials></iron-ajax> 

    <template is="dom-repeat" items="[[ajaxResponse.items]]"> 
     <mhc-ticket ticket-id="[[item.id]]"></mhc-ticket> 
    </template> 

</template> 
関連する問題