-2

I'm having trouble understanding what I'm doing wrong interfacing with this API of Freelancer.com, retrieving bids:

I'm sending a GET request to https://www.freelancer.com/api/projects/0.1/bids/?projects[]=36483622&projects[]=36483620 with the following headers:

[
    'Authorization: Bearer ' . $token,
    'Content-Type: application/json'
]

I'm getting HTTP 401 returned, with the body as follows:

{
    "status": "error",
    "message": "You must be logged in to perform this request",
    "error_code": "RestExceptionCodes.NOT_AUTHENTICATED",
    "request_id": "45b290aa21a0fabe9effb0c6c5294097"
}

What am I doing wrong? My token works fine when I try to retrieve projects via this URL:

https://www.freelancer.com/api/projects/0.1/projects/active/?jobs[]=3

What does it mean I need to be logged in? Doesn't the token do that? How do I retrieve bids on projects? Can I only retrieve bids on projects that I posted? What about bids that I submitted?

Thanks

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Jodes
  • 14,118
  • 26
  • 97
  • 156
  • 1
    The cURL example request listed on the documentation page you referred to, uses `--header 'freelancer-oauth-v1: '` ...? – CBroe May 12 '23 at 11:14
  • Where are you getting `$token` from? Are you sure it's valid? – esqew May 12 '23 at 15:21
  • "*My token works fine when I try to retrieve projects via this URL:*" That's probably because that particular endpoint doesn't require authentication (since I was able to open it in my browser) and the server is disregarding your `Authorization` header entirely. – esqew May 12 '23 at 15:22
  • 1
    https://developers.freelancer.com/docs/authentication/using-access-tokens – Olivier May 12 '23 at 20:50
  • 2
    next time you need help debugging, please provide more of the source code. there might be additional issues with your request, which is not shown in the code you shared. For example, if your code also use a `CURLOPT_POST=>1` or `CURLOPT_POSTFIELDS=>...` in this request, that would be another issue with the code, but i have no idea, because you don't provide the curl_setopt options you used (-: – hanshenrik May 13 '23 at 13:54

1 Answers1

1

1: don't set a Content-Type if your request doesn't have a body. your request doesn't, so remove the Content-Type. (also emptystring is not valid json. 1 or [] would be valid JSON, but you're not sending any JSON.)

2: the header is called freelancer-oauth-v1: <oauth_access_token> so try

[
    'freelancer-oauth-v1: ' . $token,
    // remove this line, it does not belong in GET requests: 'Content-Type: application/json'
]

hanshenrik
  • 19,904
  • 4
  • 43
  • 89