skip to Main Content

I use https://github.com/nozzlegear/ShopifySharp .Net library to work with Shopify Api. I just create dev webshop and I want to test some GET methods. In documentation I saw next code:

string code = Request.QueryString["code"];
string myShopifyUrl = Request.QueryString["shop"];

string accessToken = await AuthorizationService.Authorize(code, myShopifyUrl, shopifyApiKey, shopifySecretKey); 

All parameters I understand except first , what code is this , where I should get it?? Thanks

2

Answers


  1. You should create a method in your controller which will receive a callback from Shopify:

    public ActionResult Callback(string code, string shop) {
        string accessToken = await AuthorizationService.Authorize(code, myShopifyUrl, shopifyApiKey, shopifySecretKey); 
    }
    

    Then when you building authorization URL, you should set variable redirectUrl to the method above:

    //This is the user's store URL.
    string usersMyShopifyUrl = "https://example.myshopify.com";
    
    // A URL to redirect the user to after they've confirmed app installation.
    // This URL is required, and must be listed in your app's settings in your Shopify app dashboard.
    // It's case-sensitive too!
    string redirectUrl = "https://example.com/my/redirect/url";
    
    //An array of the Shopify access scopes your application needs to run.
    var scopes = new List<AuthorizationScope>()
    {
        AuthorizationScope.ReadCustomers,
        AuthorizationScope.WriteCustomers
    };
    
    //Or, use an array of string permissions
    var scopes = new List<string>()
    {
        "read_customers",
        "write_customers"
    }
    
    //All AuthorizationService methods are static.
    string authUrl = AuthorizationService.BuildAuthorizationUrl(scopes, usersMyShopifyUrl, shopifyApiKey, redirectUrl);
    

    And once user will be redirected to authorization URL, it will open Shopify page where user will be able to install app. Then Shopify will redirect him to your callback method with code and shop parameters

    Login or Signup to reply.
  2. This is basically Authorization code

    It is with respect to concept of “OAuth”

    Refer:
    https://help.shopify.com/api/getting-started/authentication/oauth

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search