0

I am trying to add contacts to Constant Contact account using V3 API. Some user data contain accent characters, when I add these it is showing as unicode characters in constant contact account.

For example First name is GÒKÜL and last name is NÁTH. It is showing in constant contact as Gu00d2Ku00dcL and Nu00c1TH. I want to show these as original.

I think issue is in my curl function to add/update contact. Below is the code

function  updateContact($access_token,$contactid,$entry){
    $ch = curl_init();
    $base = 'https://api.cc.email/v3/';
    $url = $base . '/contacts/'.$contactid;
    curl_setopt($ch, CURLOPT_URL, $url);
    $authorization = 'Authorization: Bearer ' . $access_token;
    $ct = 'Content-Type: application/json;';
    curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorization, $ct));
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);           
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $entry);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

I tried $ct = 'Content-Type: application/json; charset=UTF-8'; and $result = utf8_decode(curl_exec($ch)); But not working.

I think someone can help me..

Deepu Sasidharan
  • 5,193
  • 10
  • 40
  • 97

1 Answers1

1

Those are not 'unicode' characters, they look a bit like Unicode Escape sequences, However, a backslash is missing. You should not be getting Gu00d2Ku00dcL, but G\u00d2K\u00dcL.

My hope is that those backslashes are actually there and something went wrong with sharing this output. If this is the case, the easiest way to parse these is to use the json_decode function.

If those backslases are really missing, then this suggests that the server you are working with is broken, and there's no easy fix for this. In that case you might want to contact who runs this server and let them know.

Evert
  • 93,428
  • 18
  • 118
  • 189