GraphQL Authorization with URL token

Hey guys, first post, hoping for some help in trying to create a graphql authorization that mimics a pre-request that I already use in a graphql native ide.

The basic workflow that the server is expecting is to submit credentials (username and password) received a token, then query the server with a url containing the token.

Currently doing it as below...

  1. set username, password and endpoint url from system variables
  2. verify the endpoint url doesn't end with a '/', if it does remove it
  3. get the url as built
  4. await response
  5. grab token value from response and place into environment variables
  6. post url with token to run query

How do I mimic this in Retool?

Some additional info, I've tried following this information (https://docs.retool.com/docs/custom-api-authentication) for setting up the authentication and I am stuck at the point where I can only pass the variable created as a header and not as a token to go into the URL.

Any help is appreciated.

Hey @EKIMMfg,
It sounds like you're actually pretty close! To pass the token as part of the URL, you should just need to add it under "URL Parameters"



Mark,
Thanks for reaching out. I attempted to use url tokens, but it appeared that I couldn't get the server response stored into the value.

I've since undone that, but I will try and redo what I had done to share it with you. Hopefully there is something simple I've missed.

Mark,
Please see example below...

The authorization works, it's just getting the response back into the query that is an issue. Second to that, when running this via an app instead of in the resource builder, the app automatically adds a '/' at the end of the url (doesn't seem to be an issue, just something I didn't expect).

Looking at the Base URL field in your screenshot, it seems like you have added the query parameter manually, this is not required. You should just need to add it under URL parameters, and Retool will automatically add it on outgoing requests:


I'm pretty sure I have to. This is a graphql query, not a rest API query, but I haven't come up with another way in Retool to sent a prequest and add the proper syntax into the url. The only portion of the url I want to modeify is the JS within the {{ }}. The graphql syntax for this server is expecting to see https://BASICSERVER.com/api/graphql?token={{ACTUAL TOKEN}}

Is there something simple I'm not understanding or something simple I'm not explaining correctly?

I did find two errors that I corrected, still no luck. It doesn't seem like the defined variable at the bottom is getting up to the URL.

Oh, I did not realize that your resource is a GraphQL endpoint. Is there a reason why you are setting it up as a REST API resource rather than a GraphQL resource?

Within building a GraphQL resource I do not have the capacity to add in this work flow or defined variables to make this happen. it would be awesome if it's just my own ignorance and I can write a transform or the tools are there and I wasn't paying attention.

CRAP, i wasn't paying attention. Thanks for all the help so far Mark. I'm going to rebuild the resource now that I understand that the custom workflow exists and can recognize the fact that it's in the GraphQL resource.

No worries! Let me know if you run into any issues as you get it set up!

Totally worked, I feel silly, but do appreciate the help. Inexperience shows.

1 Like

Don't worry! Glad we were able to get it sorted out, and if you run into any other issues, don't hesitate to reach out again, either here, or via chat in the lower right corner of most Retool pages!