Create new api client with Stata?

Hi everyone,
I am new to Stata and survey solutions. I want to access survey solutions API, but I got this error :
File “”, line 1
# // Python globals:
SyntaxError: invalid syntax
(1120 lines skipped)
(error occurred while loading SuSo.class)

I don’t know what happen. Could you help me please ?
My Python version is : 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]

What is the version of:

  • Stata
  • Survey Solutions server
  • SuSoApi client (or better where did you install it from)?

I use Stata 17.0 BE-Basic Edition.
Survey Solution Server =
SuSoApi client: I installed it through this command == ssc install susoapi

Hello @De_Anzi ,

When I try to replicate I get the following:

followed by an error (this is not surprising since I don’t have credentials for the server). But at least it managed to load the class, start executing the constructor, contact the server, obtain version.

Perhaps you have multiple Python versions installed, and the one that is actually executing is different, though I can’t comprehend in what way.

The message that you show in your log seems to complain already on line 1

# // Python globals:

Which is a comment that should be understood by all Python versions. In your case, however, the rest of the file is ignored.

Besides the version 3.8.1 shown in the screenshot, I’ve also tried with v 3.8.5 with similar result.

Here is what you may try:

  1. Repair or re-install your Python installation;
  2. Reinstall susoapi;
  3. Try susoapi version from Github, (which is newer than the SSC version).

Please do let know what you’ve tried and whether it worked.

1 Like

Hi Sergiy,

thanks for your help. I tried all your advice but I got the same error.
Finally, I decided to use your Python version (v. 3.8.1 ) and I obtained this result.

error: Server responded: 403 Forbidden.
Please check that the API user is given access to the requested resource for this server.

I have, however, the correct accesses

This is strange. I don’t think I am using any features that could be differing in these python versions.

Are your credentials used in this step belonging to an

  • API user?
  • admin?
  • HQ-user?

Is this user given permission to

  • access all workspaces? (how many)
  • default workspace only?
  • only non-default workspace?

Could you please run and share the output of

findfile suso.class
checksum `"`r(fn)'"'
findfile susobase.class
checksum `"`r(fn)'"'

My credentials belong to an admin and have access to all workspaces ( 3 precisely).

Here the result of the script:


I just realized something. as you advised me, I used the Github version of susoapi. I am new with Stata, I don’t know if it was the correct way but I copied the “code” repertory in the C:\Users\xxxxxx\ado\plus\s folder.
So, I made some changes, I deleted this version and re-install susoapi by “ssc install susoapi” . Now I got this error:

Hello De_Anzi,

  1. Thank you for reporting the file lengths. They are different from any version that was released. But it seems that whatever method you used to download them strips one-byte-per-line, which could be one of the CR+LF pair (end of line character). This should not be catastrophic, but is at least strange, since you are also on a Windows platform, and CR+LF is the default there. Perhaps, make sure that the files are downloaded as binary, not text.

In the version 21.05 of Survey Solutions there was a change in the GraphQL syntax. The property roles has been changed to role, in accordance with the fact that any user may occupy only one role.

Earlier it was defined as roles:

The version at SSC corresponds to ~April 2021 state of things, so it addresses roles which was correct at the time. Yet for modern versions of Survey Solutions mentioning roles in a query causes the server to interpret this as a bad query resulting in error 400, which is what you observe. It also shows the ‘bad’ query and you can see the roles mentioned in it.

Please retry the GitHub version which was moved forward after Survey Solutions has had this change.


I will try to do the following

  1. add a branching depending on the version of the server to use role or roles accordingly;
  2. report the file length and checksum in the greeting screen to be able to identify the version that is running.
1 Like

I don’t know if it is the right way but I copied the “code” repertory from Github in the C:\Users\xxxxxx\ado\plus\s folder. I made the test with a version from commit on 23 March and 12 jan but I got this as result:


Also, what’s means this: 21.06.3 ? It’s the version of the API ? If yes, why it’s doesn’t change when I use a different commit ?.

@De_Anzi ,

this is the version of the Survey Solutions software installed on your server (, not the Survey Solutions client that you’ve updated on your machine.

1 Like

Dear @De_Anzi ,

following the discussion above, I have modified the code of the susoapi module in the GitHub to be more verbose about its own version and versions of any dependencies.

It now displays the information similar to what is shown at this screenshot:

For python modules - versions are reported; for Stata class files - file lengths and checksums are reported.

Hope this helps to avoid further confusion with the versions.

Let me know if this is working for you now, or you still need any help with it.

Best, Sergiy

1 Like

Hi Sergiy,

thanks a lot for your help. I retried with the new Github version and I got this:

My password and my username are correct. When I use them with the survey solution API on R, they work well

  1. All of the information displayed in the last log indicates that the server is working and is responding to the queries that do not require authentication.
  2. The very first query that requires authentication fails and the server responds it is forbidden. I’d trust this message.
  3. Does your password include a dollar sign?
  4. If your password contains any characters different from digits or English letters (A…Za…z0…9), please change the password temporarily to the one containing only the A…Za…z0…9 and retry. You can revert the password back to your previous one after you finish this experiment.
  5. run the command : classutil des .sse
    If it succeeds, check that both the account name and password are displayed correctly and correspond to the values you’ve retouched in the screenshot.

I assume you are still using the admin account as you’ve mentioned. Are there any of the workspaces that have been disabled?

PS: I still don’t understand why the file sizes appear differently in your system. Compare the *.class file sizes with my screenshot. Please describe exactly the steps of how you’ve acquired them.

If there is still an issue with creating the API client object in Stata please follow the advice in the previous post and let me know.

Hi Sergiy,
Password doesn’t include a dollar sign but an underscore “_”, yes. So I created an API USER with a password containing only English letters(A…Za…z0…9). I got this error:

I tried with R and it works ( with API user and the admin user).

Also, all workspaces are available.

For your last question, how I install the package?
Firstly, I download the repository on Github :

After, I copied the content of the “code” repertory to this path C:\Users\xxxxxxxxxxx\ado\plus\s :

And that all.

Hi Sergiy,
I just realized that I had a HQ-user account. Maybe the mistake came from there.
I decided to create an API USER with a password containing only letters and numbers.
And it works:

Thank you

Most definitely.
Thank you for updating the thread with this useful information.