Last active
November 17, 2015 08:53
-
-
Save waleedsamy/d074b459591de5155af8 to your computer and use it in GitHub Desktop.
post data with request.js
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"); | |
| /** | |
| curl https://{subdomain}.zendesk.com/api/v2/tickets.json \ | |
| -d '{"ticket": {"subject": "My printer is on fire!", "comment": { "body": "The smoke is very colorful." }}}' \ | |
| -H "Content-Type: application/json" -v -u {email_address}:{password} -X POST | |
| */ | |
| var options = { | |
| url: "https://{subdomain}.zendesk.com/api/v2/tickets.json", | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json" | |
| }, | |
| auth: { | |
| user: "{email}/token", | |
| pass: "{token}" | |
| }, | |
| json: true, | |
| body: { | |
| "ticket": { | |
| "subject": "subject", | |
| "description": "description", | |
| "custom_fields": [{ | |
| "id": 28446177, | |
| "value": 'AAAA' | |
| }, { | |
| id: 28937178, | |
| "value": "category2" | |
| }] | |
| } | |
| } | |
| }; | |
| request(options, function(error, response, body) { | |
| if (error) { | |
| console.log(error); | |
| } else { | |
| console.log(body); | |
| } | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if request.js
options.jsonis not true or not exist, will throw execption, another way tp pass this is to stringify your body withJSON.stringify