function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Siri Deva Singh KhalsaSiri Deva Singh Khalsa 

monday.com api (Apex, JSON, graphQL)

Hi Folks,

I'm tyring to connect to the monday.com api, which, as far as I understand, accepts graphQL queries in JSON format (https://monday.com/developers/v2).

When I run the code below, I get a 400 'no query string was present' error.

If I run the method
req.SetHeader('Content-Type', 'application/json')

I can't even authenticate.

Any ideas?
 
public class mondayAPI{
    public static httpResponse callout(){

        String apiKey = 'mySuperSecretApiKey';
        String query = '{ "query" { "boards"(ids: 813785147)}} ';
        //instantiate httpRequest

        HttpRequest req = new HttpRequest();

        //set http method and endoint for request instance
        req.setMethod('POST');
        req.setEndpoint('https://api.monday.com/v2');

        //set body and header
        req.setHeader('Authorization', apiKey);
        req.setBody(query);

        //instantiate the http

        http h = new http();

        //make the call out using the http.send() method
        HttpResponse res = h.send(req);

        Integer statusCode = res.getStatusCode();

        String status = res.getStatus();

        String body = res.getBody();
        System.debug('Request Body: ' + req.getBody());
        System.debug(statusCode);
        System.debug(status);
        System.debug(body);

        return res;


    }
}

 
Best Answer chosen by Siri Deva Singh Khalsa
Siri Deva Singh KhalsaSiri Deva Singh Khalsa
I figured this out. I had two errors.
The graphQL within my JSON request body was malformed.
correct is: 
String query = '{ "query" : "{boards(ids:413622857){id}}" }';


The content-type request header needs to be set to json:
 
req.setHeader('Content-Type', 'application/json');

 

All Answers

AnudeepAnudeep (Salesforce Developers) 
A “no query string was present” error means the server thinks the body of your request is empty

I recommend trying the request in postman to confirm if the endpoint is correct

I also suggest posting this in the Monday community

https://community.monday.com/t/error-no-query-string-present/2704

https://community.monday.com/t/no-query-string-present-for-python-based-queries/1278/2

Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!
Siri Deva Singh KhalsaSiri Deva Singh Khalsa
Thanks Anudeep. I’ll reach out to the Monday.com community and see what I can find out. -S Michael Rencewicz Data Analyst | Castle Group 12270 SW 3rd Street, Suite 200, Plantation, FL 33325 P: 954-660-1823 | C: | F: mrencewicz@castlegroup.com | www.castlegroup.com
Siri Deva Singh KhalsaSiri Deva Singh Khalsa
I figured this out. I had two errors.
The graphQL within my JSON request body was malformed.
correct is: 
String query = '{ "query" : "{boards(ids:413622857){id}}" }';


The content-type request header needs to be set to json:
 
req.setHeader('Content-Type', 'application/json');

 
This was selected as the best answer