In the tutorial Creating flows for an API you created a REST API to create a customer contact in Salesforce. In this tutorial you’re going to create an API which will retrieve and update contact details in Salesforce.

First, find or create everything you need:

  1. In the App Connect Dashboard click the Customer API tile.
  2. Click the Operations tab. Notice that you are unable to make any changes. This is because the API is still running. To make changes we have to stop the API.
  3. To stop the API, in the navigation banner, click the 3 dot icon > Stop API.

    Click the image to view full size

  4. Click Select an operation to add > Retrieve Customer by ID.
  5. Click Select an operation to add > Replace or create Customer by ID.
  6. Note: In this tutorial, for demonstration purposes, you are going to retrieve and update a customer by ID. However, it is also possible to retrieve and update customers using other filters, based on the properties you added, so in this case the other filters would be first name, last name and email address. To choose another filter, select Retrieve Customer with filter or Replace or create Customer with filter.
  7. For the Retrieve Customer by ID operation, click Implement flow.
    1. Notice the Request URL example. When we call this API we will have to append the customer ID to the end of the URL to retrieve the customer details.

      Next we need to define which customer details we want to receive in the response.

    2. Click (+).
    3. Select Salesforce > Contact > Retrieve Contact. (If you haven’t already connected App Connect to Salesforce, specify the name and password of your Salesforce account.)
    4. As we want to retrieve contacts whose contact ID is equal to the customer ID that the user of your API enters; we’re going to add a condition and update the Where all of the following conditions are true fields as follows:

    5. Leave the other fields with their default values.
    6. Click Response. Here we define the status code and which fields will be returned in the response body.
    7. Leave the status code as the default and map all the fields to the Salesforce retrieve contact fields as follows:

      Ignore the warning messages. They will not affect the response.

      Note: When you’re creating an object, typically only the ID from the target application will be returned in the response message. If you’re retrieving an object, the response message will show you all the fields that you’ve requested from the target application.
      Info: In the Response header section, you can choose your own response code mapping. The following response codes are returned for the different operations:

      • Create operations return a response code of 201 (record created).
      • Retrieve operations return a response code of 200 (record retrieved).
      • Replace or create operations return a response code of 200 (record replaced) or 201 (record created).
    8. Click Done
  8. For the Replace or create Customer by ID operation, click Implement flow.
    1. Notice the request URL example and request body example.
    2. Click (+).
    3. Select Salesforce > Contact > Update or create Contact.
    4. As we want to update or create a contact by contact ID we’re going to update the Where fields as follows:

    5. Configure these Salesforce fields by mapping their values to those from the request body parameters:
      • Last name: LastName
      • First Name: FirstName
      • Email: Email_Address
    6. Click Response.
    7. Leave the status code as 200.
    8. Configure the response body fields by mapping their values to those from the Salesforce / Update or create Contact fields as follows:

  9. Click Done and start the API.

Finally, test your flow:

Next you’re going to test the flow to retrieve a customer and then to update the email address of the same customer.

  1. [To retrieve a customer]:
    • Click the Manage tab and make note of the URL, user name, and password. We’re going to use these credentials to invoke the API operations. As in the previous tutorial, we’re going to use Postman; however you can use your preferred utility, for example, the Linux command line and curl, or the HttpRequester add-on for Firefox.
    • In the Postman utility, open a new tab and select the GET function. (The following steps use Postman version 5.3.1. Some steps might differ slightly for different versions.)
    • In the Enter request URL field, paste the API base URL that you copied earlier and append the model name and customer ID to the end. For example, /Customer/0030Y00000X7g6uQAB.
      Info: To get a customer ID, open Salesforce and click on a contact record. The customer ID is displayed in the Salesforce URL when you’re in the contact record. For instance, it’s the string 0030Y00000X7g6uQAB from the URL
    • In the Authorization tab, change the Type to Basic Auth.
    • Add the user name and password that you copied earlier to their respective fields.
    • Click Update Request.
    • Go to the Headers tab and select the following key/value pairs:
      • Key: Content-Type
      • Value: application/json

    • Click Send.
    • The customer details are displayed. Notice that the response contains all the fields that you specified when you created the flow.
    • Copy the response for testing the replace or create operation.
    Postman utility used to call an API GET operation to retrieve a contact from Salesforce (click the image to view full size).
  2. [To update a customer (replace or create)]:
    • In the same Postman window, change the GET function to PUT.
    • In the Body tab, select raw and paste in the response you copied earlier.
    • Change the email address to
    • Click Send.
    • The response is displayed in the response palette with the new email address.
    • Open Salesforce and you’ll notice that the contact has been updated with the new email address.

Join The Discussion

Your email address will not be published. Required fields are marked *