Title: Line breaks break API
Last modified: January 17, 2018

---

# Line breaks break API

 *  Resolved [tecumseh](https://wordpress.org/support/users/tecumseh/)
 * (@tecumseh)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/line-breaks-break-api/)
 * Hey,
 * Love the plugin but came across a problem, if line breaks are contained within
   the message/if the message is quite large then the API fails to send a POST to
   my endpoint (using JSON).
 * I’d appreciate any pointers, thanks.

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Qube One ltd](https://wordpress.org/support/users/querysolutions/)
 * (@querysolutions)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/line-breaks-break-api/#post-9885231)
 * Please add the JSON you are using
 *  Thread Starter [tecumseh](https://wordpress.org/support/users/tecumseh/)
 * (@tecumseh)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/line-breaks-break-api/#post-9888535)
 * `{"body": {"name":"[your-name]", "email":"[your-email]", "subject":"[your-subject]","
   your-message":"[your-message]"}}`
 * I know the fields are already contained within the body, but my api expects.
 *     ```
        },
           "body": {
               "body": {
       ```
   
 * Removing the additional “body” from the JSON template I am using also causes 
   the issue to persist.
 * In my attempts to fix it, I did attempt using nl2br, that allowed the POST to
   be sent to my api but was invalid JSON.
 *  Plugin Author [Qube One ltd](https://wordpress.org/support/users/querysolutions/)
 * (@querysolutions)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/line-breaks-break-api/#post-9889832)
 * I see no problem with the code you added
    please send me your contact details
   here: [http://querysol.com/contact/](http://querysol.com/contact/)
 * I will need your ftp details in order to check what is wrong
 *  Thread Starter [tecumseh](https://wordpress.org/support/users/tecumseh/)
 * (@tecumseh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/line-breaks-break-api/#post-10053344)
 * Sorry about the delay, I’ve been ill for a while.
 * As you can imagine I’d like to avoid handing out access to my server unless absolutely
   necessary, sorry.
 * Can you confirm that the following use cases work in your own environment?
 * 1 – Adding new lines to your message in the form, does the API sanitize these?
   
   2 – Single quotes/double quotation marks – a combination of these tends to cause
   issues if within the message body.
 * (I just want to know if it’s my slightly weird JSON template causing issues :/)
 * I added something like this to the string in the parse_json function to fix line
   breaks
 *     ```
       trim( preg_replace( '/(\r\n)|\n|\r/', '\\n', $string))
       ```
   
 * Which worked and allowed large datasets to be sent & fixed line breaks.
 *  Thread Starter [tecumseh](https://wordpress.org/support/users/tecumseh/)
 * (@tecumseh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/line-breaks-break-api/#post-10065754)
 * So I reinstalled everything to get rid of my changes and switched to using a 
   more normal template.
 * I can confirm that multiple line breaks in the message means the message **do**
   not get sent by the API.
 * Also,
 * A message containing this: “” Did I just break you? “”
 * would lead the API to send: “message”: “\”\” Did I just break you? \”\” ”
 * CF7 does clean up the message before emailing it, is it not possible to retrieve
   the submission after it’s been formatted?
 *  Plugin Author [Qube One ltd](https://wordpress.org/support/users/querysolutions/)
 * (@querysolutions)
 * [8 years ago](https://wordpress.org/support/topic/line-breaks-break-api/#post-10237698)
 * You can manipulate the data that is being sent using this filter
    There you can
   do whatever you like with the request
 * For example:
    add_filter( ‘qs_cf7_api_get_args’ , ‘change_the_json_structure’);
 * function change_the_json_structure( $args ){
    $json = $args[‘body’]; $json = 
   stripslashes( $json ); $args[‘body’] = $json; //this will probably break the 
   json because in your example the json is escaped correctly //dont forget to return
   the args return $args; }

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Line breaks break API’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/cf7-to-api.svg)
 * [Contact form 7 TO API](https://wordpress.org/plugins/cf7-to-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cf7-to-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cf7-to-api/)
 * [Active Topics](https://wordpress.org/support/plugin/cf7-to-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cf7-to-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cf7-to-api/reviews/)

## Tags

 * [json](https://wordpress.org/support/topic-tag/json/)
 * [line breaks](https://wordpress.org/support/topic-tag/line-breaks/)

 * 6 replies
 * 2 participants
 * Last reply from: [Qube One ltd](https://wordpress.org/support/users/querysolutions/)
 * Last activity: [8 years ago](https://wordpress.org/support/topic/line-breaks-break-api/#post-10237698)
 * Status: resolved