documentation here使用curl
在所有示例中对其进行身份验证。各种语言也有some examples here。但是,我正在尝试将API与polymer的iron-ajax
元素一起使用,但我无法通过身份验证。
我尝试将它从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)
。我该怎么认证?
答案 0 :(得分:1)
我必须将参数移到标题中,将with-credentials
设置为true并强制method
为&#34; GET&#34;。它现在有效:
<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>