├── .gitignore ├── CHANGELOG.md ├── README.md ├── config.js ├── index.cjs ├── index.js ├── package.json ├── test.cjs └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | config.json 3 | private.key 4 | package-lock.json 5 | config.js -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.2.6] 2024-12-16 4 | 5 | - Updated to Profile Key for Business Plan. 6 | 7 | ## [1.2.5] 2024-11-27 8 | 9 | - More updates to new API [docs](https://www.ayrshare.com/docs/apis/) 10 | 11 | ## [1.2.4] 2024-11-21 12 | 13 | - Update to new API [docs](https://www.ayrshare.com/docs/apis/) 14 | 15 | ## [1.2.3] 2024-05-03 16 | 17 | - Added new endpoints with examples including resize, verify, webhooks, and more. Please see ReadMe for details. 18 | - Added new test cases. 19 | - Switch endpoint calls from app.ayrshare.com to api.ayrshare.com. 20 | - Moved code to support ES Module, but also still CommonJS. 21 | - Updated packages. 22 | 23 | ### Breaking Changes 24 | 25 | - Renamed the package from `social-post-api` to `social-media-api`. Be sure to update your package require/import. 26 | - Class export changed from `SocialPost` to `SocialMediaAPI`. 27 | 28 | Why the change? Because as Ayrshare has matured we've gone well beyond just posting. 29 | 30 | ## [1.1.1] 2022-11-17 31 | 32 | - Added new functions: `updateProfile`, `unlinkSocial`, `getBrandByUser`. 33 | - Added `history` get all posts. 34 | - Updated code examples and docs. 35 | 36 | No breaking changes. 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Social Media APIs for Posting, Scheduling, and Analytics 2 | 3 | ![Ayrshare logo](https://www.ayrshare.com/wp-content/uploads/2020/08/ayr-logo-2156-reduced.png) 4 | 5 | The Social Media API is a Node.js wrapper SDK for [Ayrshare's APIs](https://www.ayrshare.com). 6 | 7 | Ayrshare is a powerful set of APIs that enable you to send social media posts, get analytics, and add comments to *X/Twitter*, *Instagram*, *Facebook*, *LinkedIn*, *YouTube*, *Google Business Profile*, *Pinterest*, *TikTok*, *Reddit*, and *Telegram* on behalf of your users or clients. 8 | 9 | The Ayrshare Social API handles all the setup and maintenance for the social media networks. One API to rule them all (yeah, went there). See the full list of [full list of features](https://www.ayrshare.com/docs/apis/overview) in our docs. 10 | 11 | Get started with a [free plan](https://www.ayrshare.com/pricing), or if you have a platform or manage multiple users check out the [Business Plan](https://www.ayrshare.com/business-plan-for-multiple-users/). 12 | 13 | For more information on setup, see our installation [video](https://youtu.be/G8M6DZdtcMc) or our [Quick Start Guide](https://www.ayrshare.com/docs/quickstart). 14 | 15 | ## Installation 16 | 17 | `npm i social-media-api` 18 | 19 | ## Setup 20 | 21 | **1.** Create a free [Ayrshare account](https://app.ayrshare.com). 22 | 23 | ![alt Social Accounts Setup](https://www.ayrshare.com/wp-content/uploads/Ayrshare-login.png) 24 | 25 | **2.** Enable your social media accounts such as X/Twitter, Facebook, LinkedIn, Reddit, Instagram, Google Business Profile, Telegram, TikTok, or YouTube in the Ayrshare dashboard. 26 | 27 | ![alt Social Accounts Setup](https://www.ayrshare.com/wp-content/uploads/Ayrshare-social-linking.png) 28 | 29 | **3.** Copy your API Key from the Ayrshare dashboard. Used for authentication. 30 | 31 | ![alt API Key](https://www.ayrshare.com/wp-content/uploads/Ayrshare-API-key.png) 32 | 33 | ## Getting Started 34 | 35 | ### Initialize Social Post API 36 | 37 | Create a new Social Media API object with your API Key. 38 | 39 | ``` javascript 40 | const SocialMediaAPI = require("social-media-api"); // or import SocialMediaAPI from 'social-media-api'; 41 | const social = new SocialMediaAPI('Your API Key'); 42 | ``` 43 | 44 | ### History, Post, Delete Example 45 | 46 | This simple example shows how to post an image or video, get history, and delete the post. This example assumes you have a free API key from [Ayrshare](https://www.ayrshare.com) and have enabled X/Twitter, Facebook Pages, Instagram, LinkedIn. Note, YouTube, Google Business Profile, Telegram, TikTok, and Reddit also available. 47 | 48 | ``` javascript 49 | const SocialMediaAPI = require("social-media-api"); 50 | const API_KEY = "Your API Key"; // get an API Key at ayrshare.com 51 | const social = new SocialMediaAPI(API_KEY); 52 | 53 | const run = async () => { 54 | /** post */ 55 | const post = await social.post({ 56 | post: "Who you gonna call?", 57 | platforms: ["twitter", "facebook", "fbg", "instagram", "linkedin", "gmb"], 58 | mediaUrls: ["https://img.ayrshare.com/012/gb.jpg"] 59 | }).catch(console.error); 60 | console.log(post); 61 | 62 | /** history */ 63 | const history = await social.history() 64 | .catch(console.error); 65 | console.log(history); 66 | 67 | /** delete */ 68 | const deletePost = await social.delete({ id: post.id }) 69 | .catch(console.error); 70 | console.log(deletePost); 71 | }; 72 | 73 | run(); 74 | ``` 75 | 76 | ## Social Media API 77 | 78 | The following section details the different functions of the social media API. 79 | 80 | ### Post 81 | 82 | Published a new post to the specified social networks either immediately or at scheduled future date. Returns a promise that resolves to an object containing the post ID and post status (success, error). See the [post endpoint](https://www.ayrshare.com/docs/apis/post/post) for the full capabilities. 83 | 84 | ``` javascript 85 | const postResponse = await social.post({ 86 | // Required 87 | post: "Best post ever!", 88 | 89 | /** 90 | * Required: Social media platforms to post. 91 | * Accepts an array of strings with values: "facebook", "twitter", "instagram", "linkedin", "youtube", "gmb", "reddit", or "telegram". 92 | * YouTube requires a video and not shown in the example. See https://www.ayrshare.com/docs/apis/post/social-networks/youtube 93 | */ 94 | platforms: ["twitter", "facebook", "fbg", "instagram", "linkedin", "gmb", "telegram"], 95 | 96 | // Optional: URLs of images or videos to include in the post 97 | mediaUrls: ["https://img.ayrshare.com/012/gb.jpg"], 98 | 99 | // Optional: Datetime to schedule a future post. 100 | // Accepts an ISO-8601 UTC date time in format "YYYY-MM-DDThh:mm:ssZ". Example: 2021-07-08T12:30:00Z 101 | scheduleDate: "2020-08-07T15:17:00Z", 102 | 103 | // Optional: Shorten links in the post for all platforms similar to bit.ly. 104 | // Only URLS starting with http or https will be shortened. Default value: true. 105 | shortenLinks: true, 106 | 107 | // Optional for Business Plans, otherwise remove 108 | profileKeys: ["Profile API Key 1"]; 109 | }).catch(console.error); 110 | ``` 111 | 112 | ### Delete 113 | 114 | Delete a post with a given post ID, obtained from the "post" response. Returns a promise with the delete status. Also, can bulk delete multiple IDs at once using the "bulk" key. See the [delete endpoint](https://www.ayrshare.com/docs/apis/post/delete-post) for more details. 115 | 116 | ``` javascript 117 | const deleteResponse = await social.delete({ 118 | id: "POST ID", // optional, but required if "bulk" not present 119 | bulk: ["Post ID 1", "Post ID 2", ...] // optional, but required if "id" not present 120 | }).catch(console.error); 121 | ``` 122 | 123 | ### Get Post 124 | 125 | Get a post with a given post ID, obtained from the "post" response. Returns a promise that resolves to an array containing the post object. See the [get endpoint](https://www.ayrshare.com/docs/apis/post/get-post) for more details. 126 | 127 | ``` javascript 128 | const getResponse = await social.getPost({ id }).catch(console.error); 129 | ``` 130 | 131 | ### Retry Post 132 | 133 | Retry a failed post with a given post ID, obtained from the "post" response. Returns a promise that resolves to an object containing the post status and ID. See the [retry endpoint](https://www.ayrshare.com/docs/apis/post/retry-post) for more details. 134 | 135 | ``` javascript 136 | const retryResponse = await social.retryPost({ id }).catch(console.error); 137 | ``` 138 | 139 | ### History 140 | 141 | Get a history of all posts and their current status in descending order. Returns a promise that resolves to an array of post objects. See the [history endpoint](https://www.ayrshare.com/docs/apis/history/get-history) for more details. 142 | 143 | ``` javascript 144 | const historyResponse = await social.history({ 145 | lastRecords: 10, // optional: returns the last X number of history records 146 | lastDays: 30, // optional: returns the last X number of days of history records. Defaults to 30 if not present. 147 | }).catch(console.error); 148 | ``` 149 | 150 | Get history by post ID. See the [history by ID endpoint](https://www.ayrshare.com/docs/apis/history/get-history-id) for more details. 151 | 152 | ``` javascript 153 | const historyByIdResponse = await social.history({ 154 | id: "pK0j89" // required: Ayrshare top level post ID 155 | }).catch(console.error); 156 | ``` 157 | 158 | Get history by platform. See the [history by platform endpoint](https://www.ayrshare.com/docs/apis/history/history-platform) for more details. 159 | 160 | ``` javascript 161 | const historyAllPostsResponse = await social.history({ 162 | platform: "facebook" 163 | }).catch(console.error); 164 | ``` 165 | 166 | ### Upload Media 167 | 168 | Upload and store a new image. Returns a URL referencing the image. Can be used in "image_url" in "post". See the [media endpoint](https://www.ayrshare.com/docs/apis/media/upload-media) for more details. 169 | 170 | ``` javascript 171 | const uploadResponse = await social.upload({ 172 | // Required: The image as a Base64 encoded string. Example encoding: https://www.base64-image.de/ 173 | file:"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...", 174 | 175 | // Optional 176 | fileName: "test.png", 177 | 178 | // Optional 179 | description: "best image" 180 | }).catch(console.error); 181 | ``` 182 | 183 | ### Get Media 184 | 185 | Get all media URLS. Returns a promise that resolves to an array of URL objects. See the [media endpoint](https://www.ayrshare.com/docs/apis/media/get-media-in-gallery) for more details. 186 | 187 | ``` javascript 188 | const mediaResponse = await social.media().catch(console.error); 189 | ``` 190 | 191 | ### Get Media Upload URL for Large Files 192 | 193 | Get a URL to upload large files. Returns a promise that resolves to an object containing an access URL and an upload URL. See the [media upload url endpoint](https://www.ayrshare.com/docs/apis/media/upload-large-media) for more details. 194 | 195 | ``` javascript 196 | const mediaUploadResponse = await social.mediaUploadUrl({ 197 | fileName: "test.png", // required: The name of the file to upload 198 | contentType: "image/png" // required: The content type of the file 199 | }).catch(console.error); 200 | ``` 201 | 202 | ### Verify Media Exists 203 | 204 | Verify that the media file exists when uploaded. See the [media verify exists endpoint](https://www.ayrshare.com/docs/apis/media/verify-media-url) for more details. 205 | 206 | ``` javascript 207 | const verifyMediaResponse = await social.verifyMediaExists({ 208 | mediaUrl: "https://theImage.jpg" // required: URL of the image to verify exists 209 | }).catch(console.error); 210 | ``` 211 | 212 | ### Resize Image 213 | 214 | Get image resized according to social network requirements. See the [resize image endpoint](https://www.ayrshare.com/docs/apis/media/resize) for more details. 215 | 216 | ``` javascript 217 | const resizeImageResponse = await social.resizeImage({ 218 | imageUrl: "https://theImage.jpg", // required: URL of the image to resize 219 | platform: "facebook" // required: Platform to resize the image for. 220 | watermarkUrl: "https://theWatermark.png", // optional: URL of the watermark image to add to the image. 221 | effects: { color: "#A020F0" } // optional: Change opacity, colors, etc. See endpoint for more details. 222 | dimensions: { width: 1200, height: 628 } // optional: Width and height of the image. Required if platform is not specified. 223 | mode: "blur" // optional. See endpoint for more details. 224 | }).catch(console.error); 225 | ``` 226 | 227 | ### User 228 | 229 | Get data about the logged in user, such as post quota, used quota, active social networks, and created date. See the [user endpoint](https://www.ayrshare.com/docs/apis/user/profile-details) for more details. 230 | 231 | ``` javascript 232 | const user = await social.user().catch(console.error); 233 | ``` 234 | 235 | ### Post Analytics 236 | 237 | Get analytics on shortened links and shares, likes, shares, and impressions for a post or at the accounts level. See the [post analytics endpoint](https://www.ayrshare.com/docs/apis/analytics/post) for more details. 238 | 239 | ``` javascript 240 | const analyticsPost = await social.analyticsPost({ 241 | id: "Post ID", 242 | platforms: ["twitter", "instagram", "facebook", "youtube", "linkedin"] 243 | }).catch(console.error); 244 | ``` 245 | 246 | ### Social Media Analytics 247 | 248 | Get analytics and demographics on a user’s social profile, such as impressions, views, and followers. See the [social analytics endpoint](https://www.ayrshare.com/docs/apis/analytics/social) for more details. 249 | 250 | ``` javascript 251 | const analyticsSocial = await social.analyticsSocial({ 252 | platforms: ["twitter", "instagram", "facebook", "youtube", "pinterest", "tiktok", "reddit", "linkedin"] 253 | }).catch(console.error); 254 | ``` 255 | 256 | ### Post a Comment 257 | 258 | Add a comment to a post. Currently only on Facebook and Instagram. See the [create comment endpoint](https://www.ayrshare.com/docs/apis/comments/post-comment) for more details. 259 | 260 | ``` javascript 261 | const postCommentResponse = await social.postComment({ 262 | id: "Pkdo9sjk2", // required: Post top-level ID. 263 | platforms: ["instagram", "facebook"], // required: List of platforms to add comments. Currently available platforms: ["facebook", "instagram"] 264 | comment: "What a comment" //required: Text of the new comment to add to the post. 265 | }).catch(console.error); 266 | ``` 267 | 268 | ### Get Comments 269 | 270 | Get comments for a post. Currently only on Facebook and Instagram. See the [get comment endpoint](https://www.ayrshare.com/docs/apis/comments/get-comments) for more details. 271 | 272 | ``` javascript 273 | const getCommentResponse = await social.getComments({ 274 | id: "Pkdo9sjk2", // required: Post top-level ID. 275 | }).catch(console.error); 276 | ``` 277 | 278 | ### Delete Comments 279 | 280 | Delete either a single comment or all comments under a post that were sent via Ayrshare. Available for Facebook, Instagram, LinkedIn, Reddit, TikTok, X/Twitter, and YouTube. See the [delete comment endpoint](https://www.ayrshare.com/docs/apis/comments/delete-comments) for more details. 281 | 282 | ``` javascript 283 | const deleteCommentResponse = await social.deleteComments({ 284 | id: "Pkdo9sjk2", // required: Post top-level ID or social comment ID 285 | platforms: ["instagram", "facebook"], // optional: Required only if using the social comment id. 286 | }).catch(console.error); 287 | ``` 288 | 289 | ### Reply Comment 290 | 291 | Reply to a comment. Available for Facebook, Instagram, LinkedIn, TikTok, X/Twitter, and YouTube. See the [reply comment endpoint](https://www.ayrshare.com/docs/apis/comments/reply-to-comment) for more details. 292 | 293 | ``` javascript 294 | const replyCommentResponse = await social.replyComment({ 295 | commentId: "Pkdo9sjk2", // required: The Ayrshare commentId returned from the POST comment endpoint. Be sure to use the top level commentId. 296 | platforms: ["instagram", "facebook"], // required: Array of platforms to post the reply. Values: facebook, instagram, linkedin, tiktok, twitter, youtube 297 | comment: "What a comment" // required: The reply to add to the comment. 298 | }).catch(console.error); 299 | ``` 300 | 301 | ### Set, Delete, and List Auto Schedule 302 | 303 | Auto scheduling allows you to create and manage pre-defined posting schedules. See the [auto-schedule endpoints](https://www.ayrshare.com/docs/apis/auto-schedule/overview) for more details. 304 | 305 | ``` javascript 306 | const setAutoSchedule = await social.setAutoSchedule({ 307 | schedule: ["13:05Z", "20:14Z"], // required 308 | title: "Instagram Schedule" // optional 309 | }).catch(console.error); 310 | ``` 311 | 312 | ``` javascript 313 | const deleteAutoSchedule = await social.deleteAutoSchedule({ 314 | title: "Instagram Schedule" // optional, else default is used 315 | }).catch(console.error); 316 | ``` 317 | 318 | ``` javascript 319 | const listAutoSchedule = await social.listAutoSchedule().catch(console.error); 320 | ``` 321 | 322 | ### Add an RSS or Substack Feed 323 | 324 | Add a new RSS or Substack feed to auto post all new articles. Returns a promise that resolved to an object containing the feed ID. See [How to Automate Your Blog or Newsletter](https://www.ayrshare.com/how-to-automatically-post-your-blog-or-newsletter-to-social-media/) for more info. 325 | 326 | ``` javascript 327 | const feedResponse = await social.feedAdd({ 328 | url: "https://theRSSFeed", // required: URL to shorten 329 | 330 | // Optional: Value: "rss" or "substack". 331 | // If not set, defaults to "rss" 332 | type: "RSS", 333 | }).catch(console.error); 334 | ``` 335 | 336 | ### Delete an RSS or Substack Feed 337 | 338 | Delete an RSS feed for a given ID. See the [delete feed endpoint](https://www.ayrshare.com/docs/apis/feeds/delete-feed) for more details. 339 | 340 | ``` javascript 341 | const feedResponse = await social.feedDelete({ 342 | id: "Feed ID", // required: ID of the feed 343 | }).catch(console.error); 344 | ``` 345 | 346 | ### Get Feeds 347 | 348 | Get all registered RSS feeds. Returns a promise that resolves to an array of feed objects. See the [get feeds endpoint](https://www.ayrshare.com/docs/apis/feeds/get-feeds) for more details. 349 | 350 | ``` javascript 351 | const feedsResponse = await social.feedGet().catch(console.error); 352 | ``` 353 | 354 | ### Update Feed 355 | 356 | Update an RSS feed for a given ID. Returns a promise that resolves to an object containing the feed ID. See the [update feed endpoint](https://www.ayrshare.com/docs/apis/feeds/update-feed) for more details. 357 | 358 | ``` javascript 359 | const feedResponse = await social.feedUpdate({ 360 | id: "Feed ID", // required: ID of the feed 361 | useFirstImage: true, // optional: Use the first image in the article to add to the post. 362 | autoHashtag: true, // optional: Automatically add hashtags to the post. 363 | }).catch(console.error); 364 | ``` 365 | 366 | ## Business Functions for Multiple Users - Business or Enterprise Plan Required 367 | 368 | The [Business Plan](https://www.ayrshare.com/business-plan-for-multiple-users/) allows you to create, manage, and post on behalf of client profiles via the API or Dashboard GUI. You can [integrate](https://www.ayrshare.com/docs/multiple-users/business-plan-overview) Ayrshare into your platform, product, or agency and give your clients social media capabilites. Please [contact us](mailto:contact@ayrshare.com) with any questions. 369 | 370 | A User Profile PROFILE_KEY can be set with the `setProfileKey` function. 371 | 372 | ``` javascript 373 | const social = new SocialMediaAPI(API_KEY); 374 | social.setProfileKey(PROFILE_KEY); 375 | ``` 376 | 377 | Replace PROFILE_KEY with the Profile Key of the user you want to use. 378 | 379 | Please see the [Authorization](https://www.ayrshare.com/docs/apis/overview#authorization) docs for more details. 380 | 381 | ### Create Profile 382 | 383 | Create a new account profile under the primary account. See the [create profile endpoint](https://www.ayrshare.com/docs/apis/profiles/create-profile) for more details. 384 | 385 | ``` javascript 386 | const createProfileResponse = await social.createProfile({ 387 | // Required: title 388 | title: "New Profile Title", 389 | }).catch(console.error); 390 | ``` 391 | 392 | ### Delete Profile 393 | 394 | Delete a profile owned by the primary account. See the [delete profile endpoint](https://www.ayrshare.com/docs/apis/profiles/delete-profile) for more details. 395 | 396 | ``` javascript 397 | const deleteProfileResponse = await social.deleteProfile({ 398 | // Required: profileKey - the API Key of the profile to delete 399 | profileKey: "JI9s-kJII-9283-OMKM", 400 | }).catch(console.error); 401 | ``` 402 | 403 | ### Update Profile 404 | 405 | Update a profile owned by the primary account. See the [update profile endpoint](https://www.ayrshare.com/docs/apis/profiles/update-profile) for more details. 406 | 407 | ``` javascript 408 | const updateProfileResponse = await social.updateProfile({ 409 | // Required: profileKey - the API Key of the profile to update 410 | profileKey: "JI9s-kJII-9283-OMKM", 411 | title: "This is a greate new title" 412 | }).catch(console.error); 413 | ``` 414 | 415 | ### Get Profiles 416 | 417 | Get all the profiles associated with the primary account. See the [get profile endpoint](https://www.ayrshare.com/docs/apis/profiles/get-profiles) for more details. 418 | 419 | ``` javascript 420 | const getProfileResponse = await social.getProfiles().catch(console.error); 421 | ``` 422 | 423 | ### Unlink Social Network 424 | 425 | Unlink a social account for a given user profile owned by the primary account. See the [unlink social network endpoint](https://www.ayrshare.com/docs/apis/profiles/unlink-social-network) for more details. 426 | 427 | ``` javascript 428 | const unlinkResponse = await social.unlinkSocial({ 429 | // Required: profileKey - the API Key of the profile to delete 430 | profileKey: "JI9s-kJII-9283-OMKM", 431 | platform: "facebook" 432 | }).catch(console.error); 433 | ``` 434 | 435 | ### Generate a JWT Url 436 | 437 | Generate a JWT Token and URL used for authorizing a user's access to the Social Account linking page. See the [generate JWT endpoint](https://www.ayrshare.com/docs/apis/profiles/generate-jwt) for more details. 438 | 439 | ``` javascript 440 | const generateJWTResponse = await social.generateJWT({ 441 | domain: "ACME", // required 442 | privateKey: "-----BEGIN RSA PRIVATE KEY...", // required 443 | profileKey: "PROFILE_KEY", // required 444 | }).catch(console.error); 445 | ``` 446 | 447 | ### Get Brand Info on a User 448 | 449 | Get brand information on users and companies public social media accounts. See the [brand endpoint](https://www.ayrshare.com/docs/apis/brand/brand-user) for more details. 450 | 451 | ``` javascript 452 | const brandResponse = await social.getBrandByUser({ 453 | platforms: ["instagram", "facebook"], 454 | instagramUser: "@ayrshare", 455 | facebookUser: "ayrshare", 456 | }).catch(console.error); 457 | ``` 458 | 459 | ### Register, Unregister, and List Webhooks 460 | 461 | A webhook allows you to be notified when certain system actions occur via a call to a URL you provide. Register a webhook by providing your URL and the type of action you wish to be notified. When the action occurs a POST message will be sent to the provided URL. See the [webhooks endpoints](https://www.ayrshare.com/docs/apis/webhooks/overview) for more details. 462 | 463 | ``` javascript 464 | const registerWebhook = await social.registerWebhook({ 465 | action: "social", // required: Available actions: "feed", "social". 466 | url: "https://myhook", // required: Your URL to be called on action. URL must be in a valid format and begin with https:// 467 | }).catch(console.error); 468 | ``` 469 | 470 | ``` javascript 471 | const unregisterWebhook = await social.unregisterWebhook({ 472 | action: "social", // required: Available actions: "feed", "social". 473 | }).catch(console.error); 474 | ``` 475 | 476 | ``` javascript 477 | const listWebhooks = await social.listWebhooks().catch(console.error); 478 | ``` 479 | 480 | ### Auto Hashtags 481 | 482 | Automatically add hashtags to your post. See the [auto hashtags endpoint](https://www.ayrshare.com/docs/apis/hashtags/auto-hashtags) for more details. 483 | 484 | ``` javascript 485 | const autoHashtagsResponse = await social.autoHashtags({ 486 | post: "I love social media", // required: Post text to add hashtags for. 487 | position: "auto" // optional: Position of the hashtags. Values: "auto", "end". Default: "auto". 488 | max: 2 // optional: Maximum number of hashtags to add, ranging 1-5. Default: 2. 489 | }).catch(console.error); 490 | ``` 491 | 492 | ### Recommend Hashtags 493 | 494 | Get suggestions for hashtags based on a keyword. See the [recommend hashtags endpoint](https://www.ayrshare.com/docs/apis/hashtags/recommend-hashtags) for more details. 495 | 496 | ``` javascript 497 | const recommendHashtagsResponse = await social.recommendHashtags({ 498 | keyword: "social media", // required: Keyword to get hashtags for. 499 | }).catch(console.error); 500 | ``` 501 | 502 | ### Check Banned Hashtags 503 | 504 | Check if a hashtag is banned on Instagram or other social networks. See the [check banned hashtags endpoint](https://www.ayrshare.com/docs/apis/hashtags/check-hashtags) for more details. 505 | 506 | ``` javascript 507 | const checkBannedHashtagsResponse = await social.checkBannedHashtags({ 508 | hashtag: "socialmedia", // required: Hashtag to check. 509 | }).catch(console.error); 510 | ``` 511 | 512 | ### Get All Reviews 513 | 514 | Retrieve all the reviews for the specified platform. See the [get all reviews endpoint](https://www.ayrshare.com/docs/apis/reviews/get-reviews) for more details. 515 | 516 | ``` javascript 517 | const allReviewsResponse = await social.reviews({ 518 | platform: "facebook", // required: Platform to get reviews for. Currently available: "facebook", "gmb" 519 | }).catch(console.error); 520 | ``` 521 | 522 | ### Get Single Review 523 | 524 | Retrieve a single review. See the [get single review endpoint](https://www.ayrshare.com/docs/apis/reviews/get-one-review) for more details. 525 | 526 | ``` javascript 527 | const singleReviewResponse = await social.review({ 528 | id: "Review ID", // required 529 | platform: "gmb", // required: Platform to get review for. Currently available: "gmb" 530 | }).catch(console.error); 531 | ``` 532 | 533 | ### Reply to Review 534 | 535 | Reply to a review. See the [reply to review endpoint](https://www.ayrshare.com/docs/apis/reviews/reply-review) for more details. 536 | 537 | ``` javascript 538 | const replyReviewResponse = await social.replyReview({ 539 | reviewId: "Review ID", // required: Review ID to reply to. 540 | platform: "facebook", // required: Platform to reply to review for. Currently available: "facebook", "gmb" 541 | reply: "Thank you for the review" // required: Text of the reply to the review. 542 | }).catch(console.error); 543 | ``` 544 | 545 | ### Delete Review Reply 546 | 547 | Delete a review reply. See the [delete review reply endpoint](https://www.ayrshare.com/docs/apis/reviews/delete-review-reply) for more details. 548 | 549 | ``` javascript 550 | const deleteReplyReviewResponse = await social.deleteReplyReview({ 551 | reviewId: "Review ID", // required: Review ID to delete reply for. 552 | platform: "gmb", // required: Platform to delete reply for. Currently available: "gmb" 553 | }).catch(console.error); 554 | ``` 555 | 556 | ## Max Pack Required 557 | 558 | ### Generate Post 559 | 560 | Generate a new social post using ChatGPT. Token limits applicable. See the [generate post endpoint](https://www.ayrshare.com/docs/apis/generate/post-text) for more details. 561 | 562 | ``` javascript 563 | const generatePostResponse = await social.generatePost({ 564 | text: "I love social media", // required: Description of what the post should be about. 565 | hashtags: true, //optional: Include hashtags in the post. Default: true 566 | emojis: true, // optional: Include emojis in the post. Default: false 567 | twitter: true, // optional: Construct a post 280 or few characters. Default: false 568 | }).catch(console.error); 569 | ``` 570 | 571 | ### Generate Rewrite 572 | 573 | Generate variations of a social media post using ChatGPT. Token limits applicable. See the [generate rewrite endpoint](https://www.ayrshare.com/docs/apis/generate/rewrite-post) for more details. 574 | 575 | ``` javascript 576 | const generateRewriteResponse = await social.generateRewrite({ 577 | post: "I love social media", // required: The post text to be rewritten. 578 | emojis: true, // optional: Include emojis in the post. Default: false 579 | hashtags: true, // optional: Include hashtags in the post. Default: false 580 | twitter: true, // optional: Construct a post 280 or few characters. Default: false 581 | rewrites: 5, // optional: Number of rewrites to generate. Default: 5 582 | }).catch(console.error); 583 | ``` 584 | 585 | ### Generate Transcription 586 | 587 | Provide a transcription of a video file. See the [generate transcription endpoint](https://www.ayrshare.com/docs/apis/generate/transcribe-video) for more details. 588 | 589 | ``` javascript 590 | const generateTranscriptionResponse = await social.generateTranscription({ 591 | videoUrl: "https://theVideo.mp4", // required: URL encoded video URL. The video must be hosted by Ayrshare. 592 | }).catch(console.error); 593 | ``` 594 | 595 | ### Generate Translation 596 | 597 | Translate text for a post to over 100 different languages. See the [generate translation endpoint](https://www.ayrshare.com/docs/apis/generate/translate-post) for more details. 598 | 599 | ``` javascript 600 | const generateTranslationResponse = await social.generateTranslation({ 601 | text: "I love social media", // required: The text to be translated. 602 | lang: "es", // required: The language code to translate the text to. 603 | }).catch(console.error); 604 | ``` 605 | 606 | ### Generate Alt Text 607 | 608 | Create AI-generated alt text for your images. See the [generate alt text endpoint](https://www.ayrshare.com/docs/apis/generate/image-alt-text) for more details. 609 | 610 | ``` javascript 611 | const generateAltTextResponse = await social.generateAltText({ 612 | url: "https://theImage.jpg", // required: URL of the image to generate alt text for. 613 | keywords: ["social media", "ayrshare"], // optional: Keywords to help the AI generate better alt text. 614 | lang: "en" // optional: The language code to generate the alt text in. Default: "en" 615 | }).catch(console.error); 616 | ``` 617 | 618 | ### Shorten link 619 | 620 | Provide a URL and a shortened link will be returned. See the [shorten link endpoint](https://www.ayrshare.com/docs/apis/links/create-short-link) for more details. 621 | 622 | ``` javascript 623 | const shortenLinkResponse = await social.shortLink({ 624 | url: "https://theURL.com", // required: URL to shorten. 625 | utmId: "1234", // optional: UTM ID to track the link. See more details about utm parameters at endpoint link above. 626 | utmSource: "source", // optional 627 | utmMedium: "medium", // optional 628 | utmCampaign: "campaign", // optional 629 | utmTerm: "term", // optional 630 | utmContent: "content", // optional 631 | }).catch(console.error); 632 | ``` 633 | 634 | ### Analytics for Shortened Links 635 | 636 | Return analytics for all shortened links or a single link for a given link ID. See the [analytics link endpoint](https://www.ayrshare.com/docs/apis/links/link-analytics) for more details. 637 | 638 | ``` javascript 639 | const analyticsLinkResponse = await social.shortLinkAnalytics({ 640 | id: "Link ID", // optional: Link ID to get analytics for. 641 | fromCreatedDate: "2023-07-08T12:30:00Z", // optional: Get history of links shortened after this date. 642 | toCreatedDate: "2023-07-08T12:30:00Z", // optional: Get history of links shortened before this date. 643 | fromClickDate: "2023-07-08T12:30:00Z", // optional: Get history of links clicked after this date. 644 | toClickDate: "2023-07-08T12:30:00Z", // optional: Get history of links clicked before this date. 645 | }).catch(console.error); 646 | ``` 647 | 648 | ## Other Packages & Integrations 649 | 650 | We have other package and integrations such as [Python](https://www.ayrshare.com/docs/packages-guides/python), [Bubble.io](https://www.ayrshare.com/docs/packages-guides/bubble), and [Airtable](https://www.ayrshare.com/docs/packages-guides/airtable) + examples in PHP and Go. 651 | 652 | ## Additional Information and Support 653 | 654 | Additional examples, responses, etc. can be found at: 655 | 656 | [RESTful API Endpoint Docs](https://www.ayrshare.com/docs/apis/overview) 657 | 658 | See our [changelog](https://www.ayrshare.com/docs/whatsnew/latest) for the latest and greatest. 659 | 660 | Please [contact us](mailto:support@ayrshare.com) with your questions, or just to give us shout-out 📢! 661 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | API_KEY: "API_KEY", 3 | PROFILE_KEY: "PROFILE_KEY" 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /index.cjs: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var got = require('got'); 4 | 5 | const BASE_URL = "https://api.ayrshare.com/api"; 6 | 7 | const preProcess = (data) => { 8 | data.source = "npm"; 9 | 10 | return data; 11 | }; 12 | 13 | const doPost = (endpoint, data, headers) => { 14 | return got 15 | .post(`${BASE_URL}/${endpoint}`, { 16 | headers, 17 | json: preProcess(data), 18 | responseType: "json" 19 | }) 20 | .then((res) => res.body) 21 | .catch((err) => { 22 | if (err && err.response && err.response.body) { 23 | return err.response.body; 24 | } else { 25 | return err; 26 | } 27 | }); 28 | }; 29 | 30 | const doDelete = (endpoint, data, headers) => { 31 | return got 32 | .delete(`${BASE_URL}/${endpoint}`, { 33 | headers, 34 | json: preProcess(data), 35 | responseType: "json" 36 | }) 37 | .then((res) => res.body) 38 | .catch((err) => { 39 | if (err && err.response && err.response.body) { 40 | return err.response.body; 41 | } else { 42 | return err; 43 | } 44 | }); 45 | }; 46 | 47 | const doPut = (endpoint, data, headers) => { 48 | return got 49 | .put(`${BASE_URL}/${endpoint}`, { 50 | headers, 51 | json: preProcess(data), 52 | responseType: "json" 53 | }) 54 | .then((res) => res.body) 55 | .catch((err) => { 56 | if (err && err.response && err.response.body) { 57 | return err.response.body; 58 | } else { 59 | return err; 60 | } 61 | }); 62 | }; 63 | 64 | const buildParams = (data) => { 65 | const params = new URLSearchParams(); 66 | Object.entries(data).forEach(([key, value]) => { 67 | if (Array.isArray(value)) { 68 | value.forEach((value, i) => params.append(`${key}[${i}]`, value)); 69 | } else { 70 | params.append(key, value); 71 | } 72 | }); 73 | 74 | return params.toString(); 75 | }; 76 | 77 | const doGet = (endpoint, headers, params) => { 78 | const url = `${BASE_URL}/${endpoint}?${ 79 | params ? buildParams(preProcess(params)) : "source=npm" 80 | }`; 81 | 82 | return got 83 | .get(url, { 84 | headers, 85 | responseType: "json" 86 | }) 87 | .then((res) => res.body) 88 | .catch((err) => { 89 | if (err && err.response && err.response.body) { 90 | return err.response.body; 91 | } else { 92 | return err; 93 | } 94 | }); 95 | }; 96 | 97 | class SocialMediaAPI { 98 | constructor(apiKey) { 99 | this.apiKey = apiKey; 100 | this.headers = { 101 | "Content-Type": "application/json", 102 | Authorization: `Bearer ${apiKey}` 103 | }; 104 | } 105 | 106 | post(data) { 107 | return doPost("post", data, this.headers); 108 | } 109 | 110 | delete(data) { 111 | return doDelete("post", data, this.headers); 112 | } 113 | 114 | updatePost(data) { 115 | return doPut("post", data, this.headers); 116 | } 117 | 118 | retryPost(data) { 119 | return doPut("post/retry", data, this.headers); 120 | } 121 | 122 | getPost(data) { 123 | const { id } = data; 124 | return doGet(`post/${id}`, this.headers); 125 | } 126 | 127 | /** 128 | * Handle history, history by id, and get all history 129 | */ 130 | history(params) { 131 | const id = 132 | params && params.id 133 | ? params.id 134 | : params && params.platform 135 | ? params.platform 136 | : null; 137 | 138 | return doGet(`history${id ? `/${id}` : ""}`, this.headers, params); 139 | } 140 | 141 | media(params) { 142 | return doGet("media", this.headers, params); 143 | } 144 | 145 | verifyMediaExists(params) { 146 | return doPost("media/urlExists", params, this.headers); 147 | } 148 | 149 | mediaUploadUrl(params) { 150 | return doGet("media/uploadUrl", this.headers, params); 151 | } 152 | 153 | mediaMeta(params) { 154 | return doGet("media/meta", this.headers, params); 155 | } 156 | 157 | resizeImage(params) { 158 | return doPost("media/resize", params, this.headers); 159 | } 160 | 161 | analyticsLinks(params) { 162 | return doGet("analytics/links", this.headers, params); 163 | } 164 | 165 | analyticsPost(data) { 166 | return doPost("analytics/post", data, this.headers); 167 | } 168 | 169 | // new - DONE 1 170 | analyticsSocial(data) { 171 | return doPost("analytics/social", data, this.headers); 172 | } 173 | 174 | user(params) { 175 | return doGet("user", this.headers, params); 176 | } 177 | 178 | upload(data) { 179 | return doPost("upload", data, this.headers); 180 | } 181 | 182 | shorten(data) { 183 | return doPost("shorten", data, this.headers); 184 | } 185 | 186 | feedAdd(data) { 187 | return doPost("feed", data, this.headers); 188 | } 189 | 190 | feedDelete(data) { 191 | return doDelete("feed", data, this.headers); 192 | } 193 | 194 | feedGet(data) { 195 | return doGet("feed", data, this.headers); 196 | } 197 | 198 | feedUpdate(data) { 199 | return doPut("feed", data, this.headers); 200 | } 201 | 202 | postComment(data) { 203 | return doPost("comments", data, this.headers); 204 | } 205 | 206 | getComments(params) { 207 | const { id } = params; 208 | return doGet(`comments/${id}`, this.headers, params); 209 | } 210 | 211 | deleteComments(params) { 212 | const { id } = params; 213 | return doDelete(`comments/${id}`, params, this.headers); 214 | } 215 | 216 | replyComment(params) { 217 | return doPost(`comments/reply`, params, this.headers); 218 | } 219 | 220 | createProfile(data) { 221 | return doPost("profiles/profile", data, this.headers); 222 | } 223 | 224 | deleteProfile(data) { 225 | return doDelete("profiles/profile", data, this.headers); 226 | } 227 | 228 | updateProfile(data) { 229 | return doPut("profiles/profile", data, this.headers); 230 | } 231 | 232 | getProfiles(params) { 233 | return doGet("profiles", this.headers, params); 234 | } 235 | 236 | generateJWT(data) { 237 | return doPost("profiles/generateJWT", data, this.headers); 238 | } 239 | 240 | unlinkSocial(data) { 241 | return doDelete("profiles/social", data, this.headers); 242 | } 243 | 244 | setAutoSchedule(data) { 245 | return doPost("auto-schedule/set", data, this.headers); 246 | } 247 | 248 | deleteAutoSchedule(data) { 249 | return doDelete("auto-schedule/delete", data, this.headers); 250 | } 251 | 252 | listAutoSchedule(params) { 253 | return doGet("auto-schedule/list", this.headers, params); 254 | } 255 | 256 | registerWebhook(data) { 257 | return doPost("hook/webhook", data, this.headers); 258 | } 259 | 260 | unregisterWebhook(data) { 261 | return doDelete("hook/webhook", data, this.headers); 262 | } 263 | 264 | listWebhooks(params) { 265 | return doGet("hook/webhook", this.headers, params); 266 | } 267 | 268 | getBrandByUser(params) { 269 | return doGet("brand/byUser", this.headers, params); 270 | } 271 | 272 | generatePost(params) { 273 | return doPost("generate/post", params, this.headers); 274 | } 275 | 276 | generateRewrite(params) { 277 | return doPost("generate/rewrite", params, this.headers); 278 | } 279 | 280 | generateTranscription(params) { 281 | return doPost("generate/transcription", params, this.headers); 282 | } 283 | 284 | generateTranslation(params) { 285 | return doPost("generate/translate", params, this.headers); 286 | } 287 | 288 | generateAltText(params) { 289 | return doPost("generate/altText", params, this.headers); 290 | } 291 | 292 | autoHashtags(params) { 293 | return doPost("hashtags/auto", params, this.headers); 294 | } 295 | 296 | recommendHashtags(params) { 297 | return doGet(`hashtags/recommend`, this.headers, params); 298 | } 299 | 300 | checkBannedHashtags(params) { 301 | return doGet("hashtags/banned", this.headers, params); 302 | } 303 | 304 | shortLink(params) { 305 | return doPost("links", params, this.headers); 306 | } 307 | 308 | shortLinkAnalytics(params) { 309 | const { id } = params; 310 | return doGet(`links/${id}`, this.headers, params); 311 | } 312 | 313 | reviews(params) { 314 | return doGet("reviews", this.headers, params); 315 | } 316 | 317 | review(params) { 318 | const { id } = params; 319 | return doGet(`reviews/${id}`, this.headers, params); 320 | } 321 | 322 | replyReview(params) { 323 | return doPost("reviews", params, this.headers); 324 | } 325 | 326 | deleteReplyReview(params) { 327 | return doDelete("reviews", params, this.headers); 328 | } 329 | } 330 | 331 | module.exports = SocialMediaAPI; 332 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import got from "got"; 2 | 3 | const BASE_URL = "https://api.ayrshare.com/api"; 4 | // const BASE_URL = "http://localhost:5001/ayrshare/us-central1/api"; 5 | const ERROR_MSG = { 6 | status: "error", 7 | message: 8 | "Wrong parameters. Please check at https://docs.ayrshare.com/rest-api/endpoints" 9 | }; 10 | 11 | const preProcess = (data) => { 12 | data.source = "npm"; 13 | 14 | return data; 15 | }; 16 | 17 | const doPost = (endpoint, data, headers) => { 18 | return got 19 | .post(`${BASE_URL}/${endpoint}`, { 20 | headers, 21 | json: preProcess(data), 22 | responseType: "json" 23 | }) 24 | .then((res) => res.body) 25 | .catch((err) => { 26 | if (err && err.response && err.response.body) { 27 | return err.response.body; 28 | } else { 29 | return err; 30 | } 31 | }); 32 | }; 33 | 34 | const doDelete = (endpoint, data, headers) => { 35 | return got 36 | .delete(`${BASE_URL}/${endpoint}`, { 37 | headers, 38 | json: preProcess(data), 39 | responseType: "json" 40 | }) 41 | .then((res) => res.body) 42 | .catch((err) => { 43 | if (err && err.response && err.response.body) { 44 | return err.response.body; 45 | } else { 46 | return err; 47 | } 48 | }); 49 | }; 50 | 51 | const doPut = (endpoint, data, headers) => { 52 | return got 53 | .put(`${BASE_URL}/${endpoint}`, { 54 | headers, 55 | json: preProcess(data), 56 | responseType: "json" 57 | }) 58 | .then((res) => res.body) 59 | .catch((err) => { 60 | if (err && err.response && err.response.body) { 61 | return err.response.body; 62 | } else { 63 | return err; 64 | } 65 | }); 66 | }; 67 | 68 | const buildParams = (data) => { 69 | const params = new URLSearchParams(); 70 | Object.entries(data).forEach(([key, value]) => { 71 | if (Array.isArray(value)) { 72 | value.forEach((value, i) => params.append(`${key}[${i}]`, value)); 73 | } else { 74 | params.append(key, value); 75 | } 76 | }); 77 | 78 | return params.toString(); 79 | }; 80 | 81 | const doGet = (endpoint, headers, params) => { 82 | const url = `${BASE_URL}/${endpoint}?${ 83 | params ? buildParams(preProcess(params)) : "source=npm" 84 | }`; 85 | 86 | return got 87 | .get(url, { 88 | headers, 89 | responseType: "json" 90 | }) 91 | .then((res) => res.body) 92 | .catch((err) => { 93 | if (err && err.response && err.response.body) { 94 | return err.response.body; 95 | } else { 96 | return err; 97 | } 98 | }); 99 | }; 100 | 101 | class SocialMediaAPI { 102 | constructor(apiKey) { 103 | this.apiKey = apiKey; 104 | this.profileKey = null; 105 | } 106 | 107 | getHeaders() { 108 | const headers = { 109 | "Content-Type": "application/json", 110 | "Authorization": `Bearer ${this.apiKey}` 111 | }; 112 | 113 | if (this.profileKey) { 114 | headers["Profile-Key"] = this.profileKey; 115 | } 116 | 117 | return headers; 118 | } 119 | 120 | setProfileKey(profileKey) { 121 | this.profileKey = profileKey; 122 | return this; 123 | } 124 | 125 | post(data) { 126 | return doPost("post", data, this.getHeaders()); 127 | } 128 | 129 | delete(data) { 130 | return doDelete("post", data, this.getHeaders()); 131 | } 132 | 133 | updatePost(data) { 134 | return doPut("post", data, this.getHeaders()); 135 | } 136 | 137 | retryPost(data) { 138 | return doPut("post/retry", data, this.getHeaders()); 139 | } 140 | 141 | getPost(data) { 142 | const { id } = data; 143 | return doGet(`post/${id}`, this.getHeaders()); 144 | } 145 | 146 | /** 147 | * Handle history, history by id, and get all history 148 | */ 149 | history(params) { 150 | const id = 151 | params && params.id 152 | ? params.id 153 | : params && params.platform 154 | ? params.platform 155 | : null; 156 | 157 | return doGet(`history${id ? `/${id}` : ""}`, this.getHeaders(), params); 158 | } 159 | 160 | media(params) { 161 | return doGet("media", this.getHeaders(), params); 162 | } 163 | 164 | verifyMediaExists(params) { 165 | return doPost("media/urlExists", params, this.getHeaders()); 166 | } 167 | 168 | mediaUploadUrl(params) { 169 | return doGet("media/uploadUrl", this.getHeaders(), params); 170 | } 171 | 172 | mediaMeta(params) { 173 | return doGet("media/meta", this.getHeaders(), params); 174 | } 175 | 176 | resizeImage(params) { 177 | return doPost("media/resize", params, this.getHeaders()); 178 | } 179 | 180 | analyticsLinks(params) { 181 | return doGet("analytics/links", this.getHeaders(), params); 182 | } 183 | 184 | analyticsPost(data) { 185 | return doPost("analytics/post", data, this.getHeaders()); 186 | } 187 | 188 | // new - DONE 1 189 | analyticsSocial(data) { 190 | return doPost("analytics/social", data, this.getHeaders()); 191 | } 192 | 193 | user(params) { 194 | return doGet("user", this.getHeaders(), params); 195 | } 196 | 197 | upload(data) { 198 | return doPost("upload", data, this.getHeaders()); 199 | } 200 | 201 | shorten(data) { 202 | return doPost("shorten", data, this.getHeaders()); 203 | } 204 | 205 | feedAdd(data) { 206 | return doPost("feed", data, this.getHeaders()); 207 | } 208 | 209 | feedDelete(data) { 210 | return doDelete("feed", data, this.getHeaders()); 211 | } 212 | 213 | feedGet(data) { 214 | return doGet("feed", data, this.getHeaders()); 215 | } 216 | 217 | feedUpdate(data) { 218 | return doPut("feed", data, this.getHeaders()); 219 | } 220 | 221 | postComment(data) { 222 | return doPost("comments", data, this.getHeaders()); 223 | } 224 | 225 | getComments(params) { 226 | const { id } = params; 227 | return doGet(`comments/${id}`, this.getHeaders(), params); 228 | } 229 | 230 | deleteComments(params) { 231 | const { id } = params; 232 | return doDelete(`comments/${id}`, params, this.getHeaders()); 233 | } 234 | 235 | replyComment(params) { 236 | return doPost(`comments/reply`, params, this.getHeaders()); 237 | } 238 | 239 | createProfile(data) { 240 | return doPost("profiles/profile", data, this.getHeaders()); 241 | } 242 | 243 | deleteProfile(data) { 244 | return doDelete("profiles/profile", data, this.getHeaders()); 245 | } 246 | 247 | updateProfile(data) { 248 | return doPut("profiles/profile", data, this.getHeaders()); 249 | } 250 | 251 | getProfiles(params) { 252 | return doGet("profiles", this.getHeaders(), params); 253 | } 254 | 255 | generateJWT(data) { 256 | return doPost("profiles/generateJWT", data, this.getHeaders()); 257 | } 258 | 259 | unlinkSocial(data) { 260 | return doDelete("profiles/social", data, this.getHeaders()); 261 | } 262 | 263 | setAutoSchedule(data) { 264 | return doPost("auto-schedule/set", data, this.getHeaders()); 265 | } 266 | 267 | deleteAutoSchedule(data) { 268 | return doDelete("auto-schedule/delete", data, this.getHeaders()); 269 | } 270 | 271 | listAutoSchedule(params) { 272 | return doGet("auto-schedule/list", this.getHeaders(), params); 273 | } 274 | 275 | registerWebhook(data) { 276 | return doPost("hook/webhook", data, this.getHeaders()); 277 | } 278 | 279 | unregisterWebhook(data) { 280 | return doDelete("hook/webhook", data, this.getHeaders()); 281 | } 282 | 283 | listWebhooks(params) { 284 | return doGet("hook/webhook", this.getHeaders(), params); 285 | } 286 | 287 | getBrandByUser(params) { 288 | return doGet("brand/byUser", this.getHeaders(), params); 289 | } 290 | 291 | generatePost(params) { 292 | return doPost("generate/post", params, this.getHeaders()); 293 | } 294 | 295 | generateRewrite(params) { 296 | return doPost("generate/rewrite", params, this.getHeaders()); 297 | } 298 | 299 | generateTranscription(params) { 300 | return doPost("generate/transcription", params, this.getHeaders()); 301 | } 302 | 303 | generateTranslation(params) { 304 | return doPost("generate/translate", params, this.getHeaders()); 305 | } 306 | 307 | generateAltText(params) { 308 | return doPost("generate/altText", params, this.getHeaders()); 309 | } 310 | 311 | autoHashtags(params) { 312 | return doPost("hashtags/auto", params, this.getHeaders()); 313 | } 314 | 315 | recommendHashtags(params) { 316 | return doGet(`hashtags/recommend`, this.getHeaders(), params); 317 | } 318 | 319 | checkBannedHashtags(params) { 320 | return doGet("hashtags/banned", this.getHeaders(), params); 321 | } 322 | 323 | shortLink(params) { 324 | return doPost("links", params, this.getHeaders()); 325 | } 326 | 327 | shortLinkAnalytics(params) { 328 | const { id } = params; 329 | return doGet(`links/${id}`, this.getHeaders(), params); 330 | } 331 | 332 | reviews(params) { 333 | return doGet("reviews", this.getHeaders(), params); 334 | } 335 | 336 | review(params) { 337 | const { id } = params; 338 | return doGet(`reviews/${id}`, this.getHeaders(), params); 339 | } 340 | 341 | replyReview(params) { 342 | return doPost("reviews", params, this.getHeaders()); 343 | } 344 | 345 | deleteReplyReview(params) { 346 | return doDelete("reviews", params, this.getHeaders()); 347 | } 348 | } 349 | 350 | export default SocialMediaAPI; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "social-media-api", 3 | "version": "1.2.6", 4 | "description": "Social Media API for Instagram, Facebook, LinkedIn, YouTube, X/Twitter, Google Business Profile, Reddit, TikTok, and Telegram. Easily integrate with your platform or app to schedule posts, get analytics, or manage comments on behalf of your users.", 5 | "main": "index.js", 6 | "type": "module", 7 | "exports": { 8 | "import": "./index.js", 9 | "require": "./index.cjs" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/ayrshare/social-media-api" 14 | }, 15 | "keywords": [ 16 | "Ayrshare", 17 | "Social Media", 18 | "Social Networks", 19 | "Social Networking", 20 | "Social Posting", 21 | "Social Media API", 22 | "Social API", 23 | "API Social Post", 24 | "Automation", 25 | "Automate Social Post", 26 | "Facebook API", 27 | "Twitter API", 28 | "X API", 29 | "LinkedIn API", 30 | "Reddit API", 31 | "Google Business Profile API", 32 | "GMB API", 33 | "Telegram API", 34 | "Instagram API", 35 | "YouTube API", 36 | "TikTok API", 37 | "TikTok Posting", 38 | "Instagram", 39 | "Instgram API", 40 | "Schedule Social Media", 41 | "Social Media White Label", 42 | "Social Media Multiple Users", 43 | "Client Social Media", 44 | "Agency Social Media", 45 | "Social Sharing API", 46 | "Facebook Analytics", 47 | "Twitter Analytics", 48 | "LinkedIn Analytics", 49 | "Instagram Analytics", 50 | "Reddit Analytics", 51 | "Google My Business Analytics", 52 | "TikTok Analytics" 53 | ], 54 | "author": "Ayrshare", 55 | "url": "https://www.ayrshare.com", 56 | "license": "MIT", 57 | "bugs": { 58 | "url": "https://github.com/ayrshare/social-media-api/issues" 59 | }, 60 | "bin": { 61 | "social-media-api": "./index.js" 62 | }, 63 | "homepage": "https://www.ayrshare.com", 64 | "dependencies": { 65 | "datauri": "^4.1.0", 66 | "got": "^11.8.6" 67 | }, 68 | "devDependencies": { 69 | "rollup": "^4.17.2" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test.cjs: -------------------------------------------------------------------------------- 1 | // npx rollup index.js --file index.cjs --format cjs 2 | 3 | const SocialMediaAPI = require("./index.cjs"); 4 | /** 5 | * Add your API Key to a config.js file, Profile Key (Business Plan), and Domain (Business Plan) 6 | * { 7 | * "API_KEY": "your api key", 8 | * "PROFIL_KEY": "user profile key", 9 | * "DOMAIN": "Business Plan domain" 10 | * } 11 | */ 12 | const config = require("./config.json"); 13 | const { API_KEY, PROFILE_KEY, DOMAIN } = config; 14 | 15 | const social = new SocialMediaAPI(API_KEY); 16 | 17 | /** Test history */ 18 | const testHistory = async (platform, id) => { 19 | const history = await social.history( 20 | platform ? { platform } : id ? { id } : null 21 | ); 22 | console.log("testHistory:", history); 23 | }; 24 | 25 | /** Test get details on the current user */ 26 | const testUser = async () => { 27 | const user = await social.user(); 28 | console.log("testUser:", user); 29 | }; 30 | 31 | /** Test Add a feed */ 32 | const testFeed = async () => { 33 | const feedAdd = await social.feedAdd({ 34 | type: "substack", 35 | url: "https://bankless.substack.com/" 36 | }); 37 | console.log("testFeed:", feedAdd); 38 | }; 39 | 40 | /** Test Auto Schedule */ 41 | const testAutoSchedule = async () => { 42 | const setAutoSchedule = await social.setAutoSchedule({ 43 | schedule: ["13:05Z", "20:14Z"], 44 | title: "test" 45 | }); 46 | console.log("testAutoSchedule:", setAutoSchedule); 47 | }; 48 | 49 | /** Test delete */ 50 | const testDelete = async (id) => { 51 | const deletePost = await social.delete({ id }); 52 | console.log("testDelete:", deletePost); 53 | }; 54 | 55 | /** Test post 56 | * Uncomment the platforms you want to post to and/or include the random video. 57 | */ 58 | const testPost = async () => { 59 | const post = await social.post({ 60 | randomPost: true, 61 | // platforms: ["twitter", "facebook", "linkedin", "instagram", "tiktok"], 62 | platforms: ["twitter"], 63 | randomMediaUrl: true, 64 | // isLandscapeVideo: true, 65 | shortenLinks: true, 66 | // requiresApproval: true 67 | }); 68 | console.log("testPost: ", post); 69 | 70 | return post.id; 71 | }; 72 | 73 | const testGetPost = async (id) => { 74 | const post = await social.getPost({ id }); 75 | console.log("testGetPost: ", post); 76 | }; 77 | 78 | const testRetryPost = async (id) => { 79 | const post = await social.retryPost({ id }); 80 | console.log("testRetryPost: ", post); 81 | }; 82 | 83 | /** Test Post Update */ 84 | const testPostUpdate = async (id) => { 85 | const post = await social.updatePost({ 86 | id, 87 | approved: true 88 | }); 89 | console.log("test post update: ", post); 90 | 91 | return post.id; 92 | }; 93 | 94 | /** Test Instagram post */ 95 | const testInstagramPost = async () => { 96 | const postInstagram = await social.post({ 97 | randomPost: true, 98 | platforms: ["instagram"], 99 | media_urls: ["https://images.ayrshare.com/imgs/GhostBusters.jpg"], 100 | tagged: ["@ayrshare"], 101 | shorten_links: true 102 | }); 103 | console.log("testInstagramPost:", postInstagram); 104 | }; 105 | 106 | /** Test Upload - Video required*/ 107 | const testVideoPost = async () => { 108 | const datauri = require("datauri"); 109 | const content = await datauri("./test-video.mp4"); 110 | const upload = await social.upload({ 111 | file: content, 112 | fileName: "Test.mp4", 113 | description: "A great test" 114 | }); 115 | console.log("testVideoPost:", upload); 116 | }; 117 | 118 | const testAnalytics = async (id) => { 119 | const analytics = await social.analyticsPost({ 120 | id, 121 | // platforms: ["facebook", "instagram", "twitter", "linkedin"], 122 | platforms: ["facebook"] 123 | }); 124 | return console.log("testAnalytics:", analytics); 125 | }; 126 | 127 | const testAnalyticsSocial = async (platforms) => { 128 | const analytics = await social.analyticsSocial({ 129 | platforms 130 | }); 131 | return console.log("testAnalyticsSocial:", analytics); 132 | }; 133 | 134 | const testGetComments = async (id) => { 135 | const analytics = await social.getComments({ 136 | id 137 | }); 138 | return console.log("testGetComments:", analytics); 139 | }; 140 | 141 | const testListWebhooks = async () => { 142 | const listWebhooks = await social.listWebhooks(); 143 | console.log("testListWebhooks:", listWebhooks); 144 | }; 145 | 146 | const testPostComment = async (id) => { 147 | const analytics = await social.postComment({ 148 | id, 149 | platforms: ["facebook", "instagram"], 150 | comment: "My thoughts exactly" 151 | }); 152 | return console.log("testPostComment:", analytics); 153 | }; 154 | 155 | /** Business Plan Membership - required ---------------- */ 156 | const testCreateProfile = async () => { 157 | const createProfile = await social.createProfile({ 158 | title: "Best Profile Title Ever" 159 | }); 160 | console.log(createProfile); 161 | 162 | return createProfile.profileKey; 163 | }; 164 | 165 | const testDeleteProfile = async (profileKey) => { 166 | const deleteProfile = await social.deleteProfile({ 167 | profileKey: profileKey 168 | }); 169 | console.log("testDeleteProfile:", deleteProfile); 170 | }; 171 | 172 | const testCreateandDelete = async () => { 173 | const profileKey = await testCreateProfile(); 174 | return testDeleteProfile(profileKey); 175 | }; 176 | 177 | const testGenerateJWT = async () => { 178 | const fs = require("fs"); 179 | const privateKey = fs.readFileSync(`./private.key`, "utf8"); 180 | 181 | const jwt = await social.generateJWT({ 182 | domain: DOMAIN, 183 | privateKey, 184 | profileKey: PROFILE_KEY 185 | }); 186 | 187 | return console.log("testGenerateJWT", jwt); 188 | }; 189 | 190 | const testUpdateProfile = async (profileKey) => { 191 | const updateProfile = await social.updateProfile({ 192 | profileKey, 193 | title: "A Nice Title" 194 | }); 195 | console.log("UpdateProfile:", updateProfile); 196 | }; 197 | 198 | const testUnlinkSocial = async (profileKey, platform) => { 199 | const unlinkSocial = await social.unlinkSocial({ profileKey, platform }); 200 | console.log("testUnlinkSocial:", unlinkSocial); 201 | }; 202 | 203 | const testGetBrandByUser = async (platforms, username) => { 204 | const getBrandByUser = await social.getBrandByUser({ 205 | platforms, 206 | instagramUser: username 207 | }); 208 | console.log("testGetBrandByUser:", getBrandByUser); 209 | }; 210 | 211 | const testVerifyMediaExists = async (mediaUrl) => { 212 | const verifyMediaExists = await social.verifyMediaExists({ 213 | mediaUrl 214 | }); 215 | console.log("testVerifyMediaExists:", verifyMediaExists); 216 | }; 217 | 218 | const testMediaMeta = async (url) => { 219 | const mediaMeta = await social.mediaMeta({ 220 | url 221 | }); 222 | console.log("testMediaMeta:", mediaMeta); 223 | }; 224 | 225 | const testMediaUploadUrl = async (fileName, contentType) => { 226 | const mediaMeta = await social.mediaUploadUrl({ 227 | fileName, 228 | contentType 229 | }); 230 | console.log("testMediaUploadUrl:", mediaMeta); 231 | }; 232 | 233 | const testResizeImage = async (imageUrl, platform) => { 234 | const resizeImage = await social.resizeImage({ 235 | imageUrl, 236 | platform 237 | }); 238 | console.log("testResizeImage:", resizeImage); 239 | }; 240 | 241 | const testAutoHashtags = async (post) => { 242 | const autoHashtags = await social.autoHashtags({ 243 | post 244 | }); 245 | console.log("testAutoHashtags:", autoHashtags); 246 | }; 247 | 248 | const testRecommendHashtags = async (keyword) => { 249 | const recommendHashtags = await social.recommendHashtags({ 250 | keyword 251 | }); 252 | console.log("testRecommendHashtags:", recommendHashtags); 253 | }; 254 | 255 | const testCheckBannedHashtags = async (hashtag) => { 256 | const checkBannedHashtags = await social.checkBannedHashtags({ 257 | hashtag 258 | }); 259 | console.log("testCheckBannedHashtags:", checkBannedHashtags); 260 | }; 261 | 262 | const testReviews = async (platform) => { 263 | const reviews = await social.reviews({ platform }); 264 | console.log("testReviews:", reviews); 265 | }; 266 | 267 | const testReview = async (id, platform) => { 268 | const review = await social.review({ 269 | id, 270 | platform 271 | }); 272 | console.log("testReview:", review); 273 | }; 274 | 275 | const testReplyReview = async (reviewId, platform, reply) => { 276 | const replyReview = await social.replyReview({ 277 | reviewId, 278 | platform, 279 | reply 280 | }); 281 | console.log("testReplyReview:", replyReview); 282 | }; 283 | 284 | const testDeleteReplyReview = async (reviewId, platform) => { 285 | const deleteReplyReview = await social.deleteReplyReview({ 286 | reviewId, 287 | platform 288 | }); 289 | console.log("testDeleteReplyReview:", deleteReplyReview); 290 | }; 291 | 292 | const testDeleteComments = async (id) => { 293 | const deleteComment = await social.deleteComments({ 294 | id 295 | }); 296 | console.log("testDeleteComment:", deleteComment); 297 | }; 298 | 299 | const testReplyComment = async (commentId, platforms, comment) => { 300 | const replyComment = await social.replyComment({ 301 | commentId, 302 | platforms, 303 | comment 304 | }); 305 | console.log("testReplyComment:", replyComment); 306 | }; 307 | 308 | /** ------------------------------------------------ */ 309 | 310 | /** Max Pack - required ---------------- */ 311 | const testGeneratePost = async (text) => { 312 | const generatePost = await social.generatePost({ 313 | text 314 | }); 315 | console.log("testGeneratePost:", generatePost); 316 | }; 317 | 318 | const testGenerateRewrite = async (post) => { 319 | const generateRewrite = await social.generateRewrite({ 320 | post 321 | }); 322 | console.log("testGenerateRewrite:", generateRewrite); 323 | }; 324 | 325 | const testGenerateTranscription = async (videoUrl) => { 326 | const generateTranscription = await social.generateTranscription({ 327 | videoUrl 328 | }); 329 | console.log("testGenerateTranscription:", generateTranscription); 330 | }; 331 | 332 | const testGenerateTranslation = async (text, lang) => { 333 | const generateTranslation = await social.generateTranslation({ 334 | text, 335 | lang 336 | }); 337 | console.log("testGenerateTranslation:", generateTranslation); 338 | }; 339 | 340 | const testGenerateAltText = async (url) => { 341 | const generateAltText = await social.generateAltText({ 342 | url 343 | }); 344 | console.log("testGenerateAltText:", generateAltText); 345 | }; 346 | 347 | const testShortLink = async (url) => { 348 | const shortLink = await social.shortLink({ 349 | url 350 | }); 351 | console.log("testShortLink:", shortLink); 352 | }; 353 | 354 | const testShortLinkAnalytics = async (id) => { 355 | const shortLinkAnalytics = await social.shortLinkAnalytics({ 356 | id 357 | }); 358 | console.log("testShortLinkAnalytics:", shortLinkAnalytics); 359 | }; 360 | 361 | /** ------------------------------------------------ */ 362 | 363 | const run = async () => { 364 | const id = await testPost(); 365 | // await testGetPost(id); 366 | // await testRetryPost(id); 367 | // const update = await testPostUpdate(id); 368 | // await testPostComment(id); 369 | // await testAnalytics("lZDx0mCKwpgCHGp9gLy5"); 370 | // await testGetComments(id); 371 | // testDelete(id); 372 | }; 373 | 374 | /* 375 | testHistory(); 376 | testUser(); 377 | testAutoSchedule(); 378 | testFeed(); 379 | testPost(); 380 | testInstagramPost(); 381 | testVideoPost(); 382 | testAnalytics(id); 383 | testComments(); 384 | testListWebhooks(); 385 | testAnalyticsSocial(["facebook"]); 386 | testMediaMeta("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg"); 387 | testDeleteComment("XOVUGutufIy5UZFb01e0"); 388 | testReplyComment( 389 | "Nsa2SWqt32BuY4ooeh7Au", 390 | ["instagram"], 391 | "Thank you for the comment!" 392 | ); 393 | */ 394 | 395 | /** Business Plan */ 396 | /* 397 | testCreateProfile(); 398 | testCreateandDelete(); 399 | testGenerateJWT(); 400 | testUnlinkSocial(PROFILE_KEY, "twitter"); 401 | testGetBrandByUser(["instagram"], "@ayrshare"); 402 | testUpdateProfile(PROFILE_KEY); 403 | testMediaUploadUrl("tree.jpg", "jpeg"); 404 | testVerifyMediaExists( 405 | "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg" 406 | ); 407 | testResizeImage( 408 | "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg", 409 | "facebook" 410 | ); 411 | testAutoHashtags("This is a test post"); 412 | testRecommendHashtags("post"); 413 | testCheckBannedHashtags("instagram"); 414 | testReviews("facebook"); 415 | testReview("10114455408676943", "facebook"); 416 | testReplyReview("10114455408676943", "facebook", "Thank you for the review!"); 417 | testDeleteReview("10114455408676943", "facebook"); 418 | */ 419 | 420 | /* Max Pack */ 421 | /* 422 | testGeneratePost("This is a test post"); 423 | testGenerateRewrite("This is a test post"); 424 | testGenerateTranscription("https://img.ayrshare.com/random/landscape5.mp4"); 425 | testGenerateTranslation("This is a test post", "fr"); 426 | testGenerateAltText("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg"); 427 | testShortLink("https://www.ayrshare.com/"); 428 | testShortLinkAnalytics("qR--d8"); 429 | */ 430 | 431 | run(); 432 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | // npx rollup index.js --file index.cjs --format cjs 2 | 3 | import SocialMediaAPI from "./index.js"; 4 | /** 5 | * Add your API Key to a config.js file, Profile Key (Business Plan), and Domain (Business Plan) 6 | * { 7 | * "API_KEY": "your api key", 8 | * "PROFILE_KEY": "user profile key", 9 | * "DOMAIN": "Business Plan domain" 10 | * } 11 | */ 12 | import config from "./config.js"; 13 | const { API_KEY, PROFILE_KEY, DOMAIN } = config; 14 | 15 | const social = new SocialMediaAPI(API_KEY); 16 | social.setProfileKey(PROFILE_KEY); 17 | 18 | /** Test history */ 19 | const testHistory = async (platform, id) => { 20 | const history = await social.history( 21 | platform ? { platform } : id ? { id } : null 22 | ); 23 | console.log("testHistory:", history); 24 | }; 25 | 26 | /** Test get details on the current user */ 27 | const testUser = async () => { 28 | const user = await social.user(); 29 | console.log("testUser:", user); 30 | }; 31 | 32 | /** Test Add a feed */ 33 | const testFeed = async () => { 34 | const feedAdd = await social.feedAdd({ 35 | type: "substack", 36 | url: "https://bankless.substack.com/" 37 | }); 38 | console.log("testFeed:", feedAdd); 39 | }; 40 | 41 | /** Test Auto Schedule */ 42 | const testAutoSchedule = async () => { 43 | const setAutoSchedule = await social.setAutoSchedule({ 44 | schedule: ["13:05Z", "20:14Z"], 45 | title: "test" 46 | }); 47 | console.log("testAutoSchedule:", setAutoSchedule); 48 | }; 49 | 50 | /** Test delete */ 51 | const testDelete = async (id) => { 52 | const deletePost = await social.delete({ id }); 53 | console.log("testDelete:", deletePost); 54 | }; 55 | 56 | /** Test post 57 | * Uncomment the platforms you want to post to and/or include the random video. 58 | */ 59 | const testPost = async () => { 60 | const post = await social.post({ 61 | randomPost: true, 62 | // platforms: ["twitter", "facebook", "linkedin", "instagram", "tiktok"], 63 | platforms: ["twitter"], 64 | randomMediaUrl: true, 65 | // isLandscapeVideo: true, 66 | shortenLinks: true, 67 | // requiresApproval: true 68 | }); 69 | console.log("testPost: ", JSON.stringify(post, null, 2)); 70 | 71 | return post.id; 72 | }; 73 | 74 | const testGetPost = async (id) => { 75 | const post = await social.getPost({ id }); 76 | console.log("testGetPost: ", post); 77 | }; 78 | 79 | const testRetryPost = async (id) => { 80 | const post = await social.retryPost({ id }); 81 | console.log("testRetryPost: ", post); 82 | }; 83 | 84 | /** Test Post Update */ 85 | const testPostUpdate = async (id) => { 86 | const post = await social.updatePost({ 87 | id, 88 | approved: true 89 | }); 90 | console.log("test post update: ", post); 91 | 92 | return post.id; 93 | }; 94 | 95 | /** Test Instagram post */ 96 | const testInstagramPost = async () => { 97 | const postInstagram = await social.post({ 98 | randomPost: true, 99 | platforms: ["instagram"], 100 | media_urls: ["https://images.ayrshare.com/imgs/GhostBusters.jpg"], 101 | tagged: ["@ayrshare"], 102 | shorten_links: true 103 | }); 104 | console.log("testInstagramPost:", postInstagram); 105 | }; 106 | 107 | /** Test Upload - Video required*/ 108 | const testVideoPost = async () => { 109 | const datauri = require("datauri"); 110 | const content = await datauri("./test-video.mp4"); 111 | const upload = await social.upload({ 112 | file: content, 113 | fileName: "Test.mp4", 114 | description: "A great test" 115 | }); 116 | console.log("testVideoPost:", upload); 117 | }; 118 | 119 | const testAnalytics = async (id) => { 120 | const analytics = await social.analyticsPost({ 121 | id, 122 | // platforms: ["facebook", "instagram", "twitter", "linkedin"], 123 | platforms: ["facebook"] 124 | }); 125 | return console.log("testAnalytics:", analytics); 126 | }; 127 | 128 | const testAnalyticsSocial = async (platforms) => { 129 | const analytics = await social.analyticsSocial({ 130 | platforms 131 | }); 132 | return console.log("testAnalyticsSocial:", analytics); 133 | }; 134 | 135 | const testGetComments = async (id) => { 136 | const analytics = await social.getComments({ 137 | id 138 | }); 139 | return console.log("testGetComments:", analytics); 140 | }; 141 | 142 | const testListWebhooks = async () => { 143 | const listWebhooks = await social.listWebhooks(); 144 | console.log("testListWebhooks:", listWebhooks); 145 | }; 146 | 147 | const testPostComment = async (id) => { 148 | const analytics = await social.postComment({ 149 | id, 150 | platforms: ["facebook", "instagram"], 151 | comment: "My thoughts exactly" 152 | }); 153 | return console.log("testPostComment:", analytics); 154 | }; 155 | 156 | /** Business Plan Membership - required ---------------- */ 157 | const testCreateProfile = async () => { 158 | const createProfile = await social.createProfile({ 159 | title: "Best Profile Title Ever" 160 | }); 161 | console.log(createProfile); 162 | 163 | return createProfile.profileKey; 164 | }; 165 | 166 | const testDeleteProfile = async (profileKey) => { 167 | const deleteProfile = await social.deleteProfile({ 168 | profileKey: profileKey 169 | }); 170 | console.log("testDeleteProfile:", deleteProfile); 171 | }; 172 | 173 | const testCreateandDelete = async () => { 174 | const profileKey = await testCreateProfile(); 175 | return testDeleteProfile(profileKey); 176 | }; 177 | 178 | const testGenerateJWT = async () => { 179 | const fs = require("fs"); 180 | const privateKey = fs.readFileSync(`./private.key`, "utf8"); 181 | 182 | const jwt = await social.generateJWT({ 183 | domain: DOMAIN, 184 | privateKey, 185 | profileKey: PROFILE_KEY 186 | }); 187 | 188 | return console.log("testGenerateJWT", jwt); 189 | }; 190 | 191 | const testUpdateProfile = async (profileKey) => { 192 | const updateProfile = await social.updateProfile({ 193 | profileKey, 194 | title: "A Nice Title" 195 | }); 196 | console.log("UpdateProfile:", updateProfile); 197 | }; 198 | 199 | const testUnlinkSocial = async (profileKey, platform) => { 200 | const unlinkSocial = await social.unlinkSocial({ profileKey, platform }); 201 | console.log("testUnlinkSocial:", unlinkSocial); 202 | }; 203 | 204 | const testGetBrandByUser = async (platforms, username) => { 205 | const getBrandByUser = await social.getBrandByUser({ 206 | platforms, 207 | instagramUser: username 208 | }); 209 | console.log("testGetBrandByUser:", getBrandByUser); 210 | }; 211 | 212 | const testVerifyMediaExists = async (mediaUrl) => { 213 | const verifyMediaExists = await social.verifyMediaExists({ 214 | mediaUrl 215 | }); 216 | console.log("testVerifyMediaExists:", verifyMediaExists); 217 | }; 218 | 219 | const testMediaMeta = async (url) => { 220 | const mediaMeta = await social.mediaMeta({ 221 | url 222 | }); 223 | console.log("testMediaMeta:", mediaMeta); 224 | }; 225 | 226 | const testMediaUploadUrl = async (fileName, contentType) => { 227 | const mediaMeta = await social.mediaUploadUrl({ 228 | fileName, 229 | contentType 230 | }); 231 | console.log("testMediaUploadUrl:", mediaMeta); 232 | }; 233 | 234 | const testResizeImage = async (imageUrl, platform) => { 235 | const resizeImage = await social.resizeImage({ 236 | imageUrl, 237 | platform 238 | }); 239 | console.log("testResizeImage:", resizeImage); 240 | }; 241 | 242 | const testAutoHashtags = async (post) => { 243 | const autoHashtags = await social.autoHashtags({ 244 | post 245 | }); 246 | console.log("testAutoHashtags:", autoHashtags); 247 | }; 248 | 249 | const testRecommendHashtags = async (keyword) => { 250 | const recommendHashtags = await social.recommendHashtags({ 251 | keyword 252 | }); 253 | console.log("testRecommendHashtags:", recommendHashtags); 254 | }; 255 | 256 | const testCheckBannedHashtags = async (hashtag) => { 257 | const checkBannedHashtags = await social.checkBannedHashtags({ 258 | hashtag 259 | }); 260 | console.log("testCheckBannedHashtags:", checkBannedHashtags); 261 | }; 262 | 263 | const testReviews = async (platform) => { 264 | const reviews = await social.reviews({ platform }); 265 | console.log("testReviews:", reviews); 266 | }; 267 | 268 | const testReview = async (id, platform) => { 269 | const review = await social.review({ 270 | id, 271 | platform 272 | }); 273 | console.log("testReview:", review); 274 | }; 275 | 276 | const testReplyReview = async (reviewId, platform, reply) => { 277 | const replyReview = await social.replyReview({ 278 | reviewId, 279 | platform, 280 | reply 281 | }); 282 | console.log("testReplyReview:", replyReview); 283 | }; 284 | 285 | const testDeleteReplyReview = async (reviewId, platform) => { 286 | const deleteReplyReview = await social.deleteReplyReview({ 287 | reviewId, 288 | platform 289 | }); 290 | console.log("testDeleteReplyReview:", deleteReplyReview); 291 | }; 292 | 293 | const testDeleteComments = async (id) => { 294 | const deleteComment = await social.deleteComments({ 295 | id 296 | }); 297 | console.log("testDeleteComment:", deleteComment); 298 | }; 299 | 300 | const testReplyComment = async (commentId, platforms, comment) => { 301 | const replyComment = await social.replyComment({ 302 | commentId, 303 | platforms, 304 | comment 305 | }); 306 | console.log("testReplyComment:", replyComment); 307 | }; 308 | 309 | /** ------------------------------------------------ */ 310 | 311 | /** Max Pack - required ---------------- */ 312 | const testGeneratePost = async (text) => { 313 | const generatePost = await social.generatePost({ 314 | text 315 | }); 316 | console.log("testGeneratePost:", generatePost); 317 | }; 318 | 319 | const testGenerateRewrite = async (post) => { 320 | const generateRewrite = await social.generateRewrite({ 321 | post 322 | }); 323 | console.log("testGenerateRewrite:", generateRewrite); 324 | }; 325 | 326 | const testGenerateTranscription = async (videoUrl) => { 327 | const generateTranscription = await social.generateTranscription({ 328 | videoUrl 329 | }); 330 | console.log("testGenerateTranscription:", generateTranscription); 331 | }; 332 | 333 | const testGenerateTranslation = async (text, lang) => { 334 | const generateTranslation = await social.generateTranslation({ 335 | text, 336 | lang 337 | }); 338 | console.log("testGenerateTranslation:", generateTranslation); 339 | }; 340 | 341 | const testGenerateAltText = async (url) => { 342 | const generateAltText = await social.generateAltText({ 343 | url 344 | }); 345 | console.log("testGenerateAltText:", generateAltText); 346 | }; 347 | 348 | const testShortLink = async (url) => { 349 | const shortLink = await social.shortLink({ 350 | url 351 | }); 352 | console.log("testShortLink:", shortLink); 353 | }; 354 | 355 | const testShortLinkAnalytics = async (id) => { 356 | const shortLinkAnalytics = await social.shortLinkAnalytics({ 357 | id 358 | }); 359 | console.log("testShortLinkAnalytics:", shortLinkAnalytics); 360 | }; 361 | 362 | /** ------------------------------------------------ */ 363 | 364 | const testWithProfileKey = async () => { 365 | social.setProfileKey(PROFILE_KEY); 366 | 367 | const post = await social.post({ 368 | randomPost: true, 369 | platforms: ["twitter"], 370 | shortenLinks: true 371 | }); 372 | console.log("testWithProfileKey post:", post); 373 | }; 374 | 375 | const run = async () => { 376 | const id = await testPost(); 377 | // await testGetPost(id); 378 | // await testRetryPost(id); 379 | // const update = await testPostUpdate(id); 380 | // await testPostComment(id); 381 | // await testAnalytics("lZDx0mCKwpgCHGp9gLy5"); 382 | // await testGetComments(id); 383 | // testDelete(id); 384 | // await testWithProfileKey(); 385 | }; 386 | 387 | /* 388 | testHistory(); 389 | testUser(); 390 | testAutoSchedule(); 391 | testFeed(); 392 | testPost(); 393 | testInstagramPost(); 394 | testVideoPost(); 395 | testAnalytics(id); 396 | testComments(); 397 | testListWebhooks(); 398 | testAnalyticsSocial(["facebook"]); 399 | testMediaMeta("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg"); 400 | testDeleteComment("XOVUGutufIy5UZFb01e0"); 401 | testReplyComment( 402 | "Nsa2SWqt32BuY4ooeh7Au", 403 | ["instagram"], 404 | "Thank you for the comment!" 405 | ); 406 | */ 407 | 408 | /** Business Plan */ 409 | /* 410 | testCreateProfile(); 411 | testCreateandDelete(); 412 | testGenerateJWT(); 413 | testUnlinkSocial(PROFILE_KEY, "twitter"); 414 | testGetBrandByUser(["instagram"], "@ayrshare"); 415 | testUpdateProfile(PROFILE_KEY); 416 | testMediaUploadUrl("tree.jpg", "jpeg"); 417 | testVerifyMediaExists( 418 | "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg" 419 | ); 420 | testResizeImage( 421 | "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg", 422 | "facebook" 423 | ); 424 | testAutoHashtags("This is a test post"); 425 | testRecommendHashtags("post"); 426 | testCheckBannedHashtags("instagram"); 427 | testReviews("facebook"); 428 | testReview("10114455408676943", "facebook"); 429 | testReplyReview("10114455408676943", "facebook", "Thank you for the review!"); 430 | testDeleteReview("10114455408676943", "facebook"); 431 | */ 432 | 433 | /* Max Pack */ 434 | /* 435 | testGeneratePost("This is a test post"); 436 | testGenerateRewrite("This is a test post"); 437 | testGenerateTranscription("https://img.ayrshare.com/random/landscape5.mp4"); 438 | testGenerateTranslation("This is a test post", "fr"); 439 | testGenerateAltText("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg"); 440 | testShortLink("https://www.ayrshare.com/"); 441 | testShortLinkAnalytics("qR--d8"); 442 | */ 443 | 444 | run(); 445 | --------------------------------------------------------------------------------