0

I'm calling the get, update and delete APIs for org unit through Google .net client library but get 404. I used Fiddler and saw that the request URL is malformed. Rather than my org unit path I see {/orgUnitPath*} string in the URL and customer Id is replaced with the actual customer Id, I made that request with actual org unit path in Fiddler and it works fine.

My org unit path is ABC/IT and I assume there is some problem initializing repeatable string because my insert and list APIs work fine:

Repeatable<string> rep = new Repeatable<string>(new List<string>{orgUnitPath});

OrgunitsResource.GetRequest gr = service.Orgunits.Get(GetGoogleUser(ConfigManager.AdminIdentity, accessToken).CustomerId, rep);

OrgUnit orgUnit = gr.Fetch();

Am I doing something wrong here?

My new code after updating the client library is:

public OrgUnit GetGoogleOrganizationUnit(string orgUnitPath, string accessToken)
        {
            AccessToken = accessToken;
            var service = new DirectoryService(GetGoogleServiceClient());

            Repeatable<string> rep = new Repeatable<string>(new List<string> { orgUnitPath });

            OrgunitsResource.GetRequest gr = service.Orgunits.Get(GetGoogleUser(ConfigManager.AdminIdentity, accessToken).CustomerId, rep);

            OrgUnit orgUnit = gr.Execute();

            return orgUnit;
        }

Following is the stack trace:

[JsonReaderException: Error parsing NaN value. Path '', line 0, position 0.]
   Newtonsoft.Json.JsonTextReader.ParseNumberNaN() +97
   Newtonsoft.Json.JsonTextReader.ParseValue() +400
   Newtonsoft.Json.JsonTextReader.ReadInternal() +35
   Newtonsoft.Json.JsonTextReader.Read() +20
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) +74
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) +442
   Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) +687
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) +111
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value, JsonSerializerSettings settings) +66
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value) +42
   Google.Apis.Json.NewtonsoftJsonSerializer.Deserialize(String input) in c:\code.google.com\google-api-dotnet-client\default_3\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\Json\NewtonsoftJsonSerializer.cs:72
   Google.Apis.Services.<DeserializeError>d__9.MoveNext() in c:\code.google.com\google-api-dotnet-client\default_3\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:357

[GoogleApiException: An Error occurred, but the error response could not be deserialized]
   BLL.GoogleAPIManagerBLL.GetGoogleOrganizationUnit(String orgUnitPath, String accessToken) in c:\Projects\FGPortal\BLL\GoogleAPIManagerBLL.cs:504
   Application.ManageOrgUnits.gvorgunits_RowCommand(Object sender, GridViewCommandEventArgs e) in c:\Projects\FGPortal\Application\ManageOrgUnits.aspx.cs:29
   System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e) +111
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +73
   System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +89
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +88
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9642898
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
AdnanQ
  • 85
  • 6

3 Answers3

1

First of all you are using an old version of the library. Please do the following using NuGet:

And then try to do the following:

OrgUnit orgUnit = service.Orgunits.Get(CustomerId).Execute();

peleyal
  • 3,472
  • 1
  • 14
  • 25
  • I get error when I try to install the package: You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references that are compatible with that framework – AdnanQ Sep 24 '13 at 06:08
  • When I installed the packages it started giving me conflicts for .net framework 4.0, even with the assembly binding redirects in web.config. – AdnanQ Sep 24 '13 at 12:07
  • Finally I got it working by removing redirects and references and installing package again. There is no overload with one argument for getting orgunit so I tried with two and got an error "JsonReaderException: Error parsing NaN value. Path '', line 0, position 0." – AdnanQ Sep 24 '13 at 12:29
  • Can you please attach your stack trace? What is the exact error? Update also the issue and contain the new code you have. Maybe it is actually a good advice to start a new project that targets .NET 4.0 (or 4.5) and install the PRERELEASE NuGet packages. – peleyal Sep 24 '13 at 14:27
  • I have updated the issue with new code and stack trace. I have my project already targeting .Net 4.0 – AdnanQ Sep 25 '13 at 05:29
  • I think the problem is still with the request URL, following is the request URL: /admin/directory/v1/customer/A152seig3/orgunits%7B/orgUnitPath*%7D I assume that when the request is executed during that time it is parsed which results in exception – AdnanQ Sep 25 '13 at 05:37
1

I had the same problem. But the problem was with the orgunitpath and my repeatable parameter. orgunitpath was in the format "/ABC/IT". Once I changed it to "ABC/IT" it worked fine for me. There was also a small difference in the way I initialized the Repeatable.

I directly used a list of string in the place of the repeatable parameter.

List<string> list = new List<string>();

list.Add("ABC/IT");

OrgunitsResource.GetRequest orgUnitRequest = googleAppsOAuthService.Orgunits.Get(superAdminImmutableId, list);

Google.Apis.Admin.Directory.directory_v1.Data.OrgUnit orgUnit = orgUnitRequest.Execute();"
J0e3gan
  • 8,740
  • 10
  • 53
  • 80
Thomas
  • 21
  • 4
0

At last I used REST operations to achieve it, let me know if anyone come across a solution. Following is the code:

public OrgUnit GetGoogleOrganizationUnit(string orgUnitPath, string accessToken)
        {
            AccessToken = accessToken;
            var service = new DirectoryService(GetGoogleServiceClient());

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format("https://www.googleapis.com/admin/directory/v1/customer/{0}/orgunits/{1}", GetGoogleUser(ConfigManager.AdminIdentity, accessToken).CustomerId, HttpUtility.UrlEncode(orgUnitPath)));
        request.Method = "GET";
        request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + accessToken);

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader sr = new StreamReader(response.GetResponseStream());

        var jLinq = JObject.Parse(sr.ReadToEnd());

        OrgUnit orgUnit = new OrgUnit();

        orgUnit.Kind = jLinq["kind"].ToString();
        orgUnit.ETag = jLinq["etag"].ToString();
        orgUnit.Name = jLinq["name"].ToString();
        orgUnit.Description = jLinq["description"].ToString();
        orgUnit.OrgUnitPath = jLinq["orgUnitPath"].ToString();
        orgUnit.ParentOrgUnitPath = jLinq["parentOrgUnitPath"].ToString();
        orgUnit.BlockInheritance = Convert.ToBoolean(jLinq["blockInheritance"]);

        return orgUnit;
    }
AdnanQ
  • 85
  • 6