Re: Adding rich text on web-form using REST API

Amit_Jain
Level 8 - Community Advisor

Adding rich text on web-form using REST API

Hi There,

I have to add a rich text on all the form. I was trying to the same using the REST API but getting following error in response:

{"success":false,"errors":[{"message":"label cannot be null","code":"701"}],"requestId":"11658#16971c2c33e","warnings":[]}

Following is my payload and end point URL:

var url = 'https://'+munckin_Id+'.mktorest.com/rest/asset/v1/form/' + formId + '/richText.json?access_token=' + access_token

var options = {

'method': 'post',

'contentType': 'x-www-form-urlencoded',

'addRichTextRequest': {

'text':'Hey this is from API',

}

};

according to the doc we don't need to add label any where not sure why I'm getting this error. Following the developer doc URL

http://developers.marketo.com/rest-api/endpoint-reference/asset-endpoint-reference/#!/Form_Fields/ad...

Thank you for your help in advance.

Regards,

Amit

Tags (3)
7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Adding rich text on web-form using REST API

"addRichTextRequest" is just the JSON schema type. It has no inherent meaning in your app unless you have some kind of schema binding, and it doesn't appear in the the JSON payload. Only the text property appears.

{

"text" : "Text Goes Here"

}

Also, please don't supply anything language-specific because we have no idea what the rest of your code looks like, what HTTP library you're using, etc. The only thing that ever matters with a REST API is the final JSON that goes on the wire.

Amit_Jain
Level 8 - Community Advisor

Re: Adding rich text on web-form using REST API

Thank you for your reply Sanford Whiteman​!

I tried following but still getting the same error:

var options = {

'method': 'post',

'text':'Hey this is from API'

};

Is this what you mean or I'm still doing something wrong?

I do not have any standard setup to develop the app. I'm actually using Google App script here.

Thank again for your reply!

Regards,
Amit

SanfordWhiteman
Level 10 - Community Moderator

Re: Adding rich text on web-form using REST API

What exactly is going on the wire? You need to show the HTTP request exactly as-is.

Amit_Jain
Level 8 - Community Advisor

Re: Adding rich text on web-form using REST API

Here is the extract from the execution log for your reference:

[19-03-12 23:32:29:929 PDT] HTTPResponse.getContentText() [0 seconds]

[19-03-12 23:32:30:251 PDT] UrlFetchApp.fetch([https://xxx-xxx-xxx.mktorest.com/rest/asset/v1/form/11633/richText.json?access_token=<access_token>, {method=post, text=Hey this is from API}]) [0.322 seconds]

Regards,
Amit

SanfordWhiteman
Level 10 - Community Moderator

Re: Adding rich text on web-form using REST API

Nope, that's not JSON. That's an application log. Again, you need to control your debugging setup. You need to be able to show exactly what JSON you put on the wire, with which HTTP headers. This is a basic prerequisite to consuming an API.

This is a REST API question, not a whatever-language-and-framework-you-happen-to-be-using question!

Amit_Jain
Level 8 - Community Advisor

Re: Adding rich text on web-form using REST API

Thank you Sanford. It's helpful!

MARKeto
Level 1

Re: Adding rich text on web-form using REST API

Hi Amit,

 

I'm having the same issue as you, did you manage to figure out what was wrong?

                PostURL = host + "/rest/asset/v1/form/" + id + "/richText.json?" + qs.ToString();

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(PostURL);
                request.Method = "POST";
                string boundary = "--mktoBoundary" + DateTime.Now.Ticks.ToString("x");
                request.ContentType = "multipart/form-data; boundary=" + boundary;
                var wr = new StreamWriter(request.GetRequestStream());
                wr.Write("--" + boundary + "\\r\\n");
                wr.Write("Content-Disposition: form-data; name=\"text\"\\r\\n");
                wr.Write("Content-type: text/html; charset=\"utf-8\"\\r\\n");
                wr.Write("<div>content</div>" + "\\r\\n");
                wr.Write("--" + boundary + "--");
                wr.Flush();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream resStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(resStream);

 I get error 701 "label cannot be null"