bannerColor WARNING_YELLOW templateName stackForums

Invitation API - Unauthorized access

3 posts / 0 new
Last post
Fikre Leguesse's picture
Joined: 2011-08-30
May 10, 2013
Invitation API - Unauthorized access

Is there anything wrong with the below request? I keep getting an 'Unauthorized Access' response

POST http://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=MyAccessToken HTTP/1.1
Content-Type: application/json; charset=utf-8
x-li-format: json
Host: api.linkedin.com
Content-Length: 223
Expect: 100-continue

{"recipients":{"values": [{"_path":"/people/IDRetrievedFromSearch"}]},"subject":"Test Subject","body":"Test Body","item-content": { "invitation-request": { "connect-type":"friend","authorization":{"name":"NAME_SEARCH","value":"pXCC"}}}}

Shikha A. Sehgal's picture
LinkedIn Employee
Joined: 2012-07-27
May 10, 2013

hey Fikre:

Are you using w_messages member permission as explained in this doc - http://developer.linkedin.com/documents/invitation-api

Jack Sparrow's picture
Joined: 2014-05-21
Jun 2, 2014

I am so new to LinkedIn

Hi I have used the following code to send a connection request using linkedIn mailbox api.

NSString *str=[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=%@&format=json",authToken];

NSMutableURLRequest *request=[NSMutableURLRequest
requestWithURL:[NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:4.0];

NSDictionary *requestData =@{@"recipients":@{
@"values":@[
@{
@"person":@{
@"_path":[NSString stringWithFormat:@"/people/id=%@",memberId]
}
}]
},
@"subject": @"Invitation to connect.",
@"item-content":@{
@"invitation-request":@{
@"connect-type":@"friend",
}
}
}
;
NSError *error2;
NSData *postData = [NSJSONSerialization dataWithJSONObject:requestData options:0 error:&error2];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];

NSURLResponse *response;
NSError *error=nil;
NSData *connection=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(!error)
{
completionBlock(YES,nil);

}

I could see few fields in the header additional to that of

"invitation-request":{
"connect-type":"friend",
"authorization":{
"name":"NAME_SEARCH",
"value":"pXCC"}
}

"authorization field which i have omitted in the json header because i have no idea how to get those values of 'name' and 'value'..

When inviting by member id, you must include a name and value node under invitation-request/authorization. You can get these authorization codes from standard profile and search results.

which api is are you mentioning above.