Search code examples
azure-data-factoryazureservicebus

How to add Broker Properties header to External Call Transformation on Data Factory


I have an issue in Data Factory's external call. I need to send data to a service bus, which requires a SessionId to be specified in the headers. However it is in the BrokerProperties as specified here: https://learn.microsoft.com/en-us/rest/api/servicebus/Message-Headers-and-Properties?redirectedfrom=MSDN

Using the mapping data flow I created an external call transformation with payload already tested and working fine. However in the Additional Headers parameters I am required to give what looks like:

BrokerProperties:  { "SessionId": "<some value>" }

I tried to assemble this in the Additional Headers in the External Call Transformation:

enter image description here

The code of these is (NAITNumber is a column coming through, simple number):

Name: 'BrokerProperties:{SessionId:' 
Value: concat(toString(NAITNumber),'}')

Which gives me the error: The value '{SessionId: 116}' of the HTTP header 'BrokerProperties' is invalid.

So it seems I need the double quotes around the key value pairs, so tried it with:

Name: '"BrokerProperties":{"SessionId"'
Value: concat('"',toString(NAITNumber),'"}')

And I get the error: Bad Request - Invalid Header HTTP Error 400. The request has an invalid header name.

Anyone else know how to specify the sessionId so Service Bus is happy?


Solution

  • OK, this will be useful for others using the mapping data flows External Call to post to Azure Service Bus. Actually its also useful for passing any additional headers to anything else, that also requires a Key Value pair within a Header value:

    The initial header value doesn't need to be in double quotes. So to provide an additional Key Value paired Header you do this in the "Additional Headers" section under the Advanced drop down of the External Call Transformation (the "Name:" and "Value:" denote which box you are entering data into):

    Name: 'AdditionalHeader:{"ActualName"'
    Value: concat('"',toString(ActualValue),'"}')
    

    I figured this out after a lot of trail and error, in my case it was:

    Name: 'BrokerProperties:{"SessionId"'
    Value: concat('"',toString(NAITNumber),'"}')