Skip to content

Instantly share code, notes, and snippets.

@renatoliveira
Created October 13, 2023 17:31
Show Gist options
  • Save renatoliveira/0f21bd8feb125d66e7ad39994ed3d13a to your computer and use it in GitHub Desktop.
Save renatoliveira/0f21bd8feb125d66e7ad39994ed3d13a to your computer and use it in GitHub Desktop.
Apex to MondayAPI
public class MondayApi {
@SuppressWarnings('PMD.ApexSuggestUsingNamedCred')
public static Map<String, Object> execute(String query) {
HttpRequest request = new HttpRequest();
request.setEndpoint('callout:MondayApi');
request.setMethod('POST');
request.setBody(JSON.serialize(new Map<String, Object>{
'query' => query
}));
request.setHeader('Content-Type', 'application/json');
request.setHeader('Authorization', '{!$Credential.Password}');
HttpResponse response = new Http().send(request);
Map<String, Object> responseBodyAsMap = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
return responseBodyAsMap;
}
}
String escapedPayload = JSON.serialize(new Map<String, Object>{
'numbers' => '0',
'link' => new Map<String, Object>{
'text' => 'Google',
'url' => 'https://google.com'
},
'email' => new Map<String, Object>{
'email' => 'ronaldo@sample.com',
'text' => 'Ronaldo'
},
'checkbox' => new Map<String, Object>{
'checked' => 'true'
},
'date3' => new Map<String, Object>{
'date' => '2023-10-13'
},
'people7' => new Map<String, Object>{
'personsAndTeams' => new List<Object>{
new Map<String, Object>{
'id' => '42466775',
'kind' => 'person'
}
}
}
});
MondayApi.execute(
'mutation {' +
'create_item (board_id: 4442867299, group_id: "other", item_name: "new item", column_values: "' + escapedPayload.escapeJava() + '") {' +
' id' +
'}' +
'}'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment