• Resolved tecumseh

    (@tecumseh)


    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

    (@querysolutions)

    Please add the JSON you are using

    Thread Starter tecumseh

    (@tecumseh)

    {"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

    (@querysolutions)

    I see no problem with the code you added
    please send me your contact details here:
    http://querysol.com/contact/

    I will need your ftp details in order to check what is wrong

    Thread Starter tecumseh

    (@tecumseh)

    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

    (@tecumseh)

    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

    (@querysolutions)

    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.