General
p/general
Share and discuss anything tech, products, business, or startup-related
Dhruv Parmar
API Support
127
β€’
Facing any issues with the API? Share them here
Replies
Best
Dhruv Parmar
Hey everyone! Dhruv from the engineering team at Product Hunt. The new version for the Product Hunt public API is built using GraphQL. We want you to have a smooth experience while integrating with the API and I'll be here to assist you in any issues that might arise. Here are some quick tips to get started: 1. To explore the GraphQL interface of the API quickly, you can use the GraphiQL Explorer app. 2. We've published a minimal Node + React App as a starter kit on Github here. Happy Hacking πŸ’»πŸš€!
Akshay Ashok
@dhruvparmar I'm trying minimal Node + React App as a starter kit, but on clicking Login with product hunt, it get redirected to /authorize but nothing seems to happen. also there is this POST http://localhost:3001/graphql 404 (Not Found) in console.
Dhruv Parmar
@akshay_ashok1 Hey, please make sure to copy `.env.sample` file and rename it to `.env` file in your project root. Also update all `PH_` variables in the `.env` file to appropriate values. I'm guessing there is an issue with the environment variables.
Prashant Nigam
@dhruvparmar Hi Dhruv, Apollo client for iOS or MacOS requires schema.json file of GraphQL server. I tried Apollo CLI to download but was getting 401. Probably missing something. Since this is not user-specific, is it available to download? if yes then please point me to the location. Your help will be much appreciated
Dhruv Parmar
@prashantbuddy hey πŸ‘‹, we've added schema.json & schema.graphql files to the API repository here. Hope this helps https://github.com/producthunt/p... https://github.com/producthunt/p...
Nikolay Siabrenko
@dhruvparmar Hello, how can I get all user following and do not rest against the limit of the API? For example, I want to see what people which I follow do on PH(upvote something, comment, add/finish goal)
Dhruv Parmar
@nikolay_siabrenko you can look up "followers" for a user. check here http://api-v2-docs.producthunt.c... If you run into rate limit issues try fetching "followers" on a per "user" basis. http://api-v2-docs.producthunt.c... We do not support subscriptions as of now, so to get a "user"'s activity you would have to regularly poll for the specific data and detect changes in that on your end. For e.g 1. To detect if a user upvoted a new post, you could poll for "votedPosts" list on the "user" object. 2. To detect changes to user's goal, you can poll "goals(userId: idOfUser)" connection with 'NEWEST' filter.
Nikolay Siabrenko
@dhruvparmar If user have 1000 following, I need make 50 request and it's more than 6250 points. 6250 points it's for all app limit or per auth user?
Dhruv Parmar
@nikolay_siabrenko in cases such as above you'd have to throttle your requests, rate limit quotas reset at every 15m interval.
Dhruv Parmar
We've made following updates to the API: 1. Added `GoalCreate` mutation which allows to create goals on behalf of the authenticated user. http://api-v2-docs.producthunt.c... 2. Added `videoUrl` field to `media` object for Posts. http://api-v2-docs.producthunt.c... 3. Fixes to `GoalUpdate` mutation. 4. Fixed order of `media` items for Post. For further details check out the GraphQL reference here http://api-v2-docs.producthunt.c... cc @ossamaweb @jpeguin1 @wayfarerish @raghuv_adhepalli @roy_shao
Knight ο£Ώ
@dhruvparmar thanks for add Goal Create, how about Project Create ? will it be added ?
Dhruv Parmar
@imknight We wouldn't be adding project create as of now. I'll keep you updated here incase something changes.
Vasanth
@dhruvparmar Is there a way to upvote using this API? I don't see a mutation for that? Also, what will be the validity for the access_grant_token & access_token?
Dhruv Parmar
@vsnthv Currently we don't allow upvotes via the API. The access_token is long lived(never expires) and access_grant_token expires in 20m.
Knight ο£Ώ
@dhruvparmar hi, still pretty new on this graphql things, but it seem like no way to filter the records ? like if I want to filter all my goals that complete only ? I can only fetch all and filter locally ?
Dhruv Parmar
@imknight hey, you can filter "goals" by using "completed" flag here http://api-v2-docs.producthunt.c... Setting `completed: true` on the query will result in only completed goals being fetched.
Knight ο£Ώ
@dhruvparmar Got it , i use Viewer to check, is a bit funny, when checking own goal cannot filter by using completed flag
Knight ο£Ώ
@dhruvparmar the same mutation work on API Explorer and not on local dev, could that my account not grant for write access scope ? but I already apply, will I get a confirmation ?
Dhruv Parmar
@imknight I've approved write access for your application. Let me know incase you're facing issues with mutations still.
Sam Ben
@dhruvparmar Hey, amazing job on the GraphQL API. Are you guys going to add more fields to the post query? I need the post makers and images also reviews would be great ;)
Arj Singh
@dhruvparmar @ossamaweb Yeah I agree. A link to product videos would be handy too. Hope we can get access to this.
Dhruv Parmar
@ossamaweb @asingh thanks for feedback guys πŸ™Œ. We should be able to add those fields to Post query. I'll update here once they are added. Would be good if you could elaborate how you'd be using them in your respective applications?
JPEGuin
@dhruvparmar I'm getting "Cannot return null for non-nullable field Collection.coverImage" when attempting to fetch a collection's coverImage. It works fine for Users as that's nullable, but seems like collections have it set to be not nullable where it may actually still return nothing. Any idea on what to do with this one?
Dhruv Parmar
@jpeguin1 that is most likely a bug in the API, do you mind sharing the ID of the collection you are fetching?
JPEGuin
@dhruvparmar I wasn't fetching a single collection. I was fetching all collections with the parameter "first: 10" in an attempt to populate a list of collections.
Dhruv Parmar
@jpeguin1 We've put in a fix for the issue. coverImage should return `null` instead of failing on CollectionType.
Dhruv Parmar
API Update: We've added support to fetch "makers" & "media" for each Post item. Check out http://api-v2-docs.producthunt.c... cc @ossamaweb @asingh2
JPEGuin
@ossamaweb @asingh2 @dhruvparmar Awesome, is this also reflected in the API explorer?
Dhruv Parmar
@jpeguin1 yes, the API explorer has the new fields.
Dhruv Parmar
API Update: We've added support to fetch "goals" & "goal(id: goalId)" to the API. Check out http://api-v2-docs.producthunt.c... cc @jpeguin1
JPEGuin
@dhruvparmar Seems like doing a "goals" query keeps returning a 204 (no content) for me. It works fine from the API explorer, but any call to this endpoint from my code succeeds but doesn't return anything. Any idea on what may be up with this? EDIT: This has now been resolved on the server-side.
Dhruv Parmar
API Update: We've added capability to cheer goals via the API. Also GoalType now has `cheer_count` to fetch count of cheers on a Goal. For details check out the the following links: 1. GoalCheer - http://api-v2-docs.producthunt.c... 2. GoalCheerUndo - http://api-v2-docs.producthunt.c... 3. "cheerCount" on GoalType http://api-v2-docs.producthunt.c... cc @wayfarerish
Sarun W.
@wayfarerish @dhruvparmar Any plan for isCheer?
Rishi
@dhruvparmar I see some planned updates to APIs here and see recent changes on github. Will the docs be updated asap or do we need to keep an eye here and on github?
Dhruv Parmar
@wayfarerish hey, any updates to the GraphQL interface of the API will always reflect in the reference here http://api-v2-docs.producthunt.c... Unfortunately we don't have a change-log yet so we've decided to publish those updates here as well for the Makers festival participants.
Yash Desai
@dhruvparmar Facing this error on POST request Use the access grant code you received through the redirect to request an access token error:"invalid_grant" error_description:"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."
Yash Desai
@dhruvparmar the starter kit seems to be only for the authorize part, can you please add a get access token sample?
Dhruv Parmar
@yhdesai hey, The "invalid_grant" issue is most likely due to an invalid `code` being used to request the access token. Regarding the starter kit, the get access token part is executed here https://github.com/producthunt/p... once the user authorizes your application. Incase you are looking to build a client only application and do not need users to authorize it you can check out this codesandbox https://codesandbox.io/s/phapi20... as well.
JPEGuin
@dhruvparmar @yhdesai I was facing this issue earlier too, which I resolved through ensuring that the redirect_uri in both the authorise and token calls matched.
Vaibhav Deep
@dhruvparmar @yhdesai @jpeguin1 I am trying the same endpoint using v2 and it still throws this error. The code and redirect_uri are correct. What might be wrong?
Dhruv Parmar
API Update: 1. Added ability to fetch "votes" on a Post or Comment. Supports filtering votes by "createdBefore" & "createdAfter" params. Results are ordered with newest votes coming first. http://api-v2-docs.producthunt.c... http://api-v2-docs.producthunt.c... 2. Added "userFollow" & "userFollowUndo" mutations. http://api-v2-docs.producthunt.c... http://api-v2-docs.producthunt.c... For further details check out the GraphQL reference here http://api-v2-docs.producthunt.c... cc @janzikan @nikolay_siabrenko
Jan ZikΓ‘n
@nikolay_siabrenko @dhruvparmar Great job! Would it be possible to provide votes as query? The use case I am thinking of is to trigger an action when a post reaches a certain amount of upvotes. II do not want to track the number of upvotes for a specific post but for all posts - for example show post on a webpage once it reaches 100 upvotes.
Dhruv Parmar
@janzikan hey, we do not plan on exposing "votes" on the root query, as "votes" should always be fetched in the context of a Votable type. For your use case I'd suggest going with something like this 1. Fetch posts ordered by VOTES everyday 2. Filter out posts which could hit the threshold (100 in this case) and trigger polling the "post(id: postId)" field for them. I know this is not ideal, but probably something that could work. Don't worry about the number of requests as we can increase your rate limit quotas if you start getting blocked by them.
Jan ZikΓ‘n
@dhruvparmar Better solution would be to be able to filter posts that have upvotes count greater than X and to order them by VOTES but in descending order. Are you planning to implement option for ordering so we choose whether the results should be ordered in ascending or descending order? Are you planning to implement filtering for the queries?
Dhruv Parmar
@janzikan the VOTES option sorts posts in descending order of votes count currently. We don't have plans to add filtering for the votes query as of now. Regarding ability to define the sort order, we'll try to incorporate this into the API. I'll share an update here once it's implemented.
JPEGuin
@dhruvparmar Is there a way to see all maker goals (not just your own ones)? And is there also. way to see goals that are a part of spaces?
Dhruv Parmar
@jpeguin1 We don't have that as of now, but are considering opening it up via `goals` field on the root query. I'll keep you updated here if it's added.
JPEGuin
@dhruvparmar Hi, I've got a quick question about mutations. When attempting to mark a goal as complete, I only get returned {"data":{"goalMarkAsComplete":{"node":null}}} Is this intentional? As it doesn't actually seem to perform the action. Here is my request: mutation { goalMarkAsComplete(input: {clientMutationId: "\(clientId)", goalId: \(goalId)}) { node { id, completedAt, createdAt, title, user { name, id, profileImage, username } } } } And what is the clientMutationId? Is it just a random String or the client ID that's retrieved when authenticating? EDIT: After looking at the error, it's an access_denied error, any way to resolve this?
Dhruv Parmar
@jpeguin1 please write to hello@producthunt.com with your API Key included in the message.
JPEGuin
@producthunt @dhruvparmar Thanks, done it now. Also, I was wondering on when goal creation support will be coming?
Nikolay Siabrenko
@dhruvparmar Hello, find a bug in pageInfo, if you use query without first param, hasNextPage always false, but by default - first: 20 { viewer { user { following(after: "", first: 20) { totalCount pageInfo { endCursor, hasNextPage } edges { cursor node { id } } } } } }
Dhruv Parmar
@nikolay_siabrenko hey, thanks for reporting the issue, I can confirm it's a bug and we'll be working on fixing it. Unfortunately the issue exists in one of the 3rd party packages we use internally so it might be a while before the fix is in. I'd suggest going with always including `first: 20` in the connection variables for now.
JPEGuin
@dhruvparmar Hey, I've got a quick question regarding the API - So a simple body param to fetch posts would look like "query": "query { posts(first: 1) { edges { node { id, name } } } }", but what would one for fetching something more nested like the posts in a collection look like? And in general where can I find this documented? EDIT: I've now figured it out. For anyone curious: Start with "collection(id: idOfTheCollection) {... which should return all posts in the collection.
Arjun
@dhruvparmar Are these the only allowed mutations? GoalMarkAsCompleteInput GoalMarkAsIncompleteInput GoalUpdateInput What about creating a goal?
Dhruv Parmar
@arjunz Yes, those are the allowed mutations for now. We are working on adding "GoalCreate". I will update you here once it's added.
Arjun
@dhruvparmar Cool thanks. It doesn't make sense to build an app if it only supported marking goals as done :D