2

このリードの作成/更新 API ( http://developers.marketo.com/documentation/rest/createupdate-leads/ ) について質問があります。C# または JAVA のサンプル コードはありません。ルビーのみ使用可能。だから私は自分でそれを試してみる必要があります。しかし、私は常に応答から null を返します。これが私のコードです:

private async Task<CreateLeadResponseResult> CreateLead(string token)
    { 

        string url = String.Format(marketoInstanceAddress+"/rest/v1/leads.json?access_token={0}", token);
        var fullUri = new Uri(url, UriKind.Absolute);
        CreateLeadResponseResult createLeadResponse = new CreateLeadResponseResult();
        CreateLeadInput input = new CreateLeadInput { email = "123@123.com", lastName = "Lee", firstName = "testtesttest", postCode = "00000" };
        CreateLeadInput input2 = new CreateLeadInput { email = "321@gagaga.com", lastName = "Lio", firstName = "ttttttt", postCode = "00000" };
        List<CreateLeadInput> inputList = new List<CreateLeadInput>();
        inputList.Add(input);
        inputList.Add(input2);

        CreateLeadRequest createLeadRequest = new CreateLeadRequest() { input = inputList };
        JavaScriptSerializer createJsonString = new JavaScriptSerializer();
        string inputJsonString = createJsonString.Serialize(createLeadRequest);

       using (var client = new HttpClient())
        {

            HttpResponseMessage response = await client.PostAsJsonAsync(fullUri.OriginalString, inputJsonString).ConfigureAwait(false);
            // I can see the JSON string is in the message body in debugging mode.

            if (response.IsSuccessStatusCode)
            {
                createLeadResponse = await response.Content.ReadAsAsync<CreateLeadResponseResult>();
            }
            else
            {
                if (response.StatusCode == HttpStatusCode.Forbidden)
                    throw new AuthenticationException("Invalid username/password combination.");
                else
                    throw new ApplicationException("Not able to get token");
            }
        }

       return createLeadResponse;}
       //get null here.

ありがとうございました。-C.

4

2 に答える 2

1

これをデバッグする最善の方法は、アプリによって送信された正確な URL、パラメーター、および JSON を取得し、Postman (Chrome プラグイン) や SOAP UI などのツールを介して手動で送信することです。次に、正確なエラー メッセージが表示されます。これは、http: //developers.marketo.com/documentation/rest/error-codes/で確認できます。それに基づいて、コードを更新できます。私は Java についてあまり知りませんが、これが私の Python コードを機能させる方法です。

于 2015-04-26T16:26:31.920 に答える