Step 2: Creating a User, Generating a Meal Plan, and Retrieving It
Last updated
Last updated
Add a new module to the right of the Google Forms module. Search for “http” and select the “HTTP” module.
Select the “Make a request” action.
Our API documentation provides the API endpoint you need to use in the HTTP module. You’ll also need an API token; follow this guide if you haven’t yet obtained your API token.
To create a user, we’ll use our user API endpoint https://api.suggestic.com/users
. Enter it in the URL field.
Choose “POST” as the method. Enter your API token in the Headers section as pictured below for authorization.
Set the “Body type” field as “Application/x-www-form-urlencoded
” and add two Fields. The first key should be named “name” with the value of the user’s name, the other “email” with our user’s email address.
Ensure the “Parse response” checkbox is checked, then click “OK” to save the module.
To test the module, right-click it, select “Run this module only” and enter whatever random name and email you want when prompted for a name and email.
If you’ve set up the connection correctly, status 201 should be returned, which means a new user has successfully been created. The response will also feature the new user’s ID. Make a note of the newly created user_id.
Right-click on the newly-created HTTP module, and click “Clone.” This will duplicate the existing module, including its parameters.
Connect the duplicated HTTP module with the first HTTP module, then edit it.
Leave the authorization token as is, and add a header. Enter sg-user in the “Name” field and data: user_id
snippet from the previous module in the “Value” field.
Set the “Body type” field as “Raw
,” the “Content type” as “JSON (application/json)” and paste the following query into the “Request content” field.
{"query":"mutation GenerateSimpleMealPlan {generateSimpleMealPlan { success message }}"}
The query above will generate our meal plan. Once done, click “OK” to save the configuration, then right-click the module and click “Run this module only.”
You will be prompted to enter a user id, paste the one we copied in the previous step and click “OK” to run the module.
The status code of your response should be 200 (OK), and the “Meal plan was successfully generated” message should be displayed.
Great! We have our user, and we have our meal plan. Now let’s retrieve it.
Duplicate the last HTTP module (the one used for generating our meal plan), and connect it to the previous module.
Since the simpleMealPlan is tied to the user it was created for; we needn’t change much in the copied module, only the request content. Copy and paste the request below into the “Request content” field.
{"query":"{mealPlan{ day calories meals { meal recipe { name id mainImage totalTime numberOfServings servingWeight ingredientsCount ingredientLines instructions nutrientsPerServing { calories carbs protein fat sugar } } } } }"}
Save the module, run it to test it, and enter the same user_id as before. You should get a status 200 (OK) returned, which means the meal plan was successfully retrieved.
Expanding the “Data” property will reveal the actual meal plan. The response will be unformatted but don’t worry; we’ll make sense of it and style it in the following steps.
For now, copy the unformatted meal plan by double-clicking it and paste it somewhere safe like your notepad.