locked
Creating Group via Microsoft Graph returns Error “An unexpected PrimitiveValue node was found when reading from the JSON reader” RRS feed

  • Question

  • I need to post the Data below to Microsoft Graph API,

    {
      "description": "An Awesome New Group",
      "displayName": "Awesome Group",
      "groupTypes": ["Unified"],
      "mailEnabled": true,
      "mailNickname": "awesomeGroup",
      "securityEnabled": false
    }

    Am trying to create group using my admin account via Microsoft Graph. I have

    implemented all the required parameters/variables but when I tried making calls to the API,

    it displays error below: It seems that my json post was not properly sent..

    { "error": { "code": "Request_BadRequest", "message": "An unexpected 'PrimitiveValue' node was found when reading from

    the JSON reader. A 'StartArray' node was expected.", "innerError": { "request-id": "02bfcc43-5982-4c49-8484-da9d6cc61bab", "date": "2017-12-05T17:53:57" } } }

    Below is my code

    <?php 
    session_start();
    
    
    echo $acc= $_SESSION['access_token'];
    
    $data_string = array("description" => "An Awesome New Group", "displayName" => "Awesome Group", "groupTypes" => "Unified", "mailEnabled" => "true", "mailNickname" => "awesomeGroup", "securityEnabled" => "fasle"); 
    $data = json_encode($data_string); 
    //$data = $data_string; 
    $curl = curl_init();
    
    curl_setopt_array($curl, array( 
    CURLOPT_URL => "https://graph.microsoft.com/v1.0/groups",
    
    CURLOPT_HEADER => true,
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_ENCODING => "", 
    CURLOPT_MAXREDIRS => 10, 
    CURLOPT_TIMEOUT => 30, 
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
    CURLOPT_CUSTOMREQUEST => "POST", 
    CURLOPT_POSTFIELDS => "$data", 
    CURLOPT_HTTPHEADER => array( 
    "accept: application/json", 
    "authorization: Bearer $acc", 
    "content-type: application/json; charset=utf-8" 
    ), 
    ));
    
    $response = curl_exec($curl); 
    $err = curl_error($curl);
    
    curl_close($curl);
    
    
    
    print_r($response);
    
    
    
    
    if ($err) { 
    echo "cURL Error #:" . $err; 
    } else { 
    //echo $response; 
    }
    ?>

    Wednesday, December 6, 2017 6:55 AM

All replies

  • The post looks good.

    I took your information from above, and posted the same in MS Graph explorer.

    My advice is to closely examine the actual traffic you are sending on the wire.  Can you use fiddler or some other network took and examine the POST request directly?

    I suspect that something is being corrupted or your script is not building the request properly.

    Here is my test using fiddler:

    POST https://graph.microsoft.com/v1.0/groups HTTP/1.1
    Authorization: Bearer <SNIP>
    Content-Type: application/json; charset=utf-8
    Host: graph.microsoft.com
    Content-Length: 201
    {
      "description": "An Awesome New Group2",
      "displayName": "Awesome Group2",
      "groupTypes": ["Unified"],
      "mailEnabled": true,
      "mailNickname": "awesomeGroup3",
      "securityEnabled": false
    }
    HTTP/1.1 201 Created
    Cache-Control: private
    Transfer-Encoding: chunked
    Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
    Location: https://graph.microsoft.com/v2/3e676bf8-9757-4b52-8813-b2d44a75c42b/directoryObjects/14864609-bb1f-459c-9492-bb9d3741b46f/Microsoft.DirectoryServices.Group,https://graph.microsoft.com
    request-id: 7da3ad4c-4982-4365-af58-a20ef3b8284a
    client-request-id: 7da3ad4c-4982-4365-af58-a20ef3b8284a
    x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"East US","Slice":"SliceA","Ring":"2","ScaleUnit":"000","Host":"AGSFE_IN_24","ADSiteName":"EST"}}
    OData-Version: 4.0
    Duration: 326.384
    Date: Wed, 03 Jan 2018 14:53:43 GMT
    2cc
    {"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups/$entity","id":"14864609-bb1f-459c-9492-bb9d3741b46f","deletedDateTime":null,"classification":null,"createdDateTime":"2018-01-03T14:53:44Z","description":"An Awesome New Group2","displayName":"Awesome Group2","groupTypes":["Unified"],"mail":"awesomeGroup3@MOD165648.onmicrosoft.com","mailEnabled":true,"mailNickname":"awesomeGroup3","onPremisesLastSyncDateTime":null,"onPremisesProvisioningErrors":[],"onPremisesSecurityIdentifier":null,"onPremisesSyncEnabled":null,"preferredDataLocation":null,"proxyAddresses":["SMTP:awesomeGroup3@MOD165648.onmicrosoft.com"],"renewedDateTime":"2018-01-03T14:53:44Z","securityEnabled":false,"visibility":"Public"}
    0

    Hope this helps.

    Regards,
    MaxV (MSFT)

    Wednesday, January 3, 2018 2:55 PM
  • "securityEnabled" => "fasle" is in your script code.  That "might" be the problem

    Dan Kershaw [msft]

    Tuesday, January 9, 2018 2:22 AM