Search code examples
rcurlhttr

curl to httr for Rosette API invalid method


So I finally get my ping command working using httr as script below

library(httr)
curl_com  = GET("https://api.rosette.com/rest/v1/ping", add_headers(`X-RosetteAPI-Key` = "my api"))

Great stuff but now cos Im stucked at the next bit.

Now I want to call another api to do sentiment analysis

curl -X POST \
-H "X-RosetteAPI-Key: your_api_key" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Cache-Control: no-cache" \
-d '{"content": "Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”" }' \
"https://api.rosette.com/rest/v1/sentiment"

I got error 405 - Method Not Allowed – You tried to access the Rosette API with an invalid method. I dont know how to translate the above curl command using httr can someone please talk me thru step by step?

Hope someone can help please Peddie


Solution

  • Well, while my comment that they have R code to use was correct, it's horribad R code.

    You can now just use the rosette R package to access the full API. Just make sure to put your Rosette API key into ROSETTE_API_KEY (easiest to just edit ~/.Renviron).

    devtools::install_github("hrbrmstr/rosette")
    
    ros_sentiment("Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, 'The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.'")
    ## $document
    ## $document$label
    ## [1] "pos"
    ## 
    ## $document$confidence
    ## [1] 0.7962072
    ## 
    ## 
    ## $entities
    ##           type            mention         normalized count entityId sentiment.label sentiment.confidence
    ## 1       PERSON        Dan Aykroyd        Dan Aykroyd     2  Q105221             pos            0.6385089
    ## 2 ORGANIZATION Hollywood Reporter Hollywood Reporter     1   Q61503             pos            0.5338094
    

    The rest of the API is also there:

    • rosette_api_key: Get or set ROSETTE_API_KEY value
    • ros_categories: Rosette API categorizatioin service
    • ros_embedding: Rosette API text embedding service
    • ros_entities: Rosette API entity extraction service
    • ros_info: Rosette API version info
    • ros_language: Rosette API language identification service
    • ros_make_name: Make a Name object
    • ros_morph: Rosette API morphological analysis service
    • ros_name_similarity: Rosette API version info
    • ros_name_translation: Rosette API name translation service
    • ros_ping Rosette: API availability
    • ros_relationships: Rosette API relationship extraction service
    • ros_sentences: Rosette API sentence determination service
    • ros_sentiment: Rosette API sentiment analysis service
    • ros_tokens: Rosette API tokenizatioin service

    It will be on CRAN a bit later in the month (when I have time to polish it a bit).