Authorization header

Hi everybody.

First of all, I’m integrating the Apollo SDK to an iOS project.
I’m trying to make use of an API that works with GraphQL. However, I’m required to have a client-id, which I need to use when requesting data through an HTTP header.

I’ve tried to add that header when fetching the schema in the Build Phases script, as it follows:

“${SCRIPT_PATH}”/ schema:download --endpoint="" --header="x-client-id: ".

Despite doing that, the API doesn’t allow me to fetch data since I’m not supposedly correctly authenticating. (I’ve tried that token on the API playground and works like a charm)

Any workaround?

Thank you in advance.

Hi @Javi_Gallego :wave:

When you say “API playground” are you meaning the Swift Playground or Apollo Studio in a browser? If you have one working but not the other it might be worth using something like Charles Proxy to see what the differences are in the request being sent.

Something else to note is that you shouldn’t need to download the schema on each build - schema:download. Once you’ve got the schema (from API playground?) you use that along with operations to generate code into the actual API that you use in your app.

Hi @calvincestari

By API Playground I mean the playground that the API offers to try their queries in the browser (I guess it’s quite similar, if not the same as Apollo Studio)

Concerning the schema:download, I only executed that the first time in my Xcode project. However, I’m not sure if I’m correctly sending my client-id as an HTTP header, by adding the parameter --header to the schema:download script line (as I wrote in my first message).

That’s my question, how to send a header so that the API can authorise me to make queries.

Thank you.

It sounds like you want to add that header to the query requests that gets sent to the GraphQL server. Our tutorial documentation has a section on mutations that explains how to use interceptors to achieve this. You can always find the working tutorial code here which will let you step through the code.

If you’re actually wanting to add authorization to the schema download then you should take a look at this issue.

Those links should help. Let me know if you still can’t get things working.

1 Like

Hi again.

I’ve tried it and it works like a charm!

Thank you for your support.