HTTP/1.1 415 Unsupported Media Type/ Update developer

Not applicable

I am trying to update a developer data from a wordpress website. I created a plugin for that and a template page. The data is updating on Wordpress but as a response i got HTTP/1.1 415 Unsupported Media Type/ from Apigee.

I assume there is nothing wrong with the template page, because the data is updating on WordPress.SO I am not going to add my code for the template Probably the way I PUT the data is not correct but I am not pretty sure about that.

Could you have a look???

<?php

/*
  Plugin Name: Update
  Description: Update dev
  Version: 1.1
  Author: Vanina
 */

function do_update(){
$current_user = wp_get_current_user();
 
    $current_user = wp_get_current_user();
    if ( !($current_user instanceof WP_User) )
         return;

//create a recourse link	
$urlbegin='https://api.enterprise.apigee.com/v1/organizations/orgtrial/developers/';
$varemail= $current_user->user_email ;
$url= $urlbegin.$varemail;


$arg_data = array('email'=> $_POST['user_email'],  "firstName" =>$_POST['first_name'], "lastName" => $_POST['last_name'] , "userName" =>  $_POST['user_login']  );

$data = json_encode( $arg_data );
$args = array(
     'method' => 'PUT','headers'=> array( 'Authorization' => 'Basic xyzxxxxxzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),'body'=> $data);
$response = wp_remote_request( esc_url_raw($url), $args );
	
	if ( is_wp_error( $response ) ) {
    $error_message = $response->get_error_message();
    echo "Something went wrong: $error_message";
     }  else {
   echo 'Response:<pre>';
   print_r( $response );
    echo '</pre>';
   
	 } 
}

add_action('profile_update','do_update');
?>


//RESPONSE: 


[cookies] => Array
        (
        )

    [filename] => 
    [http_response] => WP_HTTP_Requests_Response Object
        (
            [response:protected] => Requests_Response Object
                (
                    [body] => 
                    [raw] => HTTP/1.1 415 Unsupported Media Type
Date: Wed, 15 Nov 2017 12:35:50 GMT
Server: Apigee LB
Content-Length: 0
Connection: Close



Solved Solved
0 2 2,026
1 ACCEPTED SOLUTION

Hi Vanina,

Can you try this?:

$args = array(
     'method' => 'PUT',
     'headers'=> array('Authorization' => 'Basic xyzxxxxxzxxxxxxxxxxxxxx',
                       'Content-type' => 'application/json'),
     'body'=> $data);


Just add an additional header to the list: Content-type.

The 415 response status code indicates that whatever you sent was not the right content-type. And it looks to me that you haven't specified a content-type at all.

That Apigee Edge API accepts XML as well as JSON, so you need to be specific with the Content-Type header.

View solution in original post

2 REPLIES 2

Hi Vanina,

Can you try this?:

$args = array(
     'method' => 'PUT',
     'headers'=> array('Authorization' => 'Basic xyzxxxxxzxxxxxxxxxxxxxx',
                       'Content-type' => 'application/json'),
     'body'=> $data);


Just add an additional header to the list: Content-type.

The 415 response status code indicates that whatever you sent was not the right content-type. And it looks to me that you haven't specified a content-type at all.

That Apigee Edge API accepts XML as well as JSON, so you need to be specific with the Content-Type header.

Hello,

 

I am facing the same issue in APIGEE edge . The target team confirmed they sent back 200 responses to Apigee. But APIGEE is showing a 415 error. It's happening intermittently. I am setting the header as below. Not sure where is the issue. could you please help here.

 

Vignesh0808_0-1682527511678.png