我正在尝试使用 fetch 在 React Native 应用程序上发送匿名 Zendesk 票证:
export const sendZendeskTicket = async (description, email, name) => {
let body = {
"request": {
"requester":
{
"email": email,
"name": name
},
"subject": "some test subject",
"comment":
{
"body": description
}
}
}
console.log(body)
let request = await fetch(`https://*some_domain*.zendesk.com/api/v2/requests`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
let response = await request.json()
console.log(JSON.stringify(response))
return response.ok
}
我的请求正文是:
{"request": {"comment": {"body": "some problem"}, "requester": {"email": "[email protected]", "name": "Testss Userss"}, "subject": "some subject"}}
但我越来越
{"error":"RecordInvalid","description":"Record validation errors","details":{"base":[{"description":"Email: cannot be blank","error":"BlankValue","field_key":360013402611}]}}
我也尝试打电话给
/api/v2/requests.json
,但结果是一样的。
你在邮递员/失眠症上测试过这个请求吗?通过您在此处提供的请求正文,我能够创建票证。我的猜测是 JS 代码存在一些问题,并且在发出请求时电子邮件变量为 null/空白/未定义。