Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Refresh token api call

hi all,

 

am currently working with salesforce social studio reporting and they do have rest api to retrieve data and report on. This does work well with "bearer tokens" with postman and using web connection to retrieve data. However, since these tokens are associated to expire after 3600 seconds the token again has to be updated manually. I'm trying to find a manner in which this can be automated.

 

I followed the earlier provided solution to parameterize or using MS Flow (power automate) > http to post and refresh token still does not help, any suggestion will be of great help.

 

more information about social studio rest api is here

https://developer.salesforce.com/docs/atlas.en-us.api_social.meta/api_social/1-introduction-to-the-social-studio-marketing-cloud.htm

 

regards,

A!

  • Hi Anonymous,

     

    I stumbled over a similar problem as you last year. I solved my api connection by buidling a custom data connector.

    https://github.com/Microsoft/DataConnectors

     

    With the connector you have a lot of possibilitys for authentication handling:

    see: https://docs.microsoft.com/en-us/power-query/handlingauthentication

     

    The custom Connector can be attached to the data gatway from there the api calls are made.

     

    This is not a really easy way for sure but may be a solution.

     

    -------------------------------------------------------------------
    Did I answer your question? Mark my post as a solution!
    It was useful? Press Thumbs Up!

     

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Rainer and everyone,
    Thank you for the quick response. Having said this, I was able to solve this one following the below manner.
     
    Regards,
    Anand

     

    Step one: Create parameters for client_id, client_secret, oauth token, search url, username, password
    Step two: a new query with the following

     

    let
        //App Details
        client_id = #"API Key", //<===parameter
        client_secret = #"API Secret", //<===parameter
        
        //Authentication
        
        //URI's
        token_uri = #"Token URL", //<===parameter
        resource =  #"Search URL", //<===parameter
        
        //User Details  
        username = username, //<===parameter
        password = password, //<===parameter
          
       tokenResponse = Json.Document(Web.Contents(token_uri,          
                                    [
                                        Content=
                                        Text.ToBinary(Uri.BuildQueryString(
                                        [
                                            client_id = client_id
                                            ,client_secret=client_secret
                                            ,username=username
                                            ,password=password
                                            ,resource=resource
                                            ,grant_type = "password"
                                            
                                        ]))
                                        ,Headers=
                                            [Accept="application/json"]
                                            , ManualStatusHandling={400}
                                    ])),
                                    access_token = tokenResponse[access_token],
        token = "Bearer " & tokenResponse[access_token],
     GetJsonQuery = Web.Contents("[search url]",
         [
             Headers = [#"Authorization"=token]
         ]
     ),
    FormatAsJsonQuery = Json.Document(GetJsonQuery)
     
    in
     
    FormatAsJsonQuery

     

6 Replies

  • rainer1's avatar
    rainer1
    Resolver III

    Hi Anonymous,

     

    I stumbled over a similar problem as you last year. I solved my api connection by buidling a custom data connector.

    https://github.com/Microsoft/DataConnectors

     

    With the connector you have a lot of possibilitys for authentication handling:

    see: https://docs.microsoft.com/en-us/power-query/handlingauthentication

     

    The custom Connector can be attached to the data gatway from there the api calls are made.

     

    This is not a really easy way for sure but may be a solution.

     

    -------------------------------------------------------------------
    Did I answer your question? Mark my post as a solution!
    It was useful? Press Thumbs Up!

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Rainer and everyone,
      Thank you for the quick response. Having said this, I was able to solve this one following the below manner.
       
      Regards,
      Anand

       

      Step one: Create parameters for client_id, client_secret, oauth token, search url, username, password
      Step two: a new query with the following

       

      let
          //App Details
          client_id = #"API Key", //<===parameter
          client_secret = #"API Secret", //<===parameter
          
          //Authentication
          
          //URI's
          token_uri = #"Token URL", //<===parameter
          resource =  #"Search URL", //<===parameter
          
          //User Details  
          username = username, //<===parameter
          password = password, //<===parameter
            
         tokenResponse = Json.Document(Web.Contents(token_uri,          
                                      [
                                          Content=
                                          Text.ToBinary(Uri.BuildQueryString(
                                          [
                                              client_id = client_id
                                              ,client_secret=client_secret
                                              ,username=username
                                              ,password=password
                                              ,resource=resource
                                              ,grant_type = "password"
                                              
                                          ]))
                                          ,Headers=
                                              [Accept="application/json"]
                                              , ManualStatusHandling={400}
                                      ])),
                                      access_token = tokenResponse[access_token],
          token = "Bearer " & tokenResponse[access_token],
       GetJsonQuery = Web.Contents("[search url]",
           [
               Headers = [#"Authorization"=token]
           ]
       ),
      FormatAsJsonQuery = Json.Document(GetJsonQuery)
       
      in
       
      FormatAsJsonQuery

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous , 

         

        I tried making API call using the provided query after creating the required parameters.

         

        Only change I did is -

        grant_type = "client_credentials"

         

        I am getting below error - 

         

         

        P.S - I tried using other methods as well, I am getting same error whichever query I use. Please suggest what am I doing wrong. 

        Thanks in advance.