Accessing the Ning API with cURL

cURL is a command line utility that can be used to interact with the Ning API. It is mostly used for playing around with the Ning API. In this example, all requests use the xn_pretty=true parameter to make responses easier to read.

All of the requests using the following consumer credentials:

Consumer Key
0d716e57-5ada-4b29-a33c-2f4af1b26837
Consumer Secret
f0963fa5-1259-434f-86fc-8a17d14b16ca

The photo requests use the following token:

Access Key
a2f85402-f16c-4677-91e2-a334d362ad47
Access Secret
b42a0833-e1e2-4b02-a906-258a157bc702

Retrieving tokens

#!/bin/bash

# Request the access token for the given member using the Ning API

curl -u test@example.com \
    -d 'oauth_signature_method=PLAINTEXT&oauth_consumer_key=0d716e57-5ada-4b29-a33c-2f4af1b26837&oauth_signature=f0963fa5-1259-434f-86fc-8a17d14b16ca%26' \
    'https://external.ningapis.com/xn/rest/apiexample/1.0/Token?xn_pretty=true'

Response:

{
  "success" : true,
  "entry" : {
    "author" : "2cpor74jnszaj",
    "oauthConsumerKey" : "0d716e57-5ada-4b29-a33c-2f4af1b26837",
    "oauthToken" : "f450a524-652b-4700-9877-b2e8868fc0ca",
    "oauthTokenSecret" : "0cc82e2f-1a6b-4747-b846-01681ac5e25d"
  },
  "resources" : {
  }
}

Retrieving photos

#!/bin/bash

# Query the Ning API for the five most recent photos, returning the photo's
# title and the URL of the image

curl -H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="0d716e57-5ada-4b29-a33c-2f4af1b26837",oauth_token="a2f85402-f16c-4677-91e2-a334d362ad47",oauth_signature="f0963fa5-1259-434f-86fc-8a17d14b16ca%26b42a0833-e1e2-4b02-a906-258a157bc702"' \
    'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo/recent?xn_pretty=true&fields=title,image.url,title&count=5'

Response:

{
  "success" : true,
  "anchor" : "uxxWYGU-F4KrKZhlAq2toZ4o2xoGphLM",
  "firstPage" : true,
  "lastPage" : false,
  "entry" : [ {
    "id" : "3011345:Photo:3120",
    "author" : "2cpor74jnszaj",
    "createdDate" : "2010-09-29T20:21:27.120Z",
    "title" : "Updated Photo Title",
    "image" : "3011345:Photo:3120"
  }, {
    "id" : "3011345:Photo:3112",
    "author" : "2cpor74jnszaj",
    "createdDate" : "2010-09-29T20:07:16.112Z",
    "title" : "Updated Photo Title",
    "image" : "3011345:Photo:3112"
  }, {
    "id" : "3011345:Photo:3110",
    "author" : "2cpor74jnszaj",
    "createdDate" : "2010-09-29T20:06:36.110Z",
    "title" : "Photo Title",
    "image" : "3011345:Photo:3110"
  }, {
    "id" : "3011345:Photo:3108",
    "author" : "2cpor74jnszaj",
    "createdDate" : "2010-09-29T19:09:39.108Z",
    "title" : "Expedition 24 Soyuz Landing (201009250033HQ)",
    "image" : "3011345:Photo:3108"
  }, {
    "id" : "3011345:Photo:3105",
    "author" : "2cpor74jnszaj",
    "createdDate" : "2010-09-29T19:09:34.105Z",
    "title" : "Here Comes Comet Hartley 2! (NASA, Comets, 09/28/10)",
    "image" : "3011345:Photo:3105"
  } ],
  "resources" : {
    "3011345:Photo:3120" : {
      "url" : "http://api.ning.com:80/files/K4J5EOVUeUGMYc-jmIhbesRX1hcoxFDq-QXet5OGyAlNSxCCNGe1XPsAMtQaDLV-jMPybcxltE6xArM36iWDbg96hPnWDZGr/upload32498.tmp"
    },
    "3011345:Photo:3112" : {
      "url" : "http://api.ning.com:80/files/CNnwhHNSBj5HWGOq9jcI6c2a**IaIFlQyGTOBd-HUELNDIZ2LENqMvO3-sL2Wg1wjM1pE4oTh20My-y-taO-1Z8ITo0KhsTJ/upload37553.tmp"
    },
    "3011345:Photo:3110" : {
      "url" : "http://api.ning.com:80/files/fB839UrKcK*Z*jIxTfir9tzRgUfkUW1Dv73E2arr6k9j-LpKNF3x5owOBDKjvseAQ4GoBpuPpx*2yi3YEhH-uetIJj8tU1a-/upload37552.tmp"
    },
    "3011345:Photo:3108" : {
      "url" : "http://api.ning.com:80/files/O2p*fNpRXae4ESKRO6d0jPVkUSnB8hfGecHIO9osYxTHGEY1Ae5m*K2UXgF6DO4T*-mlVYyRUGJqAqV9ekTssnKiMe8RJFk-/upload37551.tmp"
    },
    "3011345:Photo:3105" : {
      "url" : "http://api.ning.com:80/files/RCys80y56jsyOuoP3mhZKEsDXa93J3wcol3hv44VN2nVoLkhyc8ejloVqksj1nvCB3ihvwHSVvWmcalEd-jKTBUB7Cso0CxL/upload37550.tmp"
    }
  }
}

Add a new photo

#!/bin/bash

# Upload a photo using the Ning API

curl -H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="0d716e57-5ada-4b29-a33c-2f4af1b26837",oauth_token="a2f85402-f16c-4677-91e2-a334d362ad47",oauth_signature="f0963fa5-1259-434f-86fc-8a17d14b16ca%26b42a0833-e1e2-4b02-a906-258a157bc702"' \
    -F 'title=Photo Title' \
    -F 'description=Photo Description' \
    -F 'file=@/home/test/img/cat.jpg' \
    'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo?xn_pretty=true' 

Response:

{
  "success" : true,
  "id" : "3011345:Photo:3120"
}

Update a photo

#!/bin/bash

# Update a photo using the Ning API

curl -X PUT \
    -H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="0d716e57-5ada-4b29-a33c-2f4af1b26837",oauth_token="a2f85402-f16c-4677-91e2-a334d362ad47",oauth_signature="f0963fa5-1259-434f-86fc-8a17d14b16ca%26b42a0833-e1e2-4b02-a906-258a157bc702"' \
    -d 'id=3011345:Photo:3120' \
    -d 'title=Updated Photo Title' \
    -d 'description=Updated Photo Description' \
    'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo?xn_pretty=true'

Response:

{
  "success" : true
}

Delete a photo

#!/bin/bash

# Delete a photo using the Ning API

curl -X DELETE \
    -H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="0d716e57-5ada-4b29-a33c-2f4af1b26837",oauth_token="a2f85402-f16c-4677-91e2-a334d362ad47",oauth_signature="f0963fa5-1259-434f-86fc-8a17d14b16ca%26b42a0833-e1e2-4b02-a906-258a157bc702"' \
    'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo?xn_pretty=true&id=3011345:Photo:3120'

Response:

{
  "success" : true
}