GraphQL to CURL example

Viewed 15

I'm attempting to test an API from FreeAgent CRM that implements GraphQL.

I'm struggling to format the request for the following example. https://api.freeagent.network/#list-app-fields

This is the example of the request:

query getFields($entity:String,$show_hidden:Boolean) {
  getFields(entity:$entity,show_hidden:$show_hidden){
    id
    name
    name_label
    main_type
    is_required
    is_visible
    is_unique
    default_value
    catalog_type_id
    reference_field_id
    reference_fa_entity_id
    reference_fa_entity_name
  }
}

I've converted this to json in order to send it with a cURL request from the command line.

curl -i -H "Authorization: bearer MY_TOKEN" -X POST -d '{"query": "query getFields($entity:"products",$show_hidden:false) { getFields(entity:$entity,show_hidden:$show_hidden){ id name name_label main_type is_required is_visible is_unique default_value catalog_type_id reference_field_id reference_fa_entity_id reference_fa_entity_name }}"}' https://freeagent.network/api/graphql

I've attempted to format this various ways, I'm not sure if I'm interpreting the graphql documentation wrong, or if there is something funny happening in this specific API and how it is setup.

Regardless of the format that I try to send, I get an error that no query string is supplied.

{"errors":[{"message":"Must provide query string."}]}

I've reached out to the support team, but wanted to cast a broader net so that I can learn more about graphql as I'm sure I'll get a better explanation as to what I'm doing wrong from the SO community.

1 Answers

Went and used postman to build the GraphQL and exported the cURL syntax after it was working properly.

curl --location --request POST 'https://freeagent.network/api/graphql' \
--header 'Authorization: bearer MY_TOKEN' \
--header 'Content-Type: application/json' \
--header 'Cookie: hazel=True' \
--data-raw '{"query":"query listEntityValues($entity: String!, $fields: [String], $order: [[String]], $limit: Int, $offset: Int, $pattern: String, $filters: [Filter]) {\n        listEntityValues(entity: $entity, fields: $fields, order: $order, limit: $limit, offset: $offset, pattern: $pattern, filters: $filters) {\n          count\n          entity_values {\n            id\n            seq_id\n            field_values\n          }\n        }\n      }","variables":{"entity":"product","show_hidden":false}}'
Related