{"id":36503376,"url":"https://github.com/pkellz/node-snapchat-marketing","last_synced_at":"2026-01-12T02:26:35.524Z","repository":{"id":34978892,"uuid":"193715196","full_name":"pkellz/node-snapchat-marketing","owner":"pkellz","description":":ghost: unoffical Node wrapper for the Snapchat marketing API","archived":false,"fork":false,"pushed_at":"2023-01-04T04:26:19.000Z","size":724,"stargazers_count":11,"open_issues_count":17,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-29T11:38:58.401Z","etag":null,"topics":["nodejs","nodejs-client","snapchat","snapchat-api","snapchat-marketing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkellz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-25T13:40:36.000Z","updated_at":"2024-01-09T22:21:06.000Z","dependencies_parsed_at":"2023-01-15T11:22:27.308Z","dependency_job_id":null,"html_url":"https://github.com/pkellz/node-snapchat-marketing","commit_stats":null,"previous_names":["pkellz/node-snap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pkellz/node-snapchat-marketing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkellz%2Fnode-snapchat-marketing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkellz%2Fnode-snapchat-marketing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkellz%2Fnode-snapchat-marketing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkellz%2Fnode-snapchat-marketing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkellz","download_url":"https://codeload.github.com/pkellz/node-snapchat-marketing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkellz%2Fnode-snapchat-marketing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28332428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","nodejs-client","snapchat","snapchat-api","snapchat-marketing"],"created_at":"2026-01-12T02:26:35.433Z","updated_at":"2026-01-12T02:26:35.505Z","avatar_url":"https://github.com/pkellz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snapchat Marketing Node.js Wrapper\n:ghost: Unoffical Node library for the Snapchat Marketing API\n\n### Looking for more contributors!\n[Snapchat Marketing API Documentation](https://developers.snapchat.com/api/docs/)\n\n## :wrench: Installation\n\nBefore you begin, you need to apply for access to the [Snapchat Marketing API](https://developers.snapchat.com/apply/). Once you are approved, you will be able to register a new application in the 'Business Details' section of your [Snapchat Business Account](https://business.snapchat.com/). Notice that the app gets a client ID, secret, and redirect URI required for authenticating with the API.\n\nIf you reach an error page when trying to access your Business Account, try disabling any ad-blockers you might have.\n\nAfter registering your application, you need to install this module in your Node.js project:\n\n```sh\nnpm install node-snapchat-marketing\n```\n\n## :arrow_forward: Initialization\n\nIn order to use this module, you have to import it in your application first:\n\n```javascript\nconst Snap = require('node-snapchat-marketing');\n```\n\nNext, initialize the Snap object with the keys you obtained from the [Snapchat business dashboard](https://business.snapchat.com/):\n\n```javascript\nconst snap = new Snap({\n  client_id: '\u003cCLIENT_ID\u003e',\n  client_secret: '\u003cCLIENT_SECRET\u003e',\n  redirect_uri: '\u003cREDIRECT_URI\u003e',\n});\n```\n\n## :key: Authenticating\n\nTo make HTTP calls, you need to create an authenticated session with the API.\n\n### Step One: Authorize\n\nTo obtain an OAuth token, you have to authorize your application with the required scope. The only scope currently available is 'snapchat-marketing-api'.\n\nYou are initially required to redirect your user to an authorization URL. You can generate the authorization URL using `snap.getAuthorizeUrl`. In case you are using [Express](http://expressjs.com/), your route definition could look as follows:\n\n```javascript\napp.get('/snap/authorize', function(req, res) {\n  var url = snap.getAuthorizeUrl('snapchat-marketing-api');\n  res.redirect(url);\n});\n```\n\nThe URL will lead to a page where your user will be required to login and approve access to his/her Snapchat account. In case that step was successful, Snap will issue a redirect to the `redirect_uri` defined in your [Snapchat business account](https://business.snapchat.com). On that redirect, you will receive a single-use authorization code via a `code` query parameter in the url.\n\n### Step Two: Receive redirect and get an access token\n\nTo complete the authorization you now need to receive the callback and convert the given authorization code into an OAuth access token. You can accomplish that using `snap.authorization`. This method will retrieve and store the access_token, refresh_token, and token expiration date inside the Snap object. Access tokens expire after 1800 seconds (30 minutes).\n\n\nIn Express - If your `redirect_uri` is https://example.com/snap/callback, your route could look like:\n\n```javascript\napp.get('/snap/callback', (req,res)=\u003e{\n  snap.authorization({ authorization_code: req.query.code }, function(err, token){\n    console.log(\"Access token is: \" + token.access_token);\n    console.log(\"Refresh token is: \" + token.refresh_token);\n    console.log(\"Access token expires in: \" + token.expires_in + \" seconds\");\n    res.redirect('/');\n  });\n});\n```\n\n##### At this point the access token, refresh token, and token expiration are saved in the `snap` instance.\n##### You can also set a refresh token globally to avoid re-requesting credentials when you reset your server.\n```javascript\nsnap.setRefreshToken('\u003ctoken\u003e');\n```\n\n### Step Three: Make HTTP requests to available resources\n\nNow that you are authenticated, you can issue requests using the provided library methods.\n\nFor instance, to obtain a list of all available organizations associated with your account, you can use `snap.organization.getAll`.\n\n```javascript\nsnap.organization.getAll(function(err, orgs)\n{\n  if(err)\n    console.log(err);\n  else\n    console.log(orgs);\n});\n```\n## :books: Library Methods\n\n### Authorization\n\n#### Generate Authorize URL\n\nAfter getting the authorize url, the user will be redirected to the redirect url with authorization code used in the next function.\n\n```javascript\nsnap.getAuthorizeUrl(scope);\n```\n\n##### Parameter\n\n- Currently, the only available scope is 'snapchat-marketing-api'.\n\n##### Example\n\n```javascript\napp.get('/snap/authorize', function(req, res) {\n  var url = snap.getAuthorizeUrl('snapchat-marketing-api');\n  res.redirect(url);\n});\n```\n\n#### Retrieve and store a new access token\n\n```javascript\nsnap.authorization(options, callback);\n```\n\n##### Parameter\n\n- options (object) - Object with attribute authorization_code\n- Available options - 'authorization_code': string\n\n##### Example\n\n```javascript\napp.get('/snap/callback', (req,res)=\u003e{\n  snap.authorization({ authorization_code : req.query.code }, function(err, token){\n    console.log(\"Access token is: \" + accessToken.access_token);\n    console.log(\"Refresh token is: \" + accessToken.access_token);\n    console.log(\"Access token expires in: \" + accessToken.expires_in + \" seconds\");\n    res.redirect('/');\n  });\n});\n```\n\n\n### Me\n\n#### [Get authenticated user](https://developers.snapchat.com/api/docs/#user)\n\n```javascript\nsnap.me(callback);\n```\n\n##### Example\n\n```javascript\nsnap.me(function(err, user){\n  if(err)\n    console.log(err);\n  else\n    console.log(user);\n})\n```\n\n### Organization\n#### [Get all organizations](https://developers.snapchat.com/api/docs/#get-all-organizations)\n\n```javascript\nsnap.organization.getAll(options, callback);\n```\n\n##### Parameter\n\n- options (object)\n- Available options - 'withAdAccounts': boolean\n\n##### Example\n\n```javascript\nsnap.organization.getAll({ withAdAccounts: true }, function(err, orgs){\n  if(err)\n    console.log(err);\n  else\n    console.log(orgs);\n});\n```\n\n#### [Get organization by id](https://developers.snapchat.com/api/docs/#get-a-specific-organization)\n\n```javascript\nsnap.organization.getById(id, callback);\n```\n\n##### Example\n\n```javascript\nsnap.organization.getById('\u003corganization_id\u003e', function(err, org){\n  if(err)\n    console.log(err);\n   else\n    console.log(org);\n});\n```\n\n### Media\n\n#### [Create a new Media](https://developers.snapchat.com/api/docs/#create-media)\n\n```javascript\nsnap.media.createMedia(media, callback);\n```\n\n##### Parameter\n\n- media (object) - JS object with options describing type of media to create\n\n##### Example\n\n```javascript\nconst newMedia = {\n    media: [\n      { name:\"Some new media\", type:\"VIDEO\", ad_account_id: myAdAccountId },\n    ]\n  }\n\nsnap.media.createMedia(newMedia, function(err, res){\n  if(err)\n    console.log(err);\n});\n```\n\n##### ad_account_id - your Snapchat business account id. Can be found on your [Snapchat Business Account](https://business.snapchat.com/)\n\n#### [Get all Media associated with the authenticated account](https://developers.snapchat.com/api/docs/#get-all-media)\n\n```javascript\nsnap.media.getAll(adAccountId, callback);\n```\n\n##### Parameter\n\n- adAccountId - your Snapchat business account id. Can be found on your [Snapchat Business Account](https://business.snapchat.com/)\n\n##### Example\n\n```javascript\nsnap.media.getAll(adAccountId, function(err,media)\n  {\n    if(err)\n      console.log(err);\n    else\n      console.log(media);\n  })\n```\n\n## :bar_chart: Testing\nBefore you try to run any tests, you MUST go to `test/credentials/keys.js` and fill in your app credentials.\n\n```javascript\nmodule.exports = {\n  CLIENT_ID: '\u003cyour_client_id\u003e',\n  CLIENT_SECRET: '\u003cyour_client_secret\u003e',\n  REDIRECT_URI: '\u003cyour_redirect_uri\u003e',\n  REFRESH_TOKEN:'\u003cyour_refresh_token\u003e'\n}\n```\n\nThen, you can execute tests using:\n```javascript\nnpm run test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkellz%2Fnode-snapchat-marketing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkellz%2Fnode-snapchat-marketing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkellz%2Fnode-snapchat-marketing/lists"}