• Resolved logicred

    (@logicred)


    I have been given a JSON endpoint, but need to pass it two POST parameters and a query. I know your plugin supports the resulting JSON import, but is there any way I can pass it these params to generate the resulting JSON?

Viewing 1 replies (of 1 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @logicred

    You should be able to write some custom code that uses the http_api_curl() hook to do this. Here’s an untested example that you can modify as needed:

    // POST parameters when fetching feed
    add_action( 'http_api_curl', 'my_curl_set_opts', 10, 3 );
    
    function my_curl_set_opts( $handle, $r, $url ) {
        if ( $url == 'https://example.com/jsonfeed' ) {
            $data = array(
                'client'            => 'CUSTOMER CODE',
                'login'             => 'LOGIN',
                'pass'              => 'PASSWORD'
            );
    
            $post_params = '';
            foreach ( $data as $pn => $pv ) {
                $post_params .= ( $post_params == '' ? '' : '&' ) . $pn . '=' . urlencode( $pv );
            }
            curl_setopt( $handle, CURLOPT_POST, true );
            curl_setopt( $handle, CURLOPT_POSTFIELDS, $post_params );
            curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
            // Optional below (disable host/peer verification in case of SSL errors)
            // curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, false );
            // curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, 0 );
        }
    }
Viewing 1 replies (of 1 total)

The topic ‘JSON – Passing a query’ is closed to new replies.