inwx/java-client

Create Contact call does not work

j-freimuth opened this issue · 5 comments

I am trying to use the java client in a scala application.

What happens:
Login works. Create contact doesn't work. Error message 2400 - Command failed is returned.

Expected behaviour:
Contact will be created.

My Code:

  private val username = settings.inwx.username
  private val password = settings.inwx.password
  private val url = if (settings.inwx.live) ApiClient.LIVE_URL else ApiClient.OTE_URL
  private val debugMode = settings.inwx.debugMode

  /**
   * Create a new INWX contact
   * Compare https://github.com/inwx/java-client
   *
   * @return
   */
  def createInwxContact(userEntity: UserEntity): Unit = {

    val client: ApiClient = new ApiClient(url, debugMode)

    val loginResponse: BasicResponse = client.login(username, password)

    if (!loginResponse.wasSuccessful) {

      throw new Exception("INWX login failed")
    }

    val requestParameters: JsonObject = new JsonObject
    requestParameters.addProperty("type", "PERSON")
    requestParameters.addProperty("name", s"${userEntity.name}".trim)
    requestParameters.addProperty("street", s"${userEntity.street.map(_.value).get}")
    requestParameters.addProperty("city", s"${userEntity.city.map(_.value).get}")
    requestParameters.addProperty("pc", s"${userEntity.postalCode.map(_.value).get}")
    requestParameters.addProperty("cc", s"${userEntity.countryCode.map(_.value).get}")
    requestParameters.addProperty("voice", s"+49.${userEntity.phone.map(_.value).get}")
    requestParameters.addProperty("email", s"${userEntity.email.value}")

    val response: BasicResponse = client.callApi("contact.create", requestParameters)

    if (!response.wasSuccessful) {

      client.logout
      throw new Exception("INWX user couldn't be created")
    }

    client.logout

    ()
  }

Logfile:

Request (account.login): {
   "method": "account.login",
   "params": {
     "user": "myCompany",
     "pass": "myPassword"
   }
 }
 Response (account.login): {
   "code": 1000,
   "msg": "Command completed successfully",
   "resData": {
     "customerId": 00000, // id changed for privacy
     "accountId": 00000, // id changed for privacy
     "tfa": "0",
     "builddate": "2017",
     "version": "1"
   }
 }
 Request (contact.create): {
   "method": "contact.create",
   "params": {
     "type": "PERSON",
     "name": "Test User",
     "street": "MyStreet",
     "city": "MyCity",
     "pc": "MyPostalCode",
     "cc": "MyCountryCode",
     "voice": "+1.23324",
     "email": "developer@myDomain.com",
     "forceNew": true
   }
 }
 Response (contact.create): {
   "code": 2400,
   "msg": "Command failed"
 }

Taking the request parameters from the debug log and plugging them into postman works just fine, even if this strange formatting for voice seems to be required, which is not in the documentation or the ajax endpoint.

Might also be interesting: The check domain endpoint does work with this client. I have not tried any other endpoints so far.

Hey, I tried to reproduce your problem but could not find any problem on my first try. I also tried your example with the correct values for cc, pc and city and it worked too.

JsonObject requestParameters = new JsonObject();
requestParameters.addProperty("type", "PERSON");
requestParameters.addProperty("name", "Test User");
requestParameters.addProperty("street", "MyStreet");
requestParameters.addProperty("city", "Berlin");
requestParameters.addProperty("pc", "10969");
requestParameters.addProperty("cc", "DE");
requestParameters.addProperty("voice", "+1.23324");
requestParameters.addProperty("email", "developer@myDomain.com");
requestParameters.addProperty("forceNew", true);
Request (account.login): {
  "method": "account.login",
  "params": {
    "user": "redacted",
    "pass": "redacted"
  }
}
Response (account.login): {
  "code": 1000,
  "msg": "Command completed successfully",
  "resData": {
    "customerId": redacted,
    "accountId": redacted,
    "tfa": "0",
    "builddate": "2017",
    "version": "1"
  }
}
Request (contact.create): {
  "method": "contact.create",
  "params": {
    "type": "PERSON",
    "name": "Test User",
    "street": "MyStreet",
    "city": "Berlin",
    "pc": "10969",
    "cc": "DE",
    "voice": "+1.23324",
    "email": "developer@myDomain.com",
    "forceNew": true
  }
}
Response (contact.create): {
  "code": 1000,
  "msg": "Command completed successfully",
  "resData": {
    "id": redacted
  }
}
Request (account.logout): {
  "method": "account.logout"
}
Response (account.logout): {
  "code": 1500,
  "msg": "Command completed successfully; ending session"
}

Maybe your values are not correct or known, especially city, pc and cc?

Thank you for your speedy reply.

I tried your data and it did work. You were right, my original test for the field street had UTF-8 characters, namely the German 'sz' character 'ß' and the German umlaut o character 'ö'. If those are sent within the street and presumably in any other field, it will respond with a 2400 error code.

Still, my tests with Postman and these character were successful, so it has to be a bug somewhere within the library and not the API. Maybe it is transformed somewhere to ASCII?

Yeah it is an encoding issue I could reproduce it. The client doesn't encode the request as UTF-8. There will be a fix within the next hours 👍

You should now be able to use version 3.1.1 from maven central.

Thank you for helping us. 🥇