Mint ORCID's via PHP script

367 views
Skip to first unread message

dhahn

unread,
Jan 28, 2014, 4:17:25 PM1/28/14
to orcid-a...@googlegroups.com
All-

I have been able to recreate the command line functionality for most of the CURL example in PHP.  I have not been able to get the correct CURL options set that would allow me to mint an ID from withing PHP without various errors.

In the end my solution was to have PHP execute a command line CURL and then return the results for parsing.  Before I go into the various things I tried has anyone got a working solution for executing a CURL request withing PHP.

Like I said I do have a work around but now I am just curious.

Doug

Kathy King

unread,
Jan 29, 2014, 1:58:12 PM1/29/14
to orcid-a...@googlegroups.com
We aren't using PHP but we are successfully using JSON with javascript for searching, if that's an option for you.

Demeranville, Tom

unread,
Jan 29, 2014, 6:57:59 PM1/29/14
to Kathy King, orcid-a...@googlegroups.com

I'll be adding the ability to the orcid-java-client (https://github.com/TomDemeranville/orcid-java-client) at some point soon too if that's any help.  It'll currently append works but not create complete profiles.  It'd be a quick job to add it I think.

I've not used CURL from PHP for a while now but perhaps if you post up the code and errors we'll be able to help.

Tom.

--
You received this message because you are subscribed to the Google Groups "ORCID API Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orcid-api-use...@googlegroups.com.
To post to this group, send email to orcid-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/orcid-api-users.
For more options, visit https://groups.google.com/groups/opt_out.


James Powell

unread,
Jul 9, 2014, 12:57:46 PM7/9/14
to orcid-a...@googlegroups.com, kkin...@gmail.com, tom.deme...@bl.uk
I'm part of an organization that's planning to create new Orcid profiles for its staff. We're not members yet so I am using the sandbox. I am trying to create a new profile using client credentials and your java client library, described here:


Although I do see a createOrcidProfile() method for your OrcidOAuth client class, I don't see how to do client credential auth/auth in order to be able to create a new profile. It seems the client expects that I have an authorization code that was supplied when a user logged in with their own Orcid credentials, before I can get an access token. Am I missing something?

thanks,
James.

Oyler, Catalina

unread,
Jul 9, 2014, 2:12:23 PM7/9/14
to James Powell, orcid-a...@googlegroups.com, kkin...@gmail.com, Demeranville, Tom
Hi James,

You can use your sandbox credentials to generate an access token for creating records.  The steps to do that are described in the first part of the document at http://support.orcid.org/knowledgebase/articles/162412-tutorial-create-a-new-record-using-curl

Best,
-Catalina


For more options, visit https://groups.google.com/d/optout.

James Powell

unread,
Jul 9, 2014, 2:52:30 PM7/9/14
to orcid-a...@googlegroups.com, james.e...@gmail.com, kkin...@gmail.com, tom.deme...@bl.uk
Using curl, I've been able to authenticate using client credentials, retrieve an access token, and use it to create a new Orcid profile with no problem in the sandbox. I'm trying to figure out how to use the java client API mentioned previously to do the same thing.  We're not going to do a mass profile creation, so I can't rely on a script that makes curl requests to create a bunch of profiles. Instead, a local person will use a web app to look themselves up in our ldap server via an employee id. The data they find will be inserted into a Web form that they can review/edit. Once they supply any additional information or make changes, they will submit this form. The target of this form submission will be "something" that uses the Orcid API to create a new profile. 

Are you maybe suggesting that I can somehow use the access token I obtained with curl in the context of Tom Demeranville's orchid java client? The problem I'm having is that I don't see a way to use, create or supply an access token to the OrcidOauthClient so I can make a subsequent API call using only client credentials. 

Peters, Robert

unread,
Jul 9, 2014, 3:25:48 PM7/9/14
to James Powell, orcid-a...@googlegroups.com, kkin...@gmail.com, Demeranville, Tom
Hi James,
Dan's client doesn't currently support creating a profile. You'll have to extend Dan's client or implement your own client. I'm sure he would be happy to merge that addition if you're inclined contribute.

Cheers,
Rob
--

Robert Peters
Lead Developer at ORCID.org

Cellphone: +1.805.440.9056
Skype: rcpeters
Timezone: PST

Demeranville, Tom

unread,
Jul 10, 2014, 6:52:17 AM7/10/14
to Peters, Robert, James Powell, orcid-a...@googlegroups.com, kkin...@gmail.com
Hi James,

I could look at putting that functionality into the library next week if it's needed.  It doesn't sound complex and shouldn't take too long.

Tom.

From: orcid-a...@googlegroups.com [orcid-a...@googlegroups.com] on behalf of Peters, Robert [r.pe...@orcid.org]
Sent: 09 July 2014 20:25
To: James Powell
Cc: orcid-a...@googlegroups.com; kkin...@gmail.com; Demeranville, Tom
Subject: Re: [ORCID API] Re: Mint ORCID's via PHP script


 
******************************************************************************************************************
Experience the British Library online at www.bl.uk
The British Library’s latest Annual Report and Accounts : www.bl.uk/aboutus/annrep/index.html
Help the British Library conserve the world's knowledge. Adopt a Book. www.bl.uk/adoptabook
The Library's St Pancras site is WiFi - enabled
*****************************************************************************************************************
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify the postm...@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
*****************************************************************************************************************
Think before you print

James Powell

unread,
Jul 10, 2014, 1:11:35 PM7/10/14
to orcid-a...@googlegroups.com, r.pe...@orcid.org, james.e...@gmail.com, kkin...@gmail.com, tom.deme...@bl.uk
that would be great. It kinda looked to me like you were laying the groundwork for this in your code already. I played around with adding a new version of the getAccessToken method to the OrcidOAuth client class that would make a client credential only authentication request, but ran into an odd problem with the ssl certificate used by the sandbox. we would definitely use this functionality. let me know how I might be of assistance. 

Demeranville, Tom

unread,
Jul 11, 2014, 3:48:25 AM7/11/14
to James Powell, orcid-a...@googlegroups.com, r.pe...@orcid.org, kkin...@gmail.com
[aside - Unit Testing OAuth APIs.]

I'm just revisiting the code now.  One of the issues here was working out how to automate testing of the OAuth client as it requires user interaction with ORCiD to log in.  In the end I used the orcid-update application as a test harness and chromedriver to fire up an actual chrome instance to do it.  This has a couple of issues, the main ones being that unit tests for the library are in a different package and that they require outside dependency, chrome.

If anyone knows of a better way of testing against an OAuth protected API, let me know!

(I've got uint tests for the parts which don't require an ORCiD login)

Tom.

From: James Powell [james.e...@gmail.com]
Sent: 10 July 2014 18:11
To: orcid-a...@googlegroups.com
Cc: r.pe...@orcid.org; james.e...@gmail.com; kkin...@gmail.com; Demeranville, Tom

Martin Fenner

unread,
Jul 11, 2014, 3:59:08 AM7/11/14
to tom demeranville, James Powell, orcid-a...@googlegroups.com, Robert Peters, kkin...@gmail.com
Tom,

I’m a big fan of PhantomJS - a headless browser - for testing user interfaces.

Best, Martin


Tom.
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify thepostm...@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
*****************************************************************************************************************
Think before you print
-- 
You received this message because you are subscribed to the Google Groups "ORCID API Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email toorcid-api-use...@googlegroups.com.

Demeranville, Tom

unread,
Jul 11, 2014, 4:31:01 AM7/11/14
to Martin Fenner, James Powell, orcid-a...@googlegroups.com, Robert Peters, kkin...@gmail.com
Cheers martin, I'll check it out.  Chromedriver does similar and seems to work.

I guess I'm venting my frustration that you have to write a test harness to test these things.

Tom.



From: orcid-a...@googlegroups.com [orcid-a...@googlegroups.com] on behalf of Martin Fenner [m...@martinfenner.org]
Sent: 11 July 2014 08:59
To: Demeranville, Tom
Cc: James Powell; orcid-a...@googlegroups.com; Robert Peters; kkin...@gmail.com
Subject: Re: [ORCID API] Mint ORCID's via PHP script

Demeranville, Tom

unread,
Jul 11, 2014, 4:36:53 AM7/11/14
to James Powell, orcid-a...@googlegroups.com, r.pe...@orcid.org, kkin...@gmail.com
Hi James,

I've got past the cert issue - change the constants to remove the sandbox-1 part of the url.  This is caused by the cert orcid.org being invalid for that subdomain.  IIRC I had to put it in at the time because v1.1 of the api wasn't finalised.  

private static final String SANDBOX_LOGIN_URI = "https://sandbox.orcid.org";

private static final String SANDBOX_API_URI_TOKEN = "https://api.sandbox.orcid.org";

private static final String SANDBOX_API_URI_V1_1 = "http://api.sandbox.orcid.org/v1.1";


I've added a method to get the token but I'm getting 401 unauthorised for some reason. This seems to happen with both the live and sandbox APIs.  Not sure if you can tell why?  Perhaps my account isn't authorised but yours is...


/** Fetch an access token that enables the creation of ORCiD profiles

* @return

* @throws IOException 

*/

public OrcidAccessToken getCreateProfileAccessToken() throws IOException{

Reference ref = new Reference(apiUriToken + TOKEN_ENDPOINT);

ClientResource client = new ClientResource(ref);

Form f = new Form();

f.add("client_id", clientID);

f.add("client_secret", clientSecret);

f.add("acope", OrcidAuthScope.CREATE_PROFILE.toString());

f.add("grant_type", "client_credentials");

Representation rep = client.post(f, MediaType.APPLICATION_JSON);

String json = rep.getText();

OrcidAccessToken token = new ObjectMapper().reader(OrcidAccessToken.class).readValue(json);

return token;

}




Tom.


From: James Powell [james.e...@gmail.com]
Sent: 10 July 2014 18:11
To: orcid-a...@googlegroups.com

Demeranville, Tom

unread,
Jul 11, 2014, 4:53:09 AM7/11/14
to James Powell, orcid-a...@googlegroups.com, r.pe...@orcid.org, kkin...@gmail.com
doh, I'm an idiot.   There was a typo there.

I'll update the repository to contain the new version of the class, method to fetch an access token and unit test.

James - Do you think you could do the bit that posts profiles?

Tom.

From: orcid-a...@googlegroups.com [orcid-a...@googlegroups.com] on behalf of Demeranville, Tom [Tom.Deme...@bl.uk]
Sent: 11 July 2014 09:36
To: James Powell; orcid-a...@googlegroups.com
Cc: r.pe...@orcid.org; kkin...@gmail.com
Subject: RE: [ORCID API] Re: Mint ORCID's via PHP script

Andrew Cockbill

unread,
Jul 11, 2014, 5:20:17 AM7/11/14
to orcid-a...@googlegroups.com
Hi Tom

We came across the SSL issue when developing our Orcid integration a few months back and reported it to Orcid.
Catalina sent a message to this group on the 12th of March to the effect that sandbox-1 was being deprecated for development for precisely this reason.

You shouldn't have any issues as long as you are using sandbox.orcid.org instead of sandbox-1.

Best wishes

Andrew Cockbill
-- 
Andrew Cockbill
Chief Data Officer
Symplectic Ltd.
Tel: 020 7418 5555
and...@symplectic.co.uk

Demeranville, Tom

unread,
Jul 11, 2014, 5:24:26 AM7/11/14
to Andrew Cockbill, orcid-a...@googlegroups.com
Thanks for the confirmation Andrew.

I've updated the library code on github to reference sandbox, not sandbox-1

Tom.

From: orcid-a...@googlegroups.com [orcid-a...@googlegroups.com] on behalf of Andrew Cockbill [and...@symplectic.co.uk]
Sent: 11 July 2014 10:20
To: orcid-a...@googlegroups.com

James Powell

unread,
Jul 12, 2014, 11:42:38 AM7/12/14
to orcid-a...@googlegroups.com, james.e...@gmail.com, r.pe...@orcid.org, kkin...@gmail.com, tom.deme...@bl.uk
I added this to OrcidOAuth client and it appears to create a profile now. Note I use apiUriToken as the base for the create profile api call becauseI was getting a 403 Forbidden error when I used apiUriV11


private static final String PROFILE_CREATE_ENDPOINT = "/orcid-profile";


public void createOrcidProfile(OrcidAccessToken token, OrcidProfile profile) throws IOException {

                Reference ref = new Reference(apiUriToken + "/v1.1" + PROFILE_CREATE_ENDPOINT );
                ClientResource client = new ClientResource(ref);
addRestletHeader(client, "Authorization", "Bearer " + token.getAccess_token());

                try {
                        System.out.println(ref.toString());
                        StringWriter sw = new StringWriter();
                        orcidMessageContext.createMarshaller().marshal(wrapProfile(profile), sw);
                        log.fine(sw.toString());
                        StringRepresentation rep = new StringRepresentation(sw.toString(), OrcidConstants.APPLICATION_ORCID_XML);
                        client.post(rep);
                } catch (JAXBException e) {
                        log.fine("problem marshalling response "+e.getMessage());
                        throw new IOException(e);
                }

}

         private static final OrcidMessage wrapProfile(OrcidProfile profile) {
                OrcidMessage message = new OrcidMessage();
                message.setOrcidProfile(profile);
                message.setMessageVersion(OrcidConstants.MESSAGE_VERSION);
                return message;
Reply all
Reply to author
Forward
0 new messages