Page 1 of 1

attaching resume to a candidate

Posted: Fri Dec 06, 2013 3:05 pm
by mgeltser
Hi,

I am trying to attach a file (simple text resume) to a candidate using this url:
https://rest5.bullhornstaffing.com/rest ... ype=Resume

I am using PUT method and writing the file as a byte array to the request stream.

I am getting InternalServerError {500} exception thrown...

I am using .NET as a development environment.

I would appreciate any help in pointing out what I am doing wrong...
Thanks,
Mike

Re: attaching resume to a candidate

Posted: Wed Dec 11, 2013 1:01 pm
by mgeltser
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title></head>
<body>
<form id="form1" method="put" enctype="multipart/form-data" action="https://rest5.bullhornstaffing.com/rest ... ype=SAMPLE" >
<div>
<input type="file" name="resumeFile" />
<br />
<input type="submit" name="button" value="Attach" />
</div>
</form>
</body>
</html>

I get 400 error bad request.

Any help would be much appreciated

Mike

Re: attaching resume to a candidate

Posted: Fri Jan 23, 2015 11:18 am
by webtech4rindia
Any luck guy with these issue? on .NET framework.

thx

Re: attaching resume to a candidate

Posted: Fri Jan 23, 2015 1:20 pm
by mgeltser
Unfortunately i could not get it to work, had to use SOAP APIs instead

Re: attaching resume to a candidate

Posted: Tue Jan 27, 2015 5:14 pm
by srg.bdavis
I couldn't get the /raw method to work either so we used the Base64 string method. Here is what we currently use to attach a resume to an existing candidate (.Net 4.5):

Code: Select all

public async Task<bool> UploadResume(int candidateId, byte[] resume, string fileName, string fileExtension, string description)
        {
            var upload = new FileUpload();
            upload.FileContent = Convert.ToBase64String(resume);
            upload.ExternalID = "portfolio";
            upload.Name = fileName;
            upload.FileType = "SAMPLE";
            upload.Description = description;
            upload.Type = "Resume";

            switch (fileExtension)
            {
                case ("doc"):
                    upload.ContentType = "application/msword";
                    break;
                case ("docx"):
                    upload.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    break;
                case ("pdf"):
                    upload.ContentType = "application/pdf";
                    break;
                case ("txt"):
                    upload.ContentType = "text/plain";
                    break;
                case ("rtf"):
                    upload.ContentType = "application/rtf";
                    break;
                case ("odt"):
                    upload.ContentType = "application/odt";
                    break;
                case ("html"):
                    upload.ContentType = "text/html";
                    break;
                case ("htm"):
                    upload.ContentType = "text/html";
                    break;
                default:
                    upload.ContentType = "text/plain";
                    break;
            }

            var token = await OAuthProvider.GetRestToken();
            var restToken = token["token"];
            var restUrl = token["url"];

            var requestUri = new StringBuilder(restUrl);
            requestUri.Append(string.Format("file/Candidate/{0}?", candidateId));
            requestUri.Append(string.Format("&BhRestToken={0}", restToken));

            using (var client = new HttpClient())
            {
                var response = await client.PutAsJsonAsync(requestUri.ToString(), upload);

                if (response.IsSuccessStatusCode)
                {
                    return true;
                }
                else
                {
                    var error = string.Empty;

                    if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                    {
                        var apiError = await response.Content.ReadAsAsync<ApiError>();
                        error = apiError.ConvertDetailToString();
                    }
                    else
                    {
                        error = await response.Content.ReadAsStringAsync();
                    }
                    throw new Exception(string.Format("Unable to attach resume to candidate: {0}", error));
                }
            }
        }
The FileUpload object is just a class containing the properties required in the /put/file method for the api.

It looks like this:

Code: Select all

public class FileUpload
    {
        [JsonProperty("externalID")]
        public string ExternalID { get; set; }

        [JsonProperty("fileContent")]
        public string FileContent { get; set; }

        [JsonProperty("fileType")]
        public string FileType { get; set; }

        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("contentType")]
        public string ContentType { get; set; }

        [JsonProperty("description")]
        public string Description { get; set; }

        [JsonProperty("type")]
        public string Type { get; set; }
    }
The request uri ends up looking like this:
https://rest.bullhorn.com/rest-services ... {restToken}