The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

JSON Option for Datafeed to Support AWS API Gateway

We are having a hard time pushing transaction data via the datafeed feature to Amazon's API Gateway product. No matter how we configure it, the API gateway keeps returning an error: "Unsupported media type." After some research, I'm not entirely sure if the AWS API Gateway is compatible with the Foxycart datafeed feature. It appears the AWS API Gateway favors JSON.

We modified your PHP test script to send an encrypted transaction as part of a JSON object:

$XMLOutput_encrypted = rc4crypt::encrypt($myKey,$XMLOutput);
$XMLOutput_encrypted = base64_encode($XMLOutput_encrypted);

$ch = curl_init($myURL);
$jsonData = array('FoxyData' => $XMLOutput_encrypted );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($jsonData));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
$result = curl_exec($ch);

These minor modifications allow us to use the API Gateway in conjuction with Lambda and SQS. Encrypted transactions are safely stored in an SQS queue so we can easily consume them in a controled fasion. This approach costs very little to run and offers a lot of value. We believe other FoxyCart clients that are using Amazon AWS would greatly benefit from this.

Would it be possible to add an option for the datafeed that could send application/json instead of text/plain so that it is compatible with the AWS API Gateway? If not, can you tell us how the API Gateway can be configured to accept the datafeed POST?

Thanks,
Marty
Comments
  • fc_romanfc_roman Member, FoxyCart Team
    Hi @Marty,

    Our brightest team members are on the task and should share their verdict with you soon.

    In the mean time, let us know if you have any other questions.
  • fc_adamfc_adam FoxyCart Team
    @mburolla,

    Good question! Amazon API Gateway does indeed prefer JSON as you noted. We're actually finishing up on a new webhooks system that will replace our existing datafeed product, and it will by default send the data as JSON, along with a stack of other improvements. We don't have an ETA just yet, but we know the current datafeed is showing it's age and we're working to bring the new solution out soon!
  • This is great news. This will allow us to consume your datafeed in a serverless fashion!

    One more question. I'm able to decrypt a transaction from the datafeed using Node.js and now I'd like to normalize this data into a SQL database. Do you have any examples in Node the would enable me to do this quickly?

    Thanks,
    Marty
  • fc_adamfc_adam FoxyCart Team
    @mburolla,

    Unfortunately we don't have any examples of working with the decrypted datafeed with Node.js, sorry!
  • By any chance, do you have some database scripts that I can run on MySQL that will generate the necessary tables and fields to store the transaction feed?
  • brettbrett FoxyCart Team
    @mburolla, unfortunately no, not at this point. Not a bad idea, though.

    Not sure about your exact use case, but if it were me and I couldn't wait for the new webhook system (with JSON and a Zapier integration), I'd probably do what you're doing to pipe the XML into API Gateway -> Lambda, then convert the XML to JSON and dump it into DynamoDB. That's not going to get you MySQL, but it might just be a lot easier.

    You've probably considered that option, though :)
Sign In or Register to comment.