简体   繁体   English

使用 RestSharp 将 JSON 数据从 Logic App 发送到 Function App 到 Eloqua

[英]Sending JSON data from Logic App to Function App to Eloqua with RestSharp

I'm trying to make a Function App that takes JSON data from a Logic App and then sends it to Eloqua API.我正在尝试制作一个 Function 应用程序,该应用程序从逻辑应用程序获取 JSON 数据,然后将其发送到 Eloqua API。

I've been using the Eloqua documentation in order to set it up.我一直在使用Eloqua 文档来设置它。

However, I am getting in to problems.但是,我遇到了问题。

I seem to not get any data from my Logic App or be able to parse the URL you get from the first OAuth2 url you send.我似乎没有从我的逻辑应用程序中获取任何数据,或者无法解析从您发送的第一个 OAuth2 url 获得的 URL。

I'm wondering if anyone knows what mistakes I've made as I'm kind of a junior on this and not entirely sure what I did wrong.我想知道是否有人知道我犯了什么错误,因为我在这方面有点初级,并不完全确定我做错了什么。

This is the code that I am using for my Function App: Main function这是我用于 Function 应用程序的代码: Main function

/*
             * Sets up the needed variables for sending to Eloqua
             */
            string clientSecreat = "xxxxx";
            var authentication = System.Text.Encoding.UTF8.GetBytes(clientSecreat);
            string getJson = req.GetQueryNameValuePairs()
                            .FirstOrDefault(q => string.Compare(q.Key, "Body", true) == 0)
                            .Value;

            /*
             * Starts by calling to get token for Oauth2
             */
            var client = new RestClient("https://login.eloqua.com/auth/oauth2/authorize?");
            var request = new RestRequest(Method.GET);
            var queryResult = client.Execute<Token>(request);
            //log.Info(queryResult.ToString());


            client = new RestClient("https://login.eloqua.com/auth/oauth2/token");
            request = new RestRequest(Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Authorization", "Basic " + authentication);
            request.AddJsonBody("grant_type: ", "authorization_code");
            request.AddJsonBody("code: " + queryResult);
            request.AddJsonBody("redirect_uri: ", "redirect_url");
            var response = await client.ExecuteAsync<AccessToken>(request);
            log.Info(response.ToString());

            /*
             * Posts the Logic App parsed JSON data
             */
            client = new RestClient("https://secure.p06.eloqua.com/API/Bulk/2.0/customObjects/377/imports/1904470/data");
            request = new RestRequest(Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Content_Type: ", "application/json");
            request.AddHeader("Authorization: ", "Basic " + response);
            request.AddJsonBody(getJson);
            var execute = await client.ExecuteAsync(request);

            return req.CreateResponse("Success");

Token.cs:令牌.cs:

public class Token
{

    [JsonProperty("code")]
    public string code { get; set; }


}

AccessToken.cs:访问令牌.cs:

    public class AccessToken
{
    [JsonProperty("access_token")]
    public string access_token { get; set; }
}

Thank you in advance.先感谢您。

If you want to use resource owner password credentials grant flow, please refer to the following rest API如果要使用资源所有者密码凭证授予流程,请参考以下 rest API


POST https://login.eloqua.com/auth/oauth2/token
Authorization: Basic <base64 encode string client_id:client_secret>
{
   "grant_type":"password",
   "scope":"full",
   "username":"testsite\\testuser",
   "password":"user123"
}
                

code代码

var authentication = Convert.ToBase64String(Encoding.UTF8.GetBytes("client_id:client_secret"));
client = new RestClient("https://login.eloqua.com/auth/oauth2/token");
            request = new RestRequest(Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Authorization", "Basic " + authentication);
            ....body
            var response = await client.ExecuteAsync<AccessToken>(request);
            log.Info(response.ToString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM