Skip to content

Instantly share code, notes, and snippets.

@paps
Last active September 27, 2017 15:00
Show Gist options
  • Save paps/57d389924f0b15c8b4733b0baefc0ff4 to your computer and use it in GitHub Desktop.
Save paps/57d389924f0b15c8b4733b0baefc0ff4 to your computer and use it in GitHub Desktop.
Simple example of how to launch a Phantombuster agent and get its result with NodeJS. Uses this API endpoint: https://hub.phantombuster.com/reference#launchagent-1
// You'll need to do
// npm install --save request
// npm install --save request-promise-native
// for this module to work
const request = require("request-promise-native")
const generateRequestOptions = (apiKey, agentId, argument) => {
return {
method: "POST",
uri: `https://phantombuster.com/api/v1/agent/${agentId}/launch`,
headers: {
"X-Phantombuster-Key-1": apiKey,
},
json: true,
body: {
output: "first-result-object",
argument: JSON.stringify(argument)
},
}
}
;(async () => {
console.log("Making a request...")
try {
result = await request(generateRequestOptions("XXXX", 123456, { "foo": "bar" }))
console.log(JSON.stringify(result, undefined, "\t"))
} catch (e) {
console.error(`Something went wrong: ${e}`)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment