Support » Plugin: CF7 to Webhook » Additional Headers

  • Resolved kpeu3e

    (@kpeu3e)


    Hello,

    I am trying to integrate CF7 with a third-party app. They require the contact form to send them this information:

    curl -X “POST” “https://api.mariner.yembo.ai/initial-params” \
    -H ‘Content-Type: application/json’ \
    -H ‘X-Landing-Page-Access-Token: your-value-here ‘ \
    -d $'{
    “move”: {
    “date”: “2018-09-01”
    },
    “consumer”: {
    “givenName”: “Joe”,
    “phone”: “5550001234”,
    “email”: “jschmo@example.com”,
    “familyName”: “Schmo”
    },
    “origin”: {
    “zip”: 12345,
    “beds”: 3
    },
    “destination”: {
    “zip”: 90210
    }
    }’

    I think some part of this request is clear, but I am not sure how to add these

    curl -X “POST” “https://api.mariner.yembo.ai/initial-params” \
    -H ‘Content-Type: application/json’ \
    -H ‘X-Landing-Page-Access-Token: your-value-here ‘ \
    -d $'{
    “move”: {
    “date”: “2018-09-01”
    },

    I have the token here, but I am not sure how to insert those headers. Would you please help me?

    Thanks!

    • This topic was modified 3 months, 3 weeks ago by kpeu3e.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mário Valney

    (@mariovalney)

    Hi.

    You can add custom headers this way:
    https://wordpress.org/support/topic/headers-7-authentication/

    Hi Mario,

    thank you very much for your reply!

    I saw that topic, but still it is not very clear for me.

    I added this as the webhook URL:
    https://api.mariner.yembo.ai/initial-params

    and this to functions.php

    add_filter( 'ctz_post_request_args', 'oilbanker_ctz_post_request_args' );
    function oilbanker_ctz_post_request_args( $args ) {
        $args['headers']['X-Landing-Page-Access-Token: my-token-here'] = 'value';
    
        return $args;
    }

    now, do I need to also add something about these two?

    -H ‘Content-Type: application/json’ \
    -d $'

    and if yes, how to add multiple headers? This way?

    add_filter( 'ctz_post_request_args', 'oilbanker_ctz_post_request_args' );
    function oilbanker_ctz_post_request_args( $args ) {
        $args['headers']['X-Landing-Page-Access-Token: my-token-here'] = 'value';
    $args['headers']['Content-Type: application/json'] = 'value';
    
        return $args;
    }

    Also, is there a way I could test if it is working in the end?

    Thank you!

    • This reply was modified 3 months, 3 weeks ago by kpeu3e.
    Plugin Author Mário Valney

    (@mariovalney)

    I guess you don’t need to add Content-Type header. And your custom header is not ok. Just add to your functions.php:

    <?php
    
    add_filter( 'ctz_post_request_args', 'kpeu3e_ctz_post_request_args' );
    function kpeu3e_ctz_post_request_args( $args ) {
        $args['headers']['X-Landing-Page-Access-Token'] = 'your-value-here';
    
        return $args;
    }

    The array key (X-Landing-Page-Access-Token) is the header name and the value is the header’s value.

    Note: please, use code tag to make your code more readable on forum.

    • This reply was modified 3 months, 3 weeks ago by Mário Valney.

    Thanks, Mario.

    And does the plugin provide an option to use custom JSON template, or is it only predefined?
    For example if I want to exclude some fields.

    Thanks.

    • This reply was modified 3 months, 2 weeks ago by kpeu3e.
    Plugin Author Mário Valney

    (@mariovalney)

    In the same way, you can use the ctz_get_data_from_contact_form filter to change data provided by form or even the ctz_post_request_args again.

    For example:

    <?php
    
    add_filter( 'ctz_post_request_args', 'kpeu3e_ctz_post_request_args' );
    function kpeu3e_ctz_post_request_args( $args ) {
        $args['headers']['X-Landing-Page-Access-Token'] = 'your-value-here';
    
        $data = json_decode( $args['body'] );
        // Your code
        $args['body'] = json_encode( $data );
    
        return $args;
    }

    Thanks!

    Great plugin and great support!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.