trash nothing
  1. posts
trash nothing
  • messages
    • List conversations
      GET
    • Mark all conversations as read
      PUT
    • Search conversations
      GET
    • Delete conversation
      DELETE
    • Archive conversation
      PUT
    • Block conversation
      PUT
    • Mark conversation as read
      PUT
    • List conversation messages
      GET
    • Reply to conversation
      POST
    • Report conversation
      POST
    • Unarchive conversation
      PUT
    • Unblock conversation
      PUT
  • misc
    • Send feedback
  • groups
    • Search groups
    • Retrieve multiple groups
    • Join groups
    • Retrieve a group
    • Submit group answers
    • Contact group moderators
    • Leave a group
  • photos
    • Create a photo
    • Retrieve multiple photos
    • Delete a photo
    • Rotate a photo
  • posts
    • List posts
      GET
    • Submit a post
      POST
    • List all posts
      GET
    • List all post changes
      GET
    • Retrieve client.js
      GET
    • Retrieve multiple posts
      GET
    • Search posts
      GET
    • Retrieve a post
      GET
    • Update a post
      PUT
    • Delete a post bookmark
      DELETE
    • Bookmark a post
      PUT
    • Retrieve post display data
      GET
    • Flag a post
      POST
    • Map a post
      PUT
    • Promise an offer post
      PUT
    • Reply to a post
      POST
    • Satisfy a post
      PUT
    • Share a post
      POST
    • Unpromise an offer post
      PUT
    • Withdraw a post
      PUT
  • stories
    • List stories
    • Submit a story
    • Retrieve a story
    • Like a story
    • Unlike a story
    • Record story viewed
  • users
    • Retrieve current user
    • Update current user
    • List current users' email alerts
    • Create an email alert
    • Delete an email alert
    • Change email address
    • Set users' email address as not bouncing
    • List current users' groups
    • Update location
    • List current users' group notices
    • List current users' post locations
    • Save a post location for the current user
    • List current users' posts
    • Search current users' posts
    • Set a profile image
    • List current users' profile images
    • Resend account verification email
    • Send password reset email
    • Report a user
    • Retrieve a user
    • Retrieve user display info
    • Submit feedback on a user
    • List posts by a user
    • Search posts by a user
    • Retrieve a users' profile image
  1. posts

Retrieve client.js

GET
/posts/client.js
posts
Defines javascript functions that can be used to validate and submit posts.
The advantage of using these functions versus using the post submission endpoint directly is that
some of the post validation checks can be done on the client side which will be faster.
NOTE: If used, this javascript file MUST be loaded dynamically for each user because the contents
of the file are generated dynamically based on the current user. The file may be cached on a per
user basis based on the HTTP cache headers that are returned when the file is requested (currently
the cache headers specify that the file should expire after one day).
The following functions are available:

window.TN.check_crossposting_restrictions(group_ids)
Checks for crossposting restrictions when the user selects more than one group to post to.
Parameters:
group_ids is an array of group IDs
Returns an object with three properties {allowed, restricted, restrictions}.
allowed is an array of the group IDs from group_ids that can be crossposted to
restricted is an array of the group IDs from group_ids that can't be crossposted to
restrictions is an object mapping group IDs that have crossposting restrictions to arrays of group IDs that are restricted.
It is useful for pinpointing why a group ID shows up in the restricted array so that users can be provided feedback
about the reason for the crossposting restriction (eg. a message like 'group A doesn't allow crossposting to group B').
For example, given group_ids = [1, 2, 3, 4] and assuming group 1 doesn't allow posting to group 3 and group 2 doesn't allow
posting to group 1, the returned object will be:
{allowed: [4], restricted: [1, 2, 3], restrictions: {1: [3], 2: [1]}}

window.TN.submit_post(args, session, preferences, callback)
Submits a new post and performs validation checks on the post before it is accepted for submission.
Parameters:
args is an object containing data about the post being submitted and must include
the following properties:
type: The type of post. One of: offer, wanted
title: A short description of the item(s).
location: A short location description.
The following properties are optional:
content: A longer description of the item(s).
group_ids: An array of group IDs to submit the post to (if any).
fair_offer: If set to 1, the post will be posted with the Fair Offer Policy (only valid for offer posts - see https://trashnothing.com/fair_offer_policy ).
photo_ids: A comma separated list of the IDs of the photos that should be attached to this post.
latitude
longitude
session is a temporary object that is used by submit_post to store data about the submission
process for a single post. The first time submit_post is called with a post, session should
be a new empty object (eg. {}). The session object should be persisted until that post
is successfully submitted and then it can be discarded so that the next post will start
over with a new empty session object.
preferences is a permanent object that the client persists and modifies based on warnings returned
by the post submission process and user input. Some post warnings passed to the callback object
have a preference_key string property so that users can opt out of those warnings in the future.
To save this opt-out preference, set the property indicated by the preference_key in the preferences
object (eg. preferences[preference_key] = 1). The preferences object is only read by submit_post and
never modified - it is up to the client to initialize, modify and persist the preferences object.
callback is a function used to return the result of the post submission. It is called and passed
one argument - an object with five properties {result, message, preference_key, identifier, session}.
The result property is a string that is one of: success, error, warning. The identifier property is
set for errors and warnings and will contain a string that represents the type of error or warning that
occurred.
A success result indicates that the post was submitted successfully. Note that posts may not
appear instantly after submission because the moderators of many groups may have additional
automatic or manual review processes in place that can delay the publishing of a post.
An error result indicates that there is an error with the post to show the user and the message property
will contain text describing the error.
A warning result indicates that there is a warning about the post to show the user and the
message property will contain a string describing the warning. A warning result doesn't prevent a post from
being submitted, to continue the submission process after a warning result, just re-submit the post
(with the updated session object) to temporarily override that specific warning.
Certain types of warnings can be opted out of. These warnings will set preference_key to a string that can be
set in the preferences object by the client to opt out of that type of warning in the future (see the description
of the preferences parameter for more details).
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request GET 'https://trashnothing.com/api/v1.2/posts/client.js?group_ids=&access_token='
Response Response Example
200 - Example 1
{}

Request

Query Params
group_ids
string 
required
A comma separated list of all the group IDs that the current user is a member of. If the current user is not a member of any groups, simply pass an empty string.
callback
string 
optional
The name of a global function to call once the script is loaded.
access_token
string 
required

Passing the current users' OAuth2 access token as a GET parameter makes it easier to load this script in a normal HTML

Responses

🟢200The client.js javascript file.
application/json
Body
object {0}
🟠400Invalid group IDs.
Modified at 2022-09-11 18:59:48
Previous
List all post changes
Next
Retrieve multiple posts
Built with