Created
June 7, 2016 21:49
-
-
Save dpawluk/0749185619f13b4126a4536d1b9bdf06 to your computer and use it in GitHub Desktop.
Very basic usage of node.js and Requests package to create_many tickets in zendesk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var request = require('request'); | |
| var util = require('util'); | |
| var config = { | |
| 'username': '[email protected]/token', // email if using password, email/token if token | |
| 'token':'AVERYSECRETAPIKEY', // password or token, see above | |
| 'subdomain': 'my_subdomain' // replace with Zendesk subdomain | |
| }; | |
| function printDone(error, response, body) { // Wrote this to be callback for testing requests | |
| console.log(error); | |
| console.log(response); | |
| console.log(body); | |
| }; | |
| "tickets": [ | |
| { | |
| var payload = { // Create fake payload, tickets array | |
| "subject": "My printer is on fire!", | |
| "comment": { "body": "The smoke is very colorful." }, | |
| "priority": "normal" | |
| }, | |
| { | |
| "subject": "Help", | |
| "comment": { "body": "This is a comment" }, | |
| "priority": "normal" | |
| } | |
| ] | |
| }; | |
| console.log(JSON.stringify(payload)); | |
| request.post({ | |
| url: util.format("https://%s.zendesk.com/api/v2/tickets/create_many.json", config.subdomain), | |
| headers:{'Content-Type':'application/json'}, | |
| body: JSON.stringify(payload) | |
| }, | |
| printDone | |
| ).auth(config.username, config.token); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment