Forum Discussion

vaishnavi's avatar
vaishnavi
Expert
10 years ago

facing issue in integrating third party API in endpoint

I am tryign to integrate a third-party API calls in my endpoint using oauth.

steps :-

1.  API call to get new access token.

I am getting below response >>  {"expires_in":1209600,"refresh_token":"AVm+qqHWICxNvhDcNSvtFRIyMw==","access_token":"AZoOjM6fLc5PhGUwjgd7zCoyMQ=="}

2. I want to get 'access_token' value from above response and to pass this value in header for 2nd API call.

 

observation : If I hardcode it into a freemaeker variable then its working fine

<#assign a_token = "ASfJllLBFpNPucOl7hMQptwyMQ==" />

<#assign http_response_client_lists = http.client.request("https://api.createsend.com/api/v3.1/clients.json").header("Authorization", "Bearer "+a_token).get()

 

issue : when I store access_token into a freemarker variable and try to use that var in 2nd API, its not working.

<#assign a_token = json_response.access_token />

 

<#assign http_response_client_lists = http.client.request("https://api.createsend.com/api/v3.1/clients.json").header("Authorization", "Bearer "+a_token).get()

 

Am I missing anything here?

Please help me find the solution.

 

Thanks,

Vaishnavi

 

  • PaoloT,

    Thanks for your suggestion.

    I have used the approach and its working now.

    • OlivierS's avatar
      OlivierS
      Lithium Alumni (Retired)

      vaishnavi have you try to display the value of the 'a_token' variable to see its content?

       

      <#assign a_token = json_response.access_token />

      Or try:

       

      <#assign a_token = json_response.access_token?json_string  />
      • vaishnavi's avatar
        vaishnavi
        Expert

        When I print ${a_token} it print the correct string value but its not working in API header.

         

        I have tried j_string, js_string, json_string but nothing is working.

        I getting below error :

        error making http request: Unauthorized

         

        Is here any issue due to encoding of API response ?

         

        when I print ${a_token?url} for <#assign a_token = "ASfJllLBFpNPucOl7hMQptwyMQ==" /> 

        output is : ASfJllLBFpNPucOl7hMQptwyMQ%3D%3D

         

        and when I print ${a_token?url} for <#assign a_token = json_response.access_token />

        output is : ASfJllLBFpNPucOl7hMQptwyMQ%26%2361%3B%26%2361%3B

         

        means it takes HTML encoded access_token  as ASfJllLBFpNPucOl7hMQptwyMQ&#61;&#61;

        Note here : &#61; is HTML encoded equivalent of equal sign( = )

        and again encodes it to MQ%26%2361%3B%26%2361%3B

         

        Does anyone know how to decode HTML encoded string in freemarker variable?