404 Resource Not Found: Domain with Google Directory API

404 Resource Not Found: domain with Google Directory API

After a bit of documentation reading, there were two things that I needed to fix.

  1. I hadn't set up the proper authorization for my test service account.

You have to go to the Apps Console > Security > Advanced > Manage API client access and add the client url for your service account as well as any specific permissions that you want to add

  1. As seen in this question, it seems that you need to create a user object rather than just passing in parameters.

Here's my updated code:

# Authorization happens here ....

api = client.discovered_api('admin', 'directory_v1')
new_user = api.users.insert.request_schema.new(
name: { familyName: 'Testy', givenName: 'Testerson' },
primaryEmail: 'ttttesterson@<domain-redacted>.com',
password: 'password123'
)

result = client.execute(
api_method: api.users.insert,
body_object: new_user
)

Google API: 404 Domain not found

Okay, this was a very easy step to overlook but it was an extremely simple fix.

The issue here was that the domain for the account was not identified. I was under the impression that the service account was already attached to the domain but that is not the case. So the fix is just one line of code to add to the client to set it to a user that is in the domain (for my case).

The fix for me was to add:

$client->setSubject('account@domain.com');

to my getClient method.

so now the method looks like:

/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
function getClient() {
$client = new Google_Client();
$client->setApplicationName('TestingApp');
$client->setAuthConfig(CREDENTIALS_PATH);
$client->setScopes(SCOPES);
$client->setSubject('account@domain.com');
return $client;
}

I saw this mentioned in the API but it states it as optional. Hopefully this will help someone else too.

Google Admin SDK Directory API members.get() returns a 404 for member email, but succeeds for member id

After getting in touch with Google support, it turns out this is a known issue, but no current eta for a fix. We're expected to work around it by using the membership id instead of the email address as the memberKey.

Resource not Found userKey Google Directory API using Service Account

Assuming you've already granted your service account domain-wide delegation, you'll need to have it impersonate an admin account using .setServiceAccountUser("admin@domain.com") as shown in the service account documentation. Service accounts are not themselves domain admins, so they need to impersonate one in order to use the Admin SDK APIs.

Google Admin SDK error Resource Not Found: domain when trying to list existing users

Even when using a service account, you still need to "act as" a Google Apps user in the domain with the proper rights (e.g. a super admin). Try:

credentials = SignedJwtAssertionCredentials(client_email, private_key,
OAUTH_SCOPE, sub='admin@domain.com')

where admin@domain.com is the email of a super admin in your domain.

Google API: 404 Domain not found

Okay, this was a very easy step to overlook but it was an extremely simple fix.

The issue here was that the domain for the account was not identified. I was under the impression that the service account was already attached to the domain but that is not the case. So the fix is just one line of code to add to the client to set it to a user that is in the domain (for my case).

The fix for me was to add:

$client->setSubject('account@domain.com');

to my getClient method.

so now the method looks like:

/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
function getClient() {
$client = new Google_Client();
$client->setApplicationName('TestingApp');
$client->setAuthConfig(CREDENTIALS_PATH);
$client->setScopes(SCOPES);
$client->setSubject('account@domain.com');
return $client;
}

I saw this mentioned in the API but it states it as optional. Hopefully this will help someone else too.

Resource not found: domain while inserting a new user with Google API

I found the mistake. The domain should of course end with ".com".
The correct request is:

def insertNewUser(directory_service):
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': 'testemail@mycompanydomain.com',
}
result = directory_service.users().insert(body=params).execute()

Does fixing a domain not found error require a G-Suite account

The Directory API only supports G Suite, Education and Government editions Google accounts.

Anyway, the error 404 is not related to your account status, but to a missing or wrong domain in your credentials. If this was your case you would get a 403 error "Not Authorized to access this resource/api"

For more info about the Directory API Prerequisties: https://developers.google.com/admin-sdk/directory/v1/guides/prerequisites



Related Topics



Leave a reply



Submit