Jump to content

REST, creating a member with a special char in username


Daniel Wolf

Recommended Posts

Posted

Hi,

I am using the REST-API to create members on demand. It is kind of a data-transfer from another community-database.
Everything is working fine, until I get an user with a special char in it's name - let's say "Gérome". The API creates a user called "G", everything starting from the special char is truncated. If I understood correctly, the function "http_build_query" should encode the data accordingly.

Manually creating an user with this name works as expected.

Anyone having an idea what is missing here?

    $querydata = array(
	'name' => 'Gérome',
	'password' => 'test123',
    );

    $curl = curl_init( $communityUrl . 'api' . $endpoint );
    curl_setopt_array( $curl, array(
	CURLOPT_RETURNTRANSFER	=> TRUE,
	CURLOPT_POST		=> 1,
	CURLOPT_HTTPAUTH	=> CURLAUTH_BASIC,
	CURLOPT_POSTFIELDS	=> http_build_query($querydata),
	CURLOPT_USERPWD		=> "{$apiKey}:"
    ) );
    $response = curl_exec( $curl );

best regards,
  Dany

Posted

http_build_query turns that into

name=G%C3%A9rome&password=test123

which appears to be correct on the surface. I cannot see any problem on the surface, and indeed my test worked just fine:

<?php

$apiKey = '__masked__';

require 'init.php';
\IPS\Dispatcher\External::i();

$response = \IPS\Http\Url::external( \IPS\Settings::i()->base_url . '/api/index.php?/core/members' )
	->request()
	->login( $apiKey, '' )
	->post( array( 'name' => 'Gérome', 'password' => 'test123', 'email' => 'gerome@test.com' ) )
	->decodeJson();

var_dump($response);
exit;

I've verified that our CURL class essentially just does the same thing (runs the values through http_build_query) to format the values.

What encoding is your core_members database table, and the 'name' column in it? Perhaps it's utf8 but needs to be utf8mb4?

Posted

Hi,

thank you for taking time to answer my question. First of all it's good news that my approach is not completely wrong. 😉

The database encoding is "utf8mb4_unicode_ci", i just checked: The column "name" of the members-table has the same encoding. As fas as I know I got the recommendation for this encoding from one of your support-topics. I will investigate further.

best regards,
  Dany

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...