0

I'm trying to connect to Upwork's new GraphQL API, having a heck of a time. All authorization is already set, the response is 200 but I am getting this error:

{"errors":[{"message":"Validation error of type FieldUndefined: Field 'user' in type 'Query' is undefined @ 'user'","locations":[{"line":2,"column":6}],"extensions":{"classification":"ValidationError"}}]}

This is my basic function:

function getUpwork() {
  var service = getService("upwork");
  var url = "https://api.upwork.com/graphql";
  var payload = JSON.stringify({
    "query":
      `query {
     user { 
      id 
      email 
      } 
    } ` });

  var headers = {
    "Authorization": `bearer ${service.getAccessToken()}`,
    "Content-Type": "application/json",
  };

  var params = {
    "method": "POST",
    payload,
    headers
  };

  var response = UrlFetchApp.fetch(url, params);

  Logger
    .log(response.getResponseCode())
    .log(response.getContentText())
}

I am just trying to get something returned from the API, but no dice. Documentation here: https://www.upwork.com/developer/documentation/graphql/api/docs/index.html#query-user

Can anyone shed some light on this for me? It's been kicking my butt for months. I have tried tons of configurations of the query.

2 Answers2

0

Try adding user to payload like

var payload = JSON.stringify({
    "query":
      `query user {
     user { 
      id 
      email 
      } 
    } ` });

Or removing query user altogether:

var payload = JSON.stringify({
    "query":
      `{
     user { 
      id 
      email 
      } 
    } ` });

And use propercase Bearer:

"Authorization": `Bearer ${service.getAccessToken()}`,
TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • Thank you for the suggestions! I tried both payload variations with the same error response ("Validation error of type FieldUndefined: Field 'user' in type 'Query' is undefined @ 'user'"). – Daniel Allen Jul 02 '23 at 15:11
  • @DanielAllen Could you quote the exact error including location/line numbers for both payloads? Have you changed `bearer` to `Bearer`? – TheMaster Jul 02 '23 at 22:15
  • 1
    Yes I switched bearer to Bearer, looks like the issue originates from Upwork itself. – Daniel Allen Jul 14 '23 at 18:40
0

Your code looks working. At the moment, there is an issue with public GraphQL queries. The team is aware of it and works hard to fix it as soon as possible. If you have any further questions, please, do not hesitate to contact Upwork Support Team.

Upwork is really sorry for the inconvenience caused.

mnovozhylov
  • 311
  • 1
  • 3