---
keyword: [Extend, Workday Graph API, Graph API, GraphQL]
nav: wcp_docs
parent_url: /wcp_docs/
title: Submit Graph API Mutations on a Page
layout: subsection
---

### Prerequisites

<a id="prereq_N10021_N1001E_N10001"></a>
-   For the mutations you want to use in your Extend app, construct and test them in the Graph API Explorer.

    See [Graph API Mutations](/wcp_docs/kbu1671067116723.html).

-   One or more edit PMDs where you'd like to submit the Graph API mutation.
-   Security:

    -   <i>Workday Graph API Applications</i> domain in the System functional area.
    -   Security domains that control access to the business objects in the mutations. The mutation descriptions in the Graph API schema documentation list the required security domains.



### Context

<a id="context_N10045_N1001E_N10001"></a>
To submit a Graph API mutation from an edit page, call the Graph API endpoint as an outbound endpoint. Use the default POST method. Specify the mutation in the `graphQuery` attribute of the endpoint.

You can specify the mutation either in:

-   An inline mutation in the PMD endpoint, or
-   A Graph Query component.


This procedure uses inline mutations in the PMD endpoints. To see examples of mutations in Graph Query components, see [Sample Graph Query Components in PMDs](/wcp_docs/yvb1682352201818.html).

### Steps

1.  <a id="step_N10060_N1005D_N1001E_N10001"></a>Open the Extend app.
2.  <a id="step_N10069_N1005D_N1001E_N10001"></a>In the AMD, add the Graph API endpoint to `dataProviders[]`.

    ```
    {
     "key" : "workday-graph",
     "value" : "https://api.workday.com/graphql/v1/"
    }
    ```

3.  <a id="step_N10169_N10079_N1003E_N10001"></a>In the PMD, add an endpoint to `outboundEndPoints[]` whose `baseUrlType` is the Graph API endpoint.

    Example:

    ```
     "outboundEndPoints" : [ {
       "name" : "initiateJobChange",
       "baseUrlType" : "workday-graph",
       "authType" : "sso",
       "httpMethod" : "POST",
       "failOnStatusCodes" : [ {
         "code" : 400
       } ]
     }
    ]
    ```

    <b>Note:</b>

    -   The Graph API endpoint uses the POST method, which is the default `httpMethod` value of an outbound endpoint.
    -   The endpoint doesn't include the `url` attribute because the `baseUrlType` value in the AMD specifies the full Graph API endpoint URL.

4.  <a id="step_N100DB_N10096_N10056_N10001"></a>Add the `graphQuery` attribute to the endpoint.

    In `graphQuery`, specify the mutation in the `query` property and the input variables in the `variables` property.

    This sample outbound endpoint runs the `initiateWorkerJobChange` mutation. The input variables contain data from page variables. The `initiateWorkerJobChange` also requires a worker ID, which is another query variable containing a flow variable.

    ```
    "outboundEndPoints" : [
      {
         "name" : "initiateJobChange",
         "baseUrlType" : "workday-graph",
         "authType" : "sso",
         "httpMethod" : "POST",
         "graphQuery" : {
           "query" : "mutation initiateJobChangeEvent(
                               $input: Staffing_JobChangesStartDetailsPOSTData_CreateInput!, $workerId: ID!) {
             initiateWorkerJobChange(input: $input, workerId: {id: $workerId}) {
               date
               workdayID {
                 id
               }
             }
           }",
           "variables" : {
             "input" : {
               "date": "<% requestDate.value.format('yyyy-MM-dd') %>",
               "reason": {
                 "id": {
                   "id": "<% pageVariables.reasonId %>",
                   "type": "WID"
                 }
               }
             },
             "workerId" : "<% flowVariables.workerFlowVariable.id %>"
           }
         },
         "failOnStatusCodes" : [ {
           "code" : 400
         } ]
       }
    ]
    ```

5.  <a id="step_N10170_N1005C_N1001E_N10001"></a>Use the returned data from the outbound endpoint, as appropriate.

    Example: To change the business title of the worker, we'll need to submit this next mutation using the returned job change ID from the `initiateJobChange` endpoint. Note the <i>jobChangeId</i> query variable, which uses <i>initiateJobChange.data.initiateWorkerJobChange.id.id</i> returned by the preceding mutation. The <i>businessTitle</i> variable uses a text widget value.

    ```
    {
         "name" : "updateBusinessTitle",
         "baseUrlType" : "workday-graph",
         "authType" : "sso",
         "httpMethod" : "POST",
         "graphQuery" : {
           "query" : "mutation updateBusinessTitle($jobChangeId: ID!, $businessTitle: String) {
             updateJobChangeBusinessTitle(
               businessTitleId: {id: $jobChangeId}
               input: {businessTitle: $businessTitle}
               jobChangeId: {id: $jobChangeId}
             ) {
               businessTitle
             }
           }",
           "variables" : {
             "jobChangeId" : "<% initiateJobChange.data.initiateWorkerJobChange.id.id %>",
             "businessTitle" : "<% newTitle.value %>"
           }
         },
         "failOnStatusCodes" : [ {
           "code" : 400
         } ]
       }
    ```

    The shopping cart pattern of the Job Change event requires another mutation that commits the updated business title. See the <i>submitJobChange</i> endpoint in the Example section.

6.  <a id="step_N10145_N1005D_N1001E_N10001"></a>Deploy and test the app on the tenant.


### Example

This sample PMD calls the series of Job Change mutations to update a business title. It also uses a query to display the current title, a `text` widget for the new title, and a `date` widget for the request date.

```
{
 "id" : "changeBusinessTitle",
 "onLoad" : "<%
   pageVariables.reasonId = '32e3a48dc5f24cd2acb4c5c0e852c08a';
 %>",
 "endPoints" : [ {
   "name" : "workerById",
   "baseUrlType" : "workday-graph",
   "authType" : "sso",
   "httpMethod" : "POST",
   "graphQuery" : {
     "query" : "query getWorkerById($workerId: ID!){
         worker(
           dataSource: {indexedAllWorkers: {
               filter: {
                 indexedAllWorkersFilter: {}
               }
             }
           },
           where: {
             workdayID: {
               in: [
                 {id: $workerId}
               ]
             }
           }
         ) {
           data{
             businessTitle
             workdayID{
               id
             }
           }
         }
       }
     ",
     "variables" : {
       "workerId" : "<% flowVariables.workerFlowVariable.id %>"
     }
   },
   "failOnStatusCodes" : [ {
     "code" : 400
   } ]
 } ],
 "outboundData" : {
   "outboundEndPoints" : [ {
     "name" : "initiateJobChange",
     "baseUrlType" : "workday-graph",
     "authType" : "sso",
     "httpMethod" : "POST",
     "graphQuery" : {
       "query" : "mutation initiateJobChangeEvent(
                           $input: Staffing_JobChangesStartDetailsPOSTData_CreateInput!, $workerId: ID!) {
         initiateWorkerJobChange(input: $input, workerId: {id: $workerId}) {
           date
           workdayID {
             id
           }
         }
       }",
       "variables" : {
         "input" : {
           "date" : "<% requestDate.value.format('yyyy-MM-dd') %>",
           "reason" : {
             "id" : {
               "id" : "<% pageVariables.reasonId %>",
               "type" : "WID"
             }
           }
         },
         "workerId" : "<% flowVariables.workerFlowVariable.id %>"
       }
     },
     "failOnStatusCodes" : [ {
       "code" : 400
     } ],
     "onSend" : "<%
         console.debug('DEBUG initiateJobChange Graph API payload: ' + self.data.toString());
         self.data;
     %>"
   }, {
     "name" : "updateBusinessTitle",
     "baseUrlType" : "workday-graph",
     "authType" : "sso",
     "httpMethod" : "POST",
     "graphQuery" : {
       "query" : "mutation updateBusinessTitle($jobChangeId: ID!, $businessTitle: String) {
         updateJobChangeBusinessTitle(
           businessTitleId: {id: $jobChangeId}
           input: {businessTitle: $businessTitle}
           jobChangeId: {id: $jobChangeId}
         ) {
           businessTitle
         }
       }",
       "variables" : {
         "jobChangeId" : "<% initiateJobChange.data.initiateWorkerJobChange.workdayID.id %>",
         "businessTitle" : "<% newTitle.value %>"
       }
     },
     "failOnStatusCodes" : [ {
       "code" : 400
     } ],
     "onSend" : "<%
         console.debug('DEBUG updateBusinessTitle Graph API payload: ' + self.data.toString());
         self.data;
     %>"
   }, {
     "name" : "submitJobChange",
     "baseUrlType" : "workday-graph",
     "authType" : "sso",
     "httpMethod" : "POST",
     "graphQuery" : {
       "query" : "mutation submitJobChange($jobChangeId: ID!) {
         submitJobChange(
           input: {}
           jobChangeId: {id: $jobChangeId}
         ) {
           workdayID {
             id
           }
         }
       }",
       "variables" : {
         "jobChangeId" : "<% initiateJobChange.data.initiateWorkerJobChange.workdayID.id %>"
       }
     },
     "failOnStatusCodes" : [ {
       "code" : 400
     } ],
     "onSend" : "<%
         console.debug('DEBUG submitJobChange Graph API payload: ' + self.data.toString());
         self.data;
     %>"
   } ]
 },
 "presentation" : {
   "title" : {
     "type" : "title",
     "label" : "Workday Extend"
   },
   "body" : {
     "type" : "section",
     "horizontal" : false,
     "children" : [ {
       "type" : "text",
       "id" : "workerName",
       "label" : "Worker Name:",
       "enabled" : false,
       "value" : "<% flowVariables.workerFlowVariable.descriptor %>"
     }, {
       "type" : "text",
       "id" : "currentTitle",
       "label" : "Current Business Title",
       "enabled" : false,
       "value" : "<% workerById.data.worker.data[0].businessTitle %>"
     }, {
       "type" : "text",
       "id" : "newTitle",
       "label" : "Enter new title:"
     }, {
       "type" : "date",
       "id" : "requestDate",
       "label" : "Enter a request effective date:"
     } ]
   }
 }
}
```

### Related Information

[Generate Queries on Graph API Explorer](/wcp_docs/uip1679531855079.html)

