how to interpret ERROR_UNSUPPORTED_NAMESPACE on getGroups? - sonos

I'm troubleshooting some errors from the Sonos API, where calls to getGroups result in HTTP 404. Here's a sample response:
{
"errorCode": "ERROR_UNSUPPORTED_NAMESPACE",
"reason": "Unexpected error"
}
And here's the corresponding request (with token and household_id redacted):
curl -H "Authorization: Bearer <token>" "https://api.ws.sonos.com/control/api/v1/households/<household_id>/groups"
This error is happening repeatedly for this particular token, which otherwise appears correct and was used to retrieve the household_id used above.
For most users, the same code path and request yields HTTP 200 and a collection of players and groups.

I'm getting the exact same error for 2 users and I can't replicate it on my end.
The documentation says;
When your app sends a namespace that is not recognized by the player,
you’ll receive an ERROR_UNSUPPORTED_NAMESPACE error response. Note
that namespaces are case-sensitive.
For example, if you misspelled the namespace, the player responds with
an ERROR_UNSUPPORTED_NAMESPACE in the global namespace:
{ "errorCode": "ERROR_UNSUPPORTED_NAMESPACE" }
https://developer.sonos.com/reference/types/globalerror/
Like you, I have not spelled anything incorrectly and as its working correctly for the vast majority of users. Again, I can get households for these particular users but not groups.
I am at a complete loss but if I find out the reason I'll follow up.
Thanks, Paul

Related

Http delete request to Google Directory API returning 412 Precondition is not met: location If-Match

I have been using Postman to send http requests to Google's Directory API. The GET request works fine (which shows that the admin token as well works fine) to get info for a user.
But, what I need to do is delete the user, and when I try this, I get the following back:
{
"error": {
"code": 412,
"message": "Precondition is not met.",
"errors": [
{
"message": "Precondition is not met.",
"domain": "global",
"reason": "conditionNotMet",
"location": "If-Match",
"locationType": "header"
}
]
}
}
I was presupposing that I was missing the etag, which is what I added from the user, but it did not work. I also tried adding "*" to the If-Match tag, and that did not work either. Maybe there is a way with a put or patch request?
The API reference is this: https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/delete
The API does not work on Google's reference page either. I have also tried this in multiple domains where I am the super-admin so the error is not related to a specific super-user or domain.
I have also made sure, in multiple tests, that the user I am trying to delete is not an admin of any type.
I am adding images below to show that the GET api works fine. So I just need to know how to format the API request to be able to delete the user.
Ok, after talking directly to Google and even seeing that Jay Lee (author of GAM) ran into the same problem, we found out that you can't delete a user if:
It has a license of some sort
It's an admin
It has a Google Vault retention rule applied
To be able to delete a user from now on, you must remove all these things (licenses, admin privileges, Vault retention rules) or you must transfer the information of that user to another user (along with whatever else Google asks you to remove beforehand).
The "Precondition is not met" is vague and Google should change this, but it means that one of the three things above have not been removed yet.
Below I am adding multiple links to confirm what I mentioned above as well as the APIs you need to use on users before being able to delete them.
https://groups.google.com/g/google-apps-manager/c/83kR-4MoPk0?pli=1
https://github.com/GAM-team/GAM/releases?gam-releases
https://developers.google.com/admin-sdk/data-transfer/reference/rest/v1/transfers#DataTransfer
https://developers.google.com/vault/guides/holds#python
https://developers.google.com/vault/reference/rest/v1/matters.holds.accounts/list

Mixture between 200 (OK) and 403 (Forbidden) HTTP response

do you know if there is a HTTP response code for this use case:
"The user is allowed to see a fraction of the called resource but not all of it".
It sounds like a mixture between the 200 response code (because the user is allowed to retrieve some of the resource) and the 403 response code (because the user is not allowed to see all of it).
I guess the 206 response code (Partial Content) makes sense somewhat. But according to the MDN Web Docs* this response sounds very 'technical' and not business case specific.
Thank you for your help!
*https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206
It would still be a status 200, since they are successfully getting the data they have access to. Whether or not there's other data they don't have access to makes no difference if they're getting what they do have access to. And there's no reason to tell them they don't have access to that other data if they're not trying to access it.
206 Means you're sending the data they have access to in smaller parts.
Imagine a user endpoint. Admin would have access to all user info, whereas a regular user only to their own. So you could have a /user/ to get all and a /user/:id to get a specific user.
If a regular user accesses /user/:id where id is their own id they should get a 200. If they try to access /user/ or /user/:id where id is not their id they should get a 403 (because they're not allowed to use the former and allowed to use the latter, but not get the data for that id). If they're not logged in they should get a 401 (doesn't even matter whether or not they would have access to it if they were logged in).
Same for if you just have a /user/ endpoint, where data is returned based on e.g. their id stored in a cookie.
If data is returned: 200. If they're not allowed to use that endpoint: 403. And again, if they're not logged in: 401.

Some Hangout's API methods are not working

I'm building a chat bot using Hangouts API and some of the API methods are not working, I receive the response:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
For example, when I get the spaces my bot is a member, it returns all spaces just fine. Then I try to use some of these spaces id to get the member list, and it returns that the request contains an invalid argument. I can't see what I'm doing wrong...
The token can't be the issue because it works fine to get the spaces.
EDIT: The create message method returns a different error:
I figured it out... My company have a lib to generate a token for google's apis and the email that was used in the request was the current user email, but, for the bot it must be used the email associated with the service account, I switched that and it started working. I think it shouldn't generate a token case the credentials are not valid because I couldn't figure out what was wrong.
Source where I found this: https://developers.google.com/hangouts/chat/how-tos/rest-api#authorizing_the_service_account

Survey Monkey API- Getting Long Lived Access Token

I am currently unable to figure out how to obtain my long-lived access token so I can create an API data feed from Survey Monkey to Alteryx.
Thus far I have been able to:
1) Go to the OAUTH page
https ://api.surveymonkey.net/oauth/authorize?redirect_uri=https:// www.surveymonkey.com&client_id=[MY-CLIENT-ID]&response_type=code
2) Authenticate access (I am not a robot: reCAPTCHA)
3) Get the Authentication Response with the short-lived code
https: //www. surveymonkey.com/home/?code=[CODE-FROM-RESPONSE]
4) Got stuck
From: https://developer.surveymonkey.com/docs/guides/oauth-guide/
To make the exchange, simply create a form-encoded ( Content-Type: application/x-www-form-urlencoded) HTTP POST request to https://api.surveymonkey.net/oauth/token?api_key=YOUR_API_KEY with the following encoded form fields: client_secret, code, redirect_uri and grant_type. The grant type must be set to "authorization_code".
This is not a "simply" for me, and would really appreciate the expression so I can enter that into my browser so I can retrieve my long-lived access token.
End goal is that I am using Alteryx to pull in the Survey Monkey data via API and creating a blended data set with additional system data. The combined data set will then feed a Tableau Dashboard. I'm sure it is a long-shot, but if anyone has an Alteryx workflow for Survey Monkey API that would solve all of my issues at once.
Thank you in advance for your insights/ guidance.
With gratitude,
Drew
(Note- I added spaces to a few of the links, as I do not have 10 reputation points; yet).
There is an example cURL request at the side of the docs here. You need to make a POST request to /oauth/token. It'll look something like this:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'code=<code>&client_id=<client_id>&client_secret=<client_secret>&redirect_uri=<redirect_uri>&grant_type=authorization_code' "https://api.surveymonkey.net/oauth/token"
Filling in the values in <>. Or in Python, something like this should work:
import requests
url = "https://api.surveymonkey.net/oauth/token"
payload = {
"code": "<code>",
"client_id": "<client_id>",
"client_secret": "<client_secret>",
"redirect_uri": "<redirect_uri>",
"grant_type": "authorization_code"
}
headers = {
'content-type': "application/x-www-form-urlencoded"
}
response = requests.request("POST", url, data=payload, headers=headers)
I'm pretty sure the requests library will automatically convert the body to the right type, but if not payload just looks like URL params:
payload = "code=<code>&client_id=<client_id>&client_secret=<client_secret>&redirect_uri=<redirect_uri>&grant_type=authorization_code"
Essentially though, you just need to make a POST request to /oauth/token with the payload provided above (code, client_id, client_secret, redirect_uri, and grant_type). The main confusing part is you can't send in a JSON body, it has to be a form body that looks like my example above.
Hope that helps.
You should be able to take the response that General Kandalaft has provided and enter each of those into the Download Tool in Alteryx. Create a field for each of client id, client secret, code, redirect_uri & grant_type and then tick those fields on the Payload Tab.
Set the HTTP Action to POST on the same tab.
There are also some examples of Oauth processes on the Alteryx Community and Gallery.
In general, when converting cURL requests to the Download Tool, -d/-F will be payload tab and -H of course will be Headers tab. form encoded etc is normally correct already and only needs to be added/changed very occasionally.
As another note, if you can't figure out the conversion of a cURL request or it's more complicated (i.e. attaching a PEM file to the call), you will find a copy of cURL in your Alteryx install directory and you can use the Run Command Tool to run that.
Kane

Google Simple API key stopped working

I'm using Python/Twisted to do asynchronous HTTP calls to the Google+ API. Our client app passes over the user's access_token and we do an API call to...
https://www.googleapis.com/plus/v1/people/me/?%s&key=%s&
... where %s and %s are being filled with a valid access_token and (supposedly) valid Simple API Key, respectively.
Everything was working beautifully yesterday. Today I continued to work on the unit tests for this when the API suddenly started returning:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
usageLimits, keyInvalid... Okay, I get it. I've seemingly hit the usage limits and they have invalidated API keys coming from this account. Except, I haven't...
The "Courtesy Limit" is supposed to be "10,000 requests/day", yet I've only made a couple hundred calls (according to Google's own usage graphs), and I am still seeing "0% used" on the quotas tab.
I would have brought this to Google directly, but they seem to have dropped their Developers Google Group in favor of a Google+ discussion that doesn't actually receive any responses.
Any help or guidance is extremely appreciated. Thanks!
The answer was quite simple! You can't send both the access_token and the key in the same API call. If you use the access_token you're authenticating the API call as the user, if you use your projects Simple API Key you're authenticating as yourself. If you use both, the call fails.
Just so we are clear, you are using your key from your Google API Console page? On there you should see a tab for "API Access" near the top left hand corner of the page. Make sure that the API Key you are using is your Key for browser apps (with referers) Key, otherwise it won't work.
At any rate, an API Call for me looks like this:
https://www.googleapis.com/plus/v1/people/114789529333378876576?key=ENTER_YOUR_KEY_HERE
You should be able to make at least one API Call per day without a valid Key.
This took me quite a long time to figure out, so hope to save some time to someone else :)
Take a look at thi spost, by google staff (in 2012..) https://groups.google.com/forum/#!topic/google-ajax-search-api/HuKhXfsoMQc
Sorry for the delayed response. This error (which we're working on improving the descriptiveness of) also occurs when you have a
restriction on your key (e.g. locked to a specific referer or IP
address). Please confirm that if you've set such a restriction in the
APIs Console, that the referer or IP address that you're making the
requests from. Pay special attention to any wildcards used on the
referer - for instance, if you use *.abc.com, it won't work if your
request comes from "yoururl".
also would have been great if google team fixed this issue! :)
In my case - I just had to wait few minutes because it was short time after updating my API KEY. Whenever you create a new key or update it on YT developer console. YT has up to 15 mins to make all the changes on their side
In my case I had a parameter named Key, so it thought that was an actual key, just renamed the parameter.