Set headers explicitly?

hi,

When making API calls from scripts, is it a good practice to set headers explicitly? If yes then what headers are most appropriate and needed for making calls to DF API? Like for the example below, what headers are necessary?

var options = {
    "CURLOPT_HTTPHEADER": ["Content-type: application/json", "Some-Other-Header: blah"]
};
 
result = platform.api.post("http://example.com/my_api", {"name":"test"}, options);

And a small doubt, when I print the result of an API call I see the following text
{"status_code":200,"content":{"resource":[{"_id":"56fe51047d57d001183c987a"}]},"content_type":null,"format":201}

Why is the content_type set to null? :thinking:

Cheers,
M.M

Hi @m_menon,

Its ok and useful in some cases, but, if you create a service inside DF and need to call this service, you dont need to set headers and also dont need use your full URL. Just call like this:

result = platform.api.post(“my_service_name”, {“name”:“test”});

The content type in your header, tells what you are sending and not what you will receive. Maybe your “http://example.com/my_api” doesn’t set the content-type, so the content_type is set to null by DF.

hi Anderson,

Alrightey thanks…that clears it up :slight_smile:

Cheers,
M&M