Typeform/js-api-client

Add create API for forms

picsoung opened this issue · 4 comments

At the moment the create form endpoint is not covered by this SDK.

Would be awesome if it was.

@picsoung doesn't this work https://github.com/Typeform/js-api-client/blob/master/src/forms.js#L46? 🤔

So I guess it's just missing from the docs? @jepser is there a reason to not show it on the docs?

jwtd commented

I just tried creating a form using that endpoint. Here is a Gist of the code.

When I submit the exact same form payload via Postman, the form is created successfully. The code in my gist returns a validation error.

{ code: 'VALIDATION_ERROR',
  description: 'The payload is invalid.',
  details: 
   [ { code: 'REQUIRED_PROPERTY',
       field: '/title',
       description: 'should have required property \'title\'',
       in: 'body' } ] }
jwtd commented

Got the create call working. I neglected to pass the data as an object.

Fix was to change this...

tf.forms.create(data).then(response => {
  console.log(response);
});

To this...

tf.forms.create({ data }).then(response => {
  console.log(response);
});

I've submitted a PR which adds Form.create to the docs and also fixes a build error related to a webpack bug.

Sorry for that, updated the docs #30 thanks @jwtd for the contribution.