I have the cURL command that works great:
curl https://{{mydomain}}.zendesk.com/api/v2/tickets.json \
-d '{"ticket": {"subject": "Testing!", "type":"problem", "priority":"low", "custom_fields": [{"id": 25227383, "value": "support"}, {"id": 24746086, "value": "customer"}, {"id": 24621686, "value": "product"}, {"id": 24462503, "value": "yes"}], "comment": { "body": "Description" }}}' \
-H "Content-Type: application/json" -v -u {{email}}/token:{{token}} https://obscura.zendesk.com/api/v2/users.json
And I tried to convert it to this in angular 5:
const body = {"ticket":
{"subject": "Testing!",
"type":"problem",
"priority":"low",
"custom_fields":
[{"id": 25227383, "value": "support"},
{"id": 24746086, "value": "customer"},
{"id": 24621686, "value": "product"},
{"id": 24462503, "value": "yes"}],
"comment": { "body": "Description" }}};
this.http.post('https://{{mydomain}}.zendesk.com/api/v2/tickets.json',
{data: body,
headers:{'Content-Type': 'application/json',
'Authorization': 'Bearer {{email}}/token:{{token}}',
'Access-Control-Allow-Origin': '*'}})
.toPromise().then(function(response) {
console.log(response.toString());
})
I'm getting the errors as below:
POST https://{{mydomain}}.zendesk.com/api/v2/tickets.json 401 (Unauthorized)
Failed to load https://{{mydomain}}.zendesk.com/api/v2/tickets.json: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 401.
ERROR Error: Uncaught (in promise): Response with status: 0 for URL: null
at resolvePromise (zone.js:824)
at resolvePromise (zone.js:795)
at eval (zone.js:873)
at ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.js:4620)
at ZoneDelegate.invokeTask (zone.js:424)
at Zone.runTask (zone.js:192)
at drainMicroTaskQueue (zone.js:602)
at ZoneTask.invokeTask [as invoke] (zone.js:503)
at invokeTask (zone.js:1540)
I assume that something is wrong with my authentication.
Does someone have any suggestions?
Thanks