google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Please add clear docs for Forms V1 API

Open notedwin-dev opened this issue 2 years ago • 1 comments

So, I have spent 4 hours last night testing out the Google Forms REST API just to see it fail authorizations and stuffs like that. Then I found out that there is NPM library for Google OAuth2 Client and Google Forms.

There is no clear docs on Google Forms API on that NPM page and the API documentation link on the README for the NPM page leads to a 404 page. Clearly a documentation wasn't made yet for googleapis.dev

I hope that you guys can rush out a documentation as this is urgent and important for users who are looking for a guide on how to use the form API.

notedwin-dev avatar Apr 17 '22 11:04 notedwin-dev

I think the broader issue is that https://googleapis.dev/nodejs/googleapis/latest/ hasn't been updated since v85, and this package is already at v100!

thebrucecgit avatar Apr 29 '22 07:04 thebrucecgit

Is there any response on from Google on this? I'm looking at the Docs now and they don't even include a reference for the Forms API.

baileywickham avatar Oct 29 '22 05:10 baileywickham

Is there any response on from Google on this? I'm looking at the Docs now and they don't even include a reference for the Forms API.

@baileywickham I have gotten it to work using the code below:

//Get a form.
//@example
const {google} = require('googleapis');
const forms = google.forms('v1');

async function main() {
  const auth = new google.auth.GoogleAuth({
    keyFilename: `sa-file.json`,
    scopes: [
      'https://www.googleapis.com/auth/drive',
      'https://www.googleapis.com/auth/drive.file',
      'https://www.googleapis.com/auth/drive.readonly',
      'https://www.googleapis.com/auth/forms.body',
      'https://www.googleapis.com/auth/forms.body.readonly',
    ],
  });

  // Acquire an auth client, and bind it to all future calls
  const authClient = await auth.getClient();
  google.options({auth: authClient});

  // Do the magic
  const res = await forms.forms.get({
    // Required. The form ID.
    formId: 'placeholder-value',
  });
  console.log(res.data);

  // Example response
  // {
  //   "formId": "my_formId",
  //   "info": {},
  //   "items": [],
  //   "linkedSheetId": "my_linkedSheetId",
  //   "responderUri": "my_responderUri",
  //   "revisionId": "my_revisionId",
  //   "settings": {}
  // }
}

main().catch((e) => {
  console.error(e);
  throw e;
});

You have to generate a Service Account credential to authenticate yourself for Google Forms in Google Cloud Console. You can find more in the main folder of Google Form's Github folder: https://github.com/googleapis/google-api-nodejs-client/blob/main/src/apis/forms/v1.ts#L1323

notedwin-dev avatar Oct 29 '22 21:10 notedwin-dev

Thanks for the help, that's very useful. It would also be great to get a response from Google on the forms documentation so it seems out of date.

baileywickham avatar Oct 30 '22 01:10 baileywickham