Giter Club home page Giter Club logo

Comments (11)

marktani avatar marktani commented on May 27, 2024 1

Just noticed this is the functions repo. For the future, please report errors like this in https://github.com/graphcool/api-bugs/ instead. Let's discuss this error here though πŸ™‚

from graphcool-templates.

heymartinadams avatar heymartinadams commented on May 27, 2024

FYI, able to neither create new nor update existing functions.

from graphcool-templates.

marktani avatar marktani commented on May 27, 2024

Yes I was about to say as much. This behaviour is observed when you have a syntax error in the function itself, or we were not able to import a specified npm module or similar.

We're already working on returning a user friendly error message in these cases instead πŸ™‚ Could you check your code for syntax errors? (might be a missing bracket or brace, for example)

from graphcool-templates.

heymartinadams avatar heymartinadams commented on May 27, 2024

Thanks! Will check the code again.

from graphcool-templates.

heymartinadams avatar heymartinadams commented on May 27, 2024

Ok. FYI, here’s the query and function.

subscription {
  User(filter: {
    mutation_in: [CREATED]
  }) {
    updatedFields
    node {
      id
      firstName
      lastName
      email
      isPaid
    }
  }
}
module.exports = function (event) {
  var sg = require("[email protected]")(___SENDGRID_API___)
  var request = sg.emptyRequest()
  request.body = [{
    "email": event.data.node.email,
    "first_name": event.data.node.firstName,
    "last_name": event.data.node.lastName,
    "LPA_paid": event.data.node.isPaid,
    "SOURCE": "LPA"
  }];
  request.method = "POST"
  request.path = "/v3/contactdb/recipients"
  return new Promise(function(resolve, reject) {
    sg.API(request, function (error, response) {
      if (error) {
        console.log("Error response received")
        reject(error)
      }
      console.log(response.statusCode)
      console.log(response.body)
      console.log(response.headers)
      resolve(response)
    })
  }
}

from graphcool-templates.

marktani avatar marktani commented on May 27, 2024

Can you try
var sg = require("sendgrid")(___SENDGRID_API___)
instead of
var sg = require("[email protected]")(___SENDGRID_API___)

from graphcool-templates.

heymartinadams avatar heymartinadams commented on May 27, 2024

Is the API key wrapped as a "string"? Tried both.

from graphcool-templates.

marktani avatar marktani commented on May 27, 2024

yes, it is

from graphcool-templates.

heymartinadams avatar heymartinadams commented on May 27, 2024

For reference: https://github.com/sendgrid/sendgrid-nodejs/blob/master/examples/contactdb/contactdb.js#L253-L279

from graphcool-templates.

heymartinadams avatar heymartinadams commented on May 27, 2024

Per @marktani: You missed a ) in the second last line, this is the correct code you need to use

module.exports = function (event) {
  var sg = require("sendgrid")(___SENDGRID_API_KEY___)
  var request = sg.emptyRequest()
  request.body = [{
    "email": event.data.node.email,
    "first_name": event.data.node.firstName,
    "last_name": event.data.node.lastName
  }];
  request.method = "POST"
  request.path = "/v3/contactdb/recipients"
  return new Promise(function(resolve, reject) {
    sg.API(request, function (error, response) {
      if (error) {
        console.log("Error response received")
        reject(error)
      }
      console.log(response.statusCode)
      console.log(response.body)
      console.log(response.headers)
      resolve(response)
    })
  })
}

from graphcool-templates.

marktani avatar marktani commented on May 27, 2024

Thanks!

from graphcool-templates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.