0

I am having a problem using WordPress's wp_remote_post() function with Redmine's REST API. The main issue is that when I attempt to post, i get a 403 - forbidden return.

This is the code that i'm working with:

$info = array(
    'issue' => array(
        'key' => '59930c6460e8e71ef58b4cc95d852153bf21b510',
        'subject' => 'New bug from ' . get_bloginfo('name') . ' (' . get_bloginfo('wpurl') . ')',
        'project_id' => 10,
        'tracker_id' => 1,
        'description' => $_POST['bug_contents'],
        'custom_fields' => array(
            array(
                'name' => 'Web Server Version',
                'id' => 1,
                'value' => $_SERVER['SERVER_SOFTWARE'],
            ),
            array(
                'name' => 'PHP Version',
                'id' => 2,
                'value' => phpversion(),
            ),
            array(
                'name' => 'MySQL Version',
                'id' => 3,
                'value' => $wpdb->get_var( "SELECT VERSION( ) as `version`" ),
            ),
            array(
                'name' => 'WordPress Version',
                'id' => 4,
                'value' => $wp_version,
            ),
            array(
                'name' => 'WordPress Admin Email',
                'id' => 5,
                'value' => get_bloginfo('admin_email'),
            ),
            array(
                'name' => 'Server IP',
                'id' => 6,
                'value' => $_SERVER['SERVER_ADDR'],
            ),
            array(
                'name' => 'Server External IP',
                'id' => 7,
                'value' => $ip_feedback_array['origin'],
            ),
        ),
    ),
);

$api_call = wp_remote_post(
    'https://ias:1q2w3e$r@rm.14all.me/issues.json',
    array(
        'method' => 'POST',
        'timeout' => 45,
        'redirection' => 5,
        'httpversion' => '1.0',
        'blocking' => true,
        'headers' => array(
            'Content-Type' => 'application/json',
            //'Authorization' => 'Basic ' . base64_encode( 'ias' . ':' . '1q2w3e$r' ),
            'X-Redmine-API-Key' => '59930c6460e8e71ef58b4cc95d852153bf21b510'
            ),
        'cookies' => array(),
        'body' => json_encode($info),
    )
);

However the response that I recieve is:

Array
(
    [headers] => Array
        (
            [server] => cloudflare-nginx
            [date] => Wed, 30 Apr 2014 15:07:58 GMT
            [content-type] => application/json; charset=utf-8
            [connection] => close
            [set-cookie] => Array
                (
                    [0] => __cfduid=dd5dfb36ec5e73c40e7eb94ba34ab8ece1398870478439; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.14all.me; HttpOnly
                    [1] => _redmine_session=BAh7BiIPc2Vzc2lvbl9pZCIlOWU4NWRlOWRjMGNiNDczZWI2YzU1NGE2MTlkMTc4NjI%3D--2396b75554bde9fbe8a15870b0e3861687968094; path=/; HttpOnly
                    [2] => autologin=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
                )

            [x-runtime] => 0.048408
            [cache-control] => no-cache
            [x-ua-compatible] => IE=Edge,chrome=1
            [x-rack-cache] => invalidate, pass
            [x-request-id] => 9dcd72c966f6434914e2b65ae706bb30
            [x-powered-by] => Phusion Passenger 4.0.10
            [status] => 403 Forbidden
            [cf-ray] => 1234a6ea3ce9014b-CDG
            [content-encoding] => gzip
        )

    [body] =>  
    [response] => Array
        (
            [code] => 403
            [message] => Forbidden
        )

    [cookies] => Array
        (
            [0] => WP_Http_Cookie Object
                (
                    [name] => __cfduid
                    [value] => dd5dfb36ec5e73c40e7eb94ba34ab8ece1398870478439
                    [expires] => 1577145000
                    [path] => /
                    [domain] => .14all.me
                    [httponly] => 
                )

            [1] => WP_Http_Cookie Object
                (
                    [name] => _redmine_session
                    [value] => BAh7BiIPc2Vzc2lvbl9pZCIlOWU4NWRlOWRjMGNiNDczZWI2YzU1NGE2MTlkMTc4NjI=--2396b75554bde9fbe8a15870b0e3861687968094
                    [expires] => 
                    [path] => /
                    [domain] => rm.14all.me
                    [httponly] => 
                )

            [2] => WP_Http_Cookie Object
                (
                    [name] => autologin
                    [value] => 
                    [expires] => 0
                    [path] => /
                    [domain] => rm.14all.me
                )

        )

    [filename] => 
)

I assume that there's an issue with how i'm sending the authentication parameters. Any help is appreciated.

  • Use curl to do the same thing and see if it returns 200 OK. Did you enable REST API as outlined here - redmine.org/projects/redmine/wiki/Rest_api#Authentication You can also use this online curl tool - hurl.it – A.Jesin Apr 30 '14 at 15:55
  • i don't want to use cURL for cross server compatibility reasons. the wp_remote_post() function was designed to replace cURL in for a lot of reasons, including speed and fall-back options. The REST api has been enabled though. What feedback did you receive from cURL when you tried? – bdb.jack Apr 30 '14 at 15:59
  • 1
    I meant the curl command line tool. Use it to test if your credentials and POSTed data are in right shape before doing it in WordPress – A.Jesin Apr 30 '14 at 16:01
  • it seems to work perfectly via curl on the server. maybe there's an issue with how i'm trying to pass my custom headers with the wp_remote_post() function? – bdb.jack Apr 30 '14 at 16:03
  • Can you edit the question and add the curl sample? It will be easier to guide. – A.Jesin Apr 30 '14 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.