Quantcast
Channel: Topliners: Message List
Viewing all articles
Browse latest Browse all 3737

HTTP 400 exception at REST API POST method

$
0
0

Hello everyone,

 

I am trying to create few assets like emails, campaigns, landing pages etc using the JAVA REST API.

GET() works fine but POST,PUT and DELETE does not work for me.

 

Here is my Service class. Please help me to debug and fix the error.

 

public void CreateEmail(Email email) {

 

  try {

  Gson gson = new Gson();

  String json = gson.toJson(email);

 

  //POST :  /assets/email

  Response response = getClient().post("/assets/email",json );

  System.out.println(response.statusCode + " status >> exception :: "+ response.exception);

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

 

public void UpdateEmail(Email email) {

 

  try {

  Gson gson = new Gson();

  String json = gson.toJson(email);

 

  //PUT :  /assets/email/{id}

  Response response = getClient().put("/assets/email"+String.valueOf(55),json );

  System.out.println("updated :: "+json);

  System.out.println(response.statusCode + " status >> exception :: "+ response.exception);

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

 

  public void DeleteEmail(int id) {

  try {

  // DELETE :  /assets/email/{id}

  getClient().delete("/assets/email"+ String.valueOf(id) );

  System.out.println("deleted email of id :: "+ id );

  } catch (Exception e) {

  e.printStackTrace();

  }

  }


Viewing all articles
Browse latest Browse all 3737