User Context successfully creates authenticated URI for "whoami" but not POST call to create user

61 views
Skip to first unread message

steev sachs

unread,
Jul 29, 2014, 9:36:11 AM7/29/14
to valenc...@googlegroups.com
I am using PHP.  I have successfully created a user context from the host spec ($opContext) and from that am creating an authenticated uri.

When I use 

$url = $opContext->createAuthenticatedUri( "$scheme://$host/d2l/api/lp/1.1/users/whoami", GET )

I am returned the correct JSON block for my user context.

When I use

$url = $opContext->createAuthenticatedUri( "$scheme://$host/d2l/api/lp/1.1/users/", POST )

and change the cURL parameters accordingly, I receive a response of "Invalid Token."

Can you advise why I might be getting this response for only a specific call?

Scott

unread,
Jul 29, 2014, 11:17:26 AM7/29/14
to valenc...@googlegroups.com
Looks right to me.
I use $uri = $opContext->createAuthenticatedUri('/d2l/api/lp/'.$lpVers.'/enrollments/', 'POST');
More details?

Desire2Learn Staff: Jacob Parker

unread,
Jul 29, 2014, 11:59:58 AM7/29/14
to valenc...@googlegroups.com
Scott is right: the first argument of createAuthenticatedUri only needs to be a route, not the full URI (although it should work either way...) (you also probably want quotes on that POST)

One thing to check is that the user context object has the right userId and userKey populated; print them to the screen/page and verify that they look right. (Don't paste them here :)) Incorrect values in the userContext or appContext don't explain why whoami would work but others not, though. Providing more code could help us understand.

If everything still looks good, try signing the request with the following credentials:
  userId: abc
  userKey: xyz
  appId: 123
  appKey: 456

and tell us what the URL you get is.

steev sachs

unread,
Jul 29, 2014, 12:14:01 PM7/29/14
to valenc...@googlegroups.com
Hi All,

Thank you for your responses.  I've tried with the dummy values and still receive Invalid Token.

It's worth noting a few things:
  • The Sample from the Valence dev site is able to successfully create a user.
  • I have copied my test file exactly over to our dev server and it works without issue, successfully creating a user.
This code, exactly as it is, continues to work without issue on our dev server.

I'm completely bewildered by this issue.  I'd love to say it's server config, but then why is it working for the Sample page, as well as for other besides the POST to create a user?

steev sachs

unread,
Jul 29, 2014, 12:29:43 PM7/29/14
to valenc...@googlegroups.com
For the record, the user context object comes back populated with all correct values.

Is there anything that could "mimic" an Invalid Token and cause the error?

I can now confirm that this is only occurring for POST requests.  In testing to see if it was somehow a misformation of my JSON, I tried the POST call to trigger a password reset (which does not take a data object) and received the same Invalid Token response.

On the other hand, I have run other GET calls successfully.

Scott

unread,
Jul 29, 2014, 1:22:34 PM7/29/14
to valenc...@googlegroups.com
>> Is there anything that could "mimic" an Invalid Token and cause the error?
What are your cURL curl_setopt's?

steev sachs

unread,
Jul 29, 2014, 1:55:49 PM7/29/14
to valenc...@googlegroups.com
The setopts were indeed to blame--this is now resolved.  I went back through and revised some of my curl options (tried doing a custom "POST" rather than a straight POST call, for example) and eventually I must've hit the nail on the head.

I remain a little unclear on why a curl call from one server would work with certain options, and the identical call would not work from another server, but I suspect that's not an issue with the API.  
Reply all
Reply to author
Forward
Message has been deleted
0 new messages