# SAP Cloud for Customer (C4C)

The Aisera Gen AI Platform supports the following operations for SAP C4C:

1. Ticket ingestion
2. Ticket Management flows

   1. Create ticket
   2. List tickets by status
   3. List tickets by name (subject or title of the ticket is called name in SAP C4C API)
   4. Update ticket’s name (subject or title of the ticket is called name in SAP C4C API)
   5. Update ticket’s status (e.g. to Closed)
   6. Get ticket by ID

   Ask your Aisera team for example JSON files that correspond to each of these flows.

### Authorization <a href="#authorization" id="authorization"></a>

* Basic auth requires a username and password.
* If the x-csrf-token is enabled, you have to make a call with Basic auth and include:\
  `x-csrf-token : fetch`\
  in the header.\
  Then use the x-csrf-token header along with Set-Cookie headers and use them as headers in succeeding calls.
* Example:\
  `curl --location --request GET 'https://my363016.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/ServiceRequestCollection?$top=1' \ --header 'Accept: application/json' \ --header 'x-csrf-token: fetch' \ --header 'Authorization: Basic xxxxx'`

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FtoyGqTAzQw6szeCODoQ0%2Ffirst_ss_C4C.jpeg?alt=media&#x26;token=3c07fc9b-2e12-4674-9f8e-d2d424c173aa" alt=""><figcaption></figcaption></figure>

### Endpoints <a href="#endpoints" id="endpoints"></a>

1. GET `/ServiceRequestCollection` to list tickets.
2. POST `/ServiceRequestCollection` to create a new ticket.
3. GET `/ServiceRequestCollection?ID={ID}` to get tickets by ID.
4. PATCH `/ServiceRequestCollection('{ObjectID}')` to update a ticket by ObjectID (after getting the ticket using the ID).

### Setup Integration in Admin UI <a href="#setup-integration-in-admin-ui" id="setup-integration-in-admin-ui"></a>

1. Navigate to **Settings > Integrations** in the Aisera Admin UI.

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2Fd59rSLSQDzh8ydrlWZiZ%2Fintegrations.jpeg?alt=media&#x26;token=5eedc1a7-ddb7-4210-86e2-086d98cb012a" alt="" width="226"><figcaption></figcaption></figure></div>

2. Click the **+ New Integration** button (top right).

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FYAb1mOw1LjgGIcTqxGmg%2Fnew_integration.jpeg?alt=media&#x26;token=0dd667a5-e262-40ba-a5f2-387b0fe6ae6b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://media-cdn.atlassian.com/file/c4395ffc-1acc-4214-a297-3e2e4144a702/image/cdn?allowAnimated=true&#x26;client=c0f6b24c-cf51-4df1-942f-10180dc619b6&#x26;collection=contentId-2462613505&#x26;height=125&#x26;max-age=2592000&#x26;mode=full-fit&#x26;source=mediaCard&#x26;token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjMGY2YjI0Yy1jZjUxLTRkZjEtOTQyZi0xMDE4MGRjNjE5YjYiLCJhY2Nlc3MiOnsidXJuOmZpbGVzdG9yZTpjb2xsZWN0aW9uOmNvbnRlbnRJZC0yNDYyNjEzNTA1IjpbInJlYWQiXX0sImV4cCI6MTc2NjA5MTkxOSwibmJmIjoxNzY2MDg5MDM5LCJhYUlkIjoiNzEyMDIwOjllZDAzNGU1LTBmODctNDk3OC1iM2UzLWI0M2Q0YTMxZDE4OCIsImh0dHBzOi8vaWQuYXRsYXNzaWFuLmNvbS9hcHBBY2NyZWRpdGVkIjpmYWxzZX0.DtjK5WK21d22xOdSWbVKkb6xP-__1mrIR1CWkgR9ov0&#x26;width=1684" alt=""><figcaption></figcaption></figure>

3. Select the **SAP C4C** icon and click **Next**.

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2Fwqpgtjc5zyvT1KzrJNWA%2FchooseC4C.jpeg?alt=media&#x26;token=81869e42-a9fa-4b95-8159-df5826094953" alt="" width="563"><figcaption></figcaption></figure></div>

3. Create a **Name** for your C4C Integration.

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FWKY3gRKAzIPFskQGYeAr%2Fstep2_endpoint_config.jpeg?alt=media&#x26;token=a78aceed-231b-47d2-900f-75b2f1d3344e" alt=""><figcaption></figcaption></figure>

3. Enter the **SAP C4C Endpoint**. The endpoint format should be : [https://my{ID}.crm.ondemand.com](https://my354265.crm.ondemand.com/)
4. If your SAP C4C implementation is not **Public**, uncheck the **Public** field.
5. Click **Next**.
6. Enter the **Username** of an SAP C4C Admin or Service User. This account will be logging in to the Aisera Gen AI Platform to transfer data to the Aisera temporary data storage.

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FlNMhbpryUr9H4kgc6wC9%2Fc4c_step3.jpeg?alt=media&#x26;token=7daeed48-4ef7-4b1b-8db6-cd6995c91ed7" alt=""><figcaption></figcaption></figure></div>

3. Enter a **Password** for the Admin or Service User account.
4. Click **OK**.

### Setup Data Source in Admin UI for Ingestion of Tickets <a href="#setup-data-source-in-admin-ui-for-ingestion-of-tickets" id="setup-data-source-in-admin-ui-for-ingestion-of-tickets"></a>

1. Navigate to **Settings > Data Sources** in the Aisera Admin UI.

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2F9ezg8lm2Zg5U8eWOUFlE%2Fdata_sources.jpeg?alt=media&#x26;token=a04305d8-ec1e-4c39-9f9d-bf687755bfe0" alt="" width="230"><figcaption></figcaption></figure></div>

2. Click **+ New Data Source**.

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FtOQwyC76MV1mpwWeLz8c%2Fnew_data_source.jpeg?alt=media&#x26;token=3f750b58-a28e-486b-96da-3fa160db5a53" alt="" width="563"><figcaption></figcaption></figure></div>

3. Select the **SAPC4C icon** and click **Next**.

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2F9JDJjcdHCqw741YX892k%2FC4C_icon.jpeg?alt=media&#x26;token=2a5f254e-22a6-4805-9113-37fd6fe6f898" alt=""><figcaption></figcaption></figure>

4. Fill in **Name** of the data source.

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FHJVkzXoBB9lMO5d5Rn3n%2Fstep2_DS.gif?alt=media&#x26;token=87d2468f-308b-477d-96f3-83ba4d34f4be" alt="" width="387"><figcaption></figcaption></figure></div>

4. Select the **Integration** that you created previously.&#x20;
5. In the **Schedule** field, choose **Incremental** from the pull-down menu, or choose a **Date Range**).
6. Click **Next**.
7. Leave the rest of the fields empty.

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2Fqqos8AkHhXPYEaUJbRzn%2Fstep3_DS.gif?alt=media&#x26;token=7e3bad15-7405-4b2e-acff-875b0423d382" alt=""><figcaption></figcaption></figure></div>

8. Add a script in the **Configuration** field of the **Overrides** window if you want to use it to transform your data.

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FKIXV3quKoFlDpk7K6fAG%2Foverrides.gif?alt=media&#x26;token=1ee013c0-514e-4233-beb3-542046a0c029" alt="" width="270"><figcaption></figcaption></figure></div>

If you have set up your system to enable a x-csrf-token, add a JSON script like the on below in the **Overrides > Configuration** field.

```
{
  "xml2json": false,
  "externalSystemTypeEnum": "SAPC4C",
  "supportectContentTypes": [
    "Request"
  ],
  "contentTypeConfiguration": {
    "Request": {
      "appliesToChildren": true,
      "httpContentType": "application/json",
      "acceptContentType": "application/json",
      "pagination": {
        "type": "page",
        "useIncrementalPaging": true,
        "pageParam": "$skip",
        "limitParam": "$top",
        "defaultLimit": 1000,
        "defaultOffset": 0,
        "dateFormat": "yyyy-MM-dd'T'HH:mm:ss'Z'",
        "parameters": [
          {
            "field": "$expand",
            "operator": "eq",
            "value": "ServiceRequestTextCollection,ServiceRequestParty"
          }
        ],
        "tableEntriesArrayPath": "d.results",
        "tableEntryPath": "d.results[0]",
        "isTableEntryJSONArray": false,
        "retriesNo": 0,
        "appendTopElement": false,
        "filterConfigurations": {
          "filterParameterMappers": [],
          "filterConfigurations": [
            {
              "filterElement": "$filter",
              "filterOperator": "and",
              "operatorMappings": {
                "eq": "eq",
                "like": "eq",
                "gt": "ge",
                "neq": "ne",
                "lt": "le"
              },
              "fieldMappings": {
                "startDate": "LastChangeDateTime",
                "endDate": "LastChangeDateTime",
                "ServiceRequestLifeCycleStatusCodeText": "ServiceRequestLifeCycleStatusCodeText",
                "BuyerPartyID": "BuyerPartyID",
                "Name": "Name"
              },
              "valueMappings": {
                "startDate": "datetimeoffset'{_value_}'",
                "endDate": "datetimeoffset'{_value_}'",
                "ServiceRequestLifeCycleStatusCodeText": "'{_value_}'",
                "BuyerPartyID": "'{_value_}'",
                "Name": "'{_value_}'"
              },
              "whitelistFields": []
            }
          ]
        },
        "overrideWithDefaultLimit": false
      },
      "pathMappings": [
        {
          "path": "/sap/c4c/odata/v1/c4codataapi/ServiceRequestCollection",
          "pathByKey": "/sap/c4c/odata/v1/c4codataapi/ServiceRequestCollection?ID={_key_}&$expand=ServiceRequestTextCollection,ServiceRequestParty",
          "createPath": "/sap/c4c/odata/v1/c4codataapi/ServiceRequestCollection"
        }
      ],
      "supportedOperations": [
        "LIST",
        "GET",
        "CREATE",
        "UPDATE"
      ],
      "operations": [
        {
          "operation": "CREATE",
          "httpMethod": "post",
          "headers": {},
          "useFormPayload": false,
          "customClose": false,
          "returnGetTableEntryOnClose": false,
          "customAddComment": false,
          "useCreatePathInUpdate": false,
          "listEntryJoltTransforms": []
        },
        {
          "operation": "UPDATE",
          "httpMethod": "patch",
          "headers": {},
          "pathMappings": [
            {
              "pathByKey": "/sap/c4c/odata/v1/c4codataapi/ServiceRequestCollection('{_key_}')"
            }
          ],
          "useFormPayload": false,
          "customClose": false,
          "returnGetTableEntryOnClose": false,
          "customAddComment": false,
          "useCreatePathInUpdate": false,
          "listEntryJoltTransforms": []
        }
      ],
      "respectRequestPaginationInCount": false,
      "respectEndDate": false,
      "handleNullDatesConfiguration": true,
      "handleDefaultDatesConfiguration": false,
      "nullDateStartHoursBefore": -1000000,
      "nullDateEndHoursAfter": 0,
      "addElementAsArrayUnderTop": false,
      "downloadFiles": false,
      "timezone": "UTC",
      "doNotFailOnNestedCall": false,
      "isAttachment": false
    }
  },
  "contextParameters": {},
  "basicTokenAuth": false,
  "startDate": true,
  "endDate": true,
  "tokenConfiguration": {
    "tokenUri": "/sap/c4c/odata/v1/c4codataapi/ServiceRequestCollection?$top=1",
    "contentType": "application/json",
    "parameters": {},
    "payloadParameters": {},
    "tokenType": "Custom",
    "tokenHeader": "x-csrf-token",
    "extractCookies": true,
    "authenticateWithCookiesOnly": false,
    "ttl": 0,
    "basicHeaderAuthorization": true,
    "basicHeaderAuthorizationHeader": "Authorization",
    "tokenResponseTrimHead": 0,
    "tokenResponseTrimTail": 0,
    "extraHeaders": {
      "x-csrf-token": "fetch"
    },
    "extractTokenFromHeader": true,
    "tokenExtractPathFromHeader": "x-csrf-token",
    "requestHttpMethod": "GET"
  },
  "sleepOnErrors": 1000,
  "retries": 10,
  "rateLimitRespectNo": 0,
  "rateLimitEntriesSize": 300,
  "sleepOnRateLimit": 1000,
  "useRemoteExecutor": false,
  "timezone": "UTC",
  "record": false,
  "useInterval": false,
  "interval": 0,
  "disableFetchingServiceCatalogCategories": false,
  "githubRepos": [],
  "oAuth2PasswordClientClient": {
    "configuration": {
      "host": "tenant-server",
      "port": 8088,
      "apiBasePath": "/tenant-server/v1",
      "connectionTimeoutInMS": 30000,
      "readTimeInMS": 30000
    }
  },
  "secondReading": false,
  "hasImageProfile": true
}
```

9. If the use case for your data source is **Create Ticket Action** use the override config in the **Override Configuration for Create Ticket Action** section.
10. Click **OK**.

### Check Field Maps <a href="#check-mappings" id="check-mappings"></a>

After you have completed the data source configuration steps (above), the data is ingested (when you click the **OK** button) and the data source filed maps are shown at the bottom of the Data Source Details window, in the **Tickets** section.

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FKRcV1CbJb4AZJ3dfPxXo%2Fdata_source_details.gif?alt=media&#x26;token=c8c6887a-1cd3-4822-b405-d5d847440794" alt=""><figcaption></figcaption></figure>

You can edit the maps using the New Field Mapping, New Custom Field, Export Fields, and Import Fields buttons at the bottom of the Data Source Details window.

Most customers leave the default maps of the data source fields as they are. You may need to modify them for your specific use case or to resolve a data issue.

After editing the maps, you can run the data source to ingest tickets (click triangle-shaped run button on the **Data Source Details** window).

If you don't see any fields as a result of your Data Source Configuration setup, you can use the Generic connector for both the Ingestion and Data Source setups for any data source but you then need to create the field mappings yourself.

* **Create Ticket**

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FqYYVEH7NLAv711WPHXN8%2Foob.gif?alt=media&#x26;token=7eeef796-7606-4c10-8cb2-38af6812b9ee" alt=""><figcaption></figcaption></figure></div>

* **List Tickets by Status**\
  \
  **Note:** Disable **Use Ticket Status Mapping**:

  \
  Action screenshots from AI Lens:

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2Fbd8Wwhi7vNeMhIAHy8T4%2Faction_snapshots.gif?alt=media&#x26;token=451ff4e6-5898-4f0f-8abf-1225b3ac215d" alt=""><figcaption></figcaption></figure></div>

* **List Tickets by Name**

<div align="left"><figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FKZRMBMtb3xAXSIR59Hxb%2Flist_tickets_by_name.gif?alt=media&#x26;token=49c0dd5e-e762-4653-bdb5-d58aebf5fc14" alt=""><figcaption></figcaption></figure></div>

* **Update the Name of a Ticket**

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2Fy9XspNK2MPAj59BFkfTX%2Fname.gif?alt=media&#x26;token=6072382b-8450-4dec-8a31-b97d8496f83c" alt=""><figcaption></figcaption></figure>

* **Update the Status of a Ticket**

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2F5bgnZs4EUboYi7X25xio%2Fstatus.gif?alt=media&#x26;token=55889781-37b2-4a9f-ac1a-9ce2f9ca4195" alt=""><figcaption></figcaption></figure>

* **Get Ticket by ID**

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2Fo4uRIgDlY8tAV0H5x2pL%2Fstatusbyid.gif?alt=media&#x26;token=766cf863-b4ab-4614-b626-1aaadc8460cf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3281977978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvBFXjH9S1CAy9f5hzg5Q%2Fuploads%2FYRksvAQPPPwzVlusYNve%2Fc4c_run.gif?alt=media&#x26;token=dc20974a-daeb-4a85-99a5-6a45c20ad859" alt=""><figcaption></figcaption></figure>
