question

Magnus-2918 avatar image
0 Votes"
Magnus-2918 asked Magnus-2918 answered

How do I add header with token in Azure Data Factory

Hi!

I'm trying to connect to a GraphQL api with the http connector in Azure Data Factory. GraphQL wants a header in this format:

Authorization: token xxxxxxxxxxxxx

How do I add that header?

/Magnus

azure-data-factory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MartinJaffer-MSFT avatar image
1 Vote"
MartinJaffer-MSFT answered Magnus-2918 commented

Hello @Magnus-2918,
Thanks for the question and using MS Q&A platform.

As we understand the ask here is how to add the authorization header when using http connector . Note, usually I see Authorization: Bearer XXXX not Authorization: token XXXX. Please double check which one it should be in your case.

  1. Open the dataset, and add a parameter. In this example I can calling it tokenparam.

  2. In the Additional Headers textbox enter the following dynamic content:

    @concat('Authorization: token ',dataset().tokenparam)

  3. Go to the copy activity and find the new place to enter parameter value. Reference wherever you are getting the token value from.

Please do let me if you have any queries.

Thanks
Martin


  • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how

  • Want a reminder to come back and check responses? Here is how to subscribe to a notification

  • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi! Thanks for trying to help. If I change to Bearer I get this so yes it must be token.

181023-prev2.png


181025-prev.png


The dataset is a http json. If I do like you suggested and then click Preview data I get "Bad Json". As you can see I'm posting a GraphQL query and I've tried in a number of ways, without Query, with Query. I don't know if it's that that is the issue here. Do I need to add an additional header application/json?

0 Votes 0 ·
prev2.png (12.0 KiB)
prev.png (36.0 KiB)
Magnus-2918 avatar image
0 Votes"
Magnus-2918 answered Magnus-2918 commented

Sorry for the last post. It returns "Invalid json syntax". If I haven't published a pipeline is there any way in ADF to see what is returned when Previewing data?

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ahh, I think I know what is happening this time. When you did "Preview Data", it needed to give a value for the token. Since preview only takes into account the current activity, it doesn't run other activities. Thus it tries to use the default value for the token. If the default value wan't valid, then an error message was probably returned instead of data. So the error message wasn't valid JSON.

TLDR: temporarily try pasting in a current and valid token instead of passing through parameters. This should work for preview. Or put it in the default values.

@Magnus-2918

0 Votes 0 ·
Magnus-2918 avatar image Magnus-2918 MartinJaffer-MSFT ·

I tried to do as you proposed but the same error. I created a new pipeline with an web activity and used json as a dataset without paramters. Then created the Authorizaton header with token. Same error

Look at the respone.

182801-unsafe.png


0 Votes 0 ·
unsafe.png (16.1 KiB)

Invalid JSON syntax.... okay. So looking at your request message body...

 query {
     employees(last: 1000) {
         edges {
 ...

That is not JSON.

Is the response body expected to return JSON @Magnus-2918 ?

0 Votes 0 ·
Show more comments
Magnus-2918 avatar image
0 Votes"
Magnus-2918 answered

I solved this, sorry for late reply all.

First of all I moved the authorization to the Linked service

201300-linked.png


Then I created a Json dataset and connected it to the Linked service.

Added a Copy Data in the pipeline and set the properties to this

201323-copy.png

What's really really important here is the formatting of the GraphQL in the Request Body. The data has to be on one line, no line breaks. The spacing is also very important to get it to work.

Hope this helped someone.



linked.png (50.9 KiB)
copy.png (53.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.