2

I am a new Salesforce developer.

I got an assignment where I have to get connected to an API using developer_id;developer_key

The documentation says,

Developer authentication involved sending a specifically formatted token as a header with your request.

The header is generated with the use of your developer_id and developer key.

The header is comprised like so: Mysite-Developer-Auth-V1: <developer_id>;<developer_key>

The following is a sample of a curl request with a valid auth header:

curl \
   -X POST "http://www.Mysite.com/api/users/0.1/self/jobs/" \
   -H 'Mysite-Developer-Auth-V1: 12345678;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
   -H "Content-Type: application/json" --data '{"jobs[]": [1,2,3]}'

Which is the best method to Authenticate and why:

1. HTTP callout?
2. Or CURL

Note that I have to carry forward the token returned by the API, to execute other functions(API).

How do I pass the header?Here is my incomplete code that I have tried

 Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('http://www.mysite.com/api/users/0.1/self/jobs/');
    request.setMethod('GET');
    HttpResponse response = http.send(request);
    // If the request is successful, parse the JSON response.
    if (response.getStatusCode() == 200) {
       //

    }

1 Answer 1

1

You can add a header to your request by using

request.addHeader(*headername*, *headervalue*);

That should let you pass the header as you'd do in curl. Also, Your code sample uses GET but your curl uses POST. Just mentioning it because GET would get any parameters visible in the querystring and registered in any logs you (or the called service) might keep.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .