You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Upwork GraphQL API获取全部或指定数量的筛选职位?

解决Upwork GraphQL API获取更多职位的问题

要获取超过默认10个的职位结果,你需要利用GraphQL的分页参数,具体操作如下:

1. 单次请求获取指定数量(如前100个)职位

Upwork的marketplaceJobPostingsSearch查询支持first参数,用来指定单次返回的职位数量(需注意API有单次返回上限,通常最大为100)。你需要修改查询语句和变量,添加该参数:

修改后的完整请求

{"query": "query marketplaceJobPostingsSearch($marketPlaceJobFilter: MarketplaceJobPostingsSearchFilter, $searchType: MarketplaceJobPostingSearchType, $sortAttributes: [MarketplaceJobPostingSearchSortAttribute], $first: Int) { marketplaceJobPostingsSearch(marketPlaceJobFilter: $marketPlaceJobFilter, searchType: $searchType, sortAttributes: $sortAttributes, first: $first) { totalCount edges { node { id title description category } } pageInfo { hasNextPage endCursor } } }","variables": {"marketPlaceJobFilter": {"titleExpression_eq": "JAVA"},"searchType": "USER_JOBS_SEARCH","sortAttributes": [{ "field": "RECENCY" }],"first": 100}}

关键修改点

  • 在查询的参数定义里新增$first: Int
  • 在marketplaceJobPostingsSearch调用时传入first: $first
  • 在variables里添加"first": 100,指定单次返回100个结果

2. 获取符合条件的全部职位

如果结果总数超过单次请求上限,需要通过游标分页循环获取:

  • 第一次请求使用上述带first参数的查询,拿到返回结果里的pageInfo.endCursor和pageInfo.hasNextPage
  • 如果hasNextPage为true,则发起下一次请求,在查询里新增$after: String参数,调用marketplaceJobPostingsSearch时传入after: $after,并在variables里设置"after": "上一次的endCursor值"
  • 重复上述步骤,直到hasNextPage变为false,此时已获取全部结果

分页请求示例(第二次请求)

{"query": "query marketplaceJobPostingsSearch($marketPlaceJobFilter: MarketplaceJobPostingsSearchFilter, $searchType: MarketplaceJobPostingSearchType, $sortAttributes: [MarketplaceJobPostingSearchSortAttribute], $first: Int, $after: String) { marketplaceJobPostingsSearch(marketPlaceJobFilter: $marketPlaceJobFilter, searchType: $searchType, sortAttributes: $sortAttributes, first: $first, after: $after) { totalCount edges { node { id title description category } } pageInfo { hasNextPage endCursor } } }","variables": {"marketPlaceJobFilter": {"titleExpression_eq": "JAVA"},"searchType": "USER_JOBS_SEARCH","sortAttributes": [{ "field": "RECENCY" }],"first": 100,"after": "上一次返回的endCursor字符串"}}

注意事项

  • 请参考Upwork官方文档确认first参数的最大允许值,避免因超出限制导致请求失败
  • 分页请求需控制频率,遵守API的速率限制规则,防止被限流

内容的提问来源于stack exchange,提问作者Bilal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 21:35:01