Create User via API throws Error

Infos:

  • Used Zammad version: 3.2.x
  • Used Zammad installation source: Not sure :frowning:
  • Operating system: Ubuntu 18.0.4 LTS
  • Browser + version: Chrome + newest

Expected behavior:

Create a User with listed Attributes (all fields exist in Zammad).

Actual behavior:

Error-Code: {ā€œerrorā€:ā€œMinimum one identifier (login, firstname, lastname, phone or email) for user is required.ā€}

Steps to reproduce the behavior:

$ch = curl_init();

$postfields = array(
ā€˜firstnameā€™ => ā€˜Helmutā€™,
ā€˜lastnameā€™ => ā€˜Jaā€™,
ā€˜emailā€™ => ā€˜helmut.ja@arcor.deā€™,
ā€˜phoneā€™ => ā€˜0164958685ā€™,
ā€˜addressā€™ => ā€˜Irgendeine Adresseā€™,
ā€˜rolesā€™ => [ā€˜Customerā€™],
ā€˜loginā€™ => ā€˜helmut.ja@arcor.deā€™,
ā€˜passwordā€™ => ā€˜mypassā€™,
ā€˜organizationā€™ => ā€˜Pfitzenmeierā€™, //this one already exists, shouldnā€™t be the problem
ā€˜inviteā€™ => true //email to new customer
);

$jsonfields = json_encode($postfields, true);

/*
echo $jsonfields;

{ā€œfirstnameā€:ā€œHelmutā€,ā€œlastnameā€:ā€œJaā€,ā€œemailā€:ā€œhelmut.ja@arcor.deā€,ā€œphoneā€:ā€œ0164958685ā€,ā€œaddressā€:ā€œIrgendeine Adresseā€,ā€œrolesā€:[ā€œCustomerā€],ā€œloginā€:ā€œhelmut.ja@arcor.deā€,ā€œpasswordā€:ā€œmypassā€,ā€œorganizationā€:ā€œPfitzenmeierā€,ā€œinviteā€:true}
*/

curl_setopt($ch, CURLOPT_URL, ā€˜https://my.zammad.de/api/v1/usersā€™);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ā€˜POSTā€™);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
ā€˜Authorization: Bearer myTokenā€™ //myToken is created with all rights!
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonfields);

$result = curl_exec($ch);

echo $result; //throws Error

curl_close($ch);

Thatā€™s my code so far, but i always get the same Error. Is anybody able to help me?

Thanks in advance!

Nvm, it was ā€œContent-Type: application/jsonā€ which was missing in the header.

Topic can be closed.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.