1

I'm trying to call an RESTful API within BizTalk. I need to make a GET against the following endpoint:

https://mycompany.com/buyer/sandboxevol/

I have below mappings configured in my Send Port

<BtsHttpUrlMapping>
  <Operation Name='Operation_1' Method='GET' Url='/page.aspx/en/eai/api/supplier/{id}?apikey={apikey}&amp;format={format}' />
</BtsHttpUrlMapping>

paramater apikey has value as XXXXXXXXXXzvrpZHbMdKY75zbszhGOu%2bfnmP7Ms%3d. I have checked this and verified from suspended instance. Suspended message But error message different apikey value present. Refer screenshot Error message (hkey value highlighted)

Error information

character % is being encoded as %25 in error message. I believe there are 2 issues

  1. Invalid APi key issue (this post talks about this) and
  2. Some firewall/proxy opening between BizTalk and 3rd party system (I shall check this with internal Admin team)

Any thoughts on resolving this encoding/weird issue

4
  • It is probably nothing to do with the encoding or the API key. I see that sort of error a lot if the API only expects TSL 1.2 and the version of .Net doesn't default to using it. See my answer on this questions. stackoverflow.com/questions/62458270/… Commented Jun 26, 2020 at 8:00
  • Thanks. I am using TLS1.2 and it solved the connection problem. But I still has the value being encoded/changed issue. Please refer my comments below for further details. Commented Jun 29, 2020 at 10:22
  • You might want to post a new question with the details of how you are sending the creating and sending the API key, and then we can recommend a fix for that. On Stackoverflow they want one problem per question. Commented Jun 29, 2020 at 20:34
  • What framework does your WCF service use? If you are using .net 3.5 or lower, TSL 1.1 is used by default. If you use .net 4.5, although it supports TSL 1.2, it is not the default protocol.For more information about TLS,Please refer to this link:learn.microsoft.com/en-us/dotnet/framework/network-programming/…. Commented Jul 2, 2020 at 7:28

1 Answer 1

1

Based on the error, its most likely happening due to TLS version mismatch. BizTalk 2013 by default use TLS1.0. The recommended version now is to use TLS1.2 or up. You can check with API provider which version of TLS they use. You can change BizTalk behavior by creating a custom send pipeline component and then set TLS version using following code in Execute method. There is no change required to BizTalk message in pipeline component, just place this one line code and return same pInMsg from execute method.

System.Net.SecurityPointManager.SecurityProtocol = SecurityProtocolType.Tls12

ref like Microsoft doc

You can also use external tools such as Postman, Fiddler to test API calls outside BizTalk to make sure API works outside BizTalk.

    public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
    {


        System.Net.SecurityProtocolType protocolType;
        if (!String.IsNullOrEmpty(TlsVersion)
            && Enum.TryParse<System.Net.SecurityProtocolType>(TlsVersion, true, out protocolType))
            System.Net.ServicePointManager.SecurityProtocol = protocolType;
        else
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;


        return pInMsg;
    }
Sign up to request clarification or add additional context in comments.

4 Comments

I am using TLS1.2 now. (Could not achieve in pipeline component but implemented in Custom WCF Behaviour). Now am getting Invalid API key error from that REST based API service. I tried in SOAP UI by passing same apikey value and recieved Invalid API key error here too. But in SOAP UI ,I was able to manually disable encoding (Disable Encoding for parameter in SOAP UI) and then it worked in SOAP UI. My guess is that same thing is being repeated in BizTalk. Character % is being changed/encoded to %25 and sent to service. May I know how can we achieve this in BizTalk. Thanks.
We have used it so many times. It works from pipeline component. I have updated the answer above with code. In the code version is driven from the pipeline property. The pipeline component should be used on a send pipeline. I have this code running in BizTalk 2016 PROD. It avoids modifying machine.config file which is required for behavior route.
Regarding the encoding, BizTalk adapter is working by default as designed. % is a reserved key word for URL and it is correctly encoding it to %25. You can look for implementing a custom behavior to fix this, I am not sure. Or if possible ask API provider to not have % in api key. Or May be encode to base64 before sending provided both party agrees.
Thanks for the info. I was able to do TLS version update from Pipeline as well. I am in talks with the API Provider and will ask them parameters at Header level rather than at query level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.