Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
Last active November 17, 2015 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waleedsamy/d074b459591de5155af8 to your computer and use it in GitHub Desktop.
Save waleedsamy/d074b459591de5155af8 to your computer and use it in GitHub Desktop.
post data with request.js
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);
}
});
@waleedsamy
Copy link
Author

if request.js options.json is not true or not exist, will throw execption, another way tp pass this is to stringify your body with JSON.stringify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment