Issue
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
Solution
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'
]
Answered By - hanshenrik Answer Checked By - Timothy Miller (WPSolving Admin)